Skip to content

Commit

Permalink
Merge pull request #61 from open-sauced/beta
Browse files Browse the repository at this point in the history
chore: release 1.1.0
  • Loading branch information
jpmcb authored Oct 26, 2023
2 parents 041a5c6 + 57acf91 commit 5a5ae87
Show file tree
Hide file tree
Showing 14 changed files with 434 additions and 75 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ jobs:
run: |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \
-ldflags="-s -w" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${{ secrets.POSTHOG_WRITE_PUBLIC_KEY }}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version={{ needs.release.outputs.release-tag }}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.writeOnlyPublicPosthogKey=${{ vars.POSTHOG_WRITE_PUBLIC_KEY }}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Version=${{ needs.release.outputs.release-tag }}'" \
-ldflags="-X 'github.com/open-sauced/pizza-cli/pkg/utils.Sha=$(git rev-parse HEAD)'" \
-o build/pizza-${{ matrix.goos }}-${{ matrix.goarch }}
gh release upload ${{ needs.release.outputs.release-tag }} build/pizza-${{ matrix.goos }}-${{ matrix.goarch }}
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,34 @@

> All notable changes to this project will be documented in this file
## [1.1.0-beta.3](https://github.com/open-sauced/pizza-cli/compare/v1.1.0-beta.2...v1.1.0-beta.3) (2023-10-26)


### 🍕 Features

* Add filtering for usernames on user-contributions ([d10c1ef](https://github.com/open-sauced/pizza-cli/commit/d10c1ef0bc69d3acd2e9f3ebdab7eee813debe19))

## [1.1.0-beta.2](https://github.com/open-sauced/pizza-cli/compare/v1.1.0-beta.1...v1.1.0-beta.2) (2023-10-26)


### 🍕 Features

* Add "pizza insights user-contributions" command ([248f90a](https://github.com/open-sauced/pizza-cli/commit/248f90a270540c7dd992b9d69dff7da1eb2ceddd))

## [1.1.0-beta.1](https://github.com/open-sauced/pizza-cli/compare/v1.0.1-beta.1...v1.1.0-beta.1) (2023-10-18)


### 🍕 Features

* add csv support for contributors insights ([51c1897](https://github.com/open-sauced/pizza-cli/commit/51c18978cb9012fa72642fcb77c9f33bf0a88076))

## [1.0.1](https://github.com/open-sauced/pizza-cli/compare/v1.0.0...v1.0.1) (2023-10-11)


### 🐛 Bug Fixes

* Hotfix for broken release workflow file ([e115fe9](https://github.com/open-sauced/pizza-cli/commit/e115fe91ded711ad075e2847b2c73f3f065b50d1))
* Release pipeline missing some env vars ([21e43e3](https://github.com/open-sauced/pizza-cli/commit/21e43e365d490eb0a9182895aaa5e45a2c00a025))
* Roll forward fix for semantic release ([#51](https://github.com/open-sauced/pizza-cli/issues/51)) ([3a6bb27](https://github.com/open-sauced/pizza-cli/commit/3a6bb27da209caccc4ab092e202516442b1cc621))

## [1.0.1-beta.1](https://github.com/open-sauced/pizza-cli/compare/v1.0.0...v1.0.1-beta.1) (2023-10-11)
Expand Down
48 changes: 30 additions & 18 deletions cmd/insights/contributors.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package insights

import (
"bytes"
"context"
"encoding/csv"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -134,11 +135,39 @@ func (cis contributorsInsightsSlice) BuildOutput(format string) (string, error)
return utils.OutputJSON(cis)
case constants.OutputYAML:
return utils.OutputYAML(cis)
case constants.OuputCSV:
return cis.OutputCSV()
default:
return "", fmt.Errorf("unknown output format %s", format)
}
}

func (cis contributorsInsightsSlice) OutputCSV() (string, error) {
if len(cis) == 0 {
return "", fmt.Errorf("repository is either non-existent or has not been indexed yet")
}
b := new(bytes.Buffer)
writer := csv.NewWriter(b)

// write headers
err := writer.WriteAll([][]string{{"Repository URL", "New Contributors", "Recent Contributors", "Alumni Contributors", "Repeat Contributors"}})
if err != nil {
return "", err
}

// write records
for _, ci := range cis {
err := writer.WriteAll([][]string{{ci.RepoURL, strconv.Itoa(len(ci.New)), strconv.Itoa(len(ci.Recent)),
strconv.Itoa(len(ci.Alumni)), strconv.Itoa(len(ci.Repeat))}})

if err != nil {
return "", err
}
}

return b.String(), nil
}

func (cis contributorsInsightsSlice) OutputTable() (string, error) {
tables := make([]string, 0, len(cis))
for i := range cis {
Expand Down Expand Up @@ -176,23 +205,6 @@ func (cis contributorsInsightsSlice) OutputTable() (string, error) {
return strings.Join(tables, separator), nil
}

func findRepositoryByOwnerAndRepoName(ctx context.Context, apiClient *client.APIClient, repoURL string) (*client.DbRepo, error) {
owner, repoName, err := utils.GetOwnerAndRepoFromURL(repoURL)
if err != nil {
return nil, fmt.Errorf("could not extract owner and repo from url: %w", err)
}
repo, response, err := apiClient.RepositoryServiceAPI.FindOneByOwnerAndRepo(ctx, owner, repoName).Execute()
if err != nil {
if response != nil && response.StatusCode == http.StatusNotFound {
message := fmt.Sprintf("repository %s is either non-existent or has not been indexed yet", repoURL)
fmt.Println("ignoring repository issue:", message)
return nil, nil
}
return nil, fmt.Errorf("error while calling 'RepositoryServiceAPI.FindOneByOwnerAndRepo' with owner %q and repo %q: %w", owner, repoName, err)
}
return repo, nil
}

func findAllContributorsInsights(ctx context.Context, opts *contributorsOptions, repoURL string) (*contributorsInsights, error) {
repo, err := findRepositoryByOwnerAndRepoName(ctx, opts.APIClient, repoURL)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/insights/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ func NewInsightsCommand() *cobra.Command {
}
cmd.AddCommand(NewContributorsCommand())
cmd.AddCommand(NewRepositoriesCommand())
cmd.AddCommand(NewUserContributionsCommand())
return cmd
}
7 changes: 4 additions & 3 deletions cmd/insights/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ type repositoriesOptions struct {
func NewRepositoriesCommand() *cobra.Command {
opts := &repositoriesOptions{}
cmd := &cobra.Command{
Use: "repositories url... [flags]",
Short: "Gather insights about indexed git repositories",
Long: "Gather insights about indexed git repositories. This command will show info about contributors, pull requests, etc.",
Use: "repositories url... [flags]",
Aliases: []string{"repos"},
Short: "Gather insights about indexed git repositories",
Long: "Gather insights about indexed git repositories. This command will show info about contributors, pull requests, etc.",
Args: func(cmd *cobra.Command, args []string) error {
fileFlag := cmd.Flags().Lookup(constants.FlagNameFile)
if !fileFlag.Changed && len(args) == 0 {
Expand Down
Loading

0 comments on commit 5a5ae87

Please sign in to comment.