Skip to content

Commit

Permalink
Merge pull request #75 from open-sauced/beta
Browse files Browse the repository at this point in the history
chore: release 1.1.1
  • Loading branch information
jpmcb authored Feb 5, 2024
2 parents ac37308 + fbf424f commit fc00730
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 46 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
- name: "🚀 release"
id: semantic-release
env:
# This ensures that publishing happens on every single trigger which then
# forces the go binaries to be built in the next step and attached to the GitHub release
FORCE_PUBLISH: "patch"
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_PACKAGE_ROOT: "npm"
Expand Down Expand Up @@ -69,7 +72,7 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
run: |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \
-ldflags="-s -w" \
-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 }}'" \
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@

> All notable changes to this project will be documented in this file
## [1.1.1-beta.3](https://github.com/open-sauced/pizza-cli/compare/v1.1.1-beta.2...v1.1.1-beta.3) (2024-02-05)


### 🐛 Bug Fixes

* Upgrade to v2 API ([#73](https://github.com/open-sauced/pizza-cli/issues/73)) ([40b468b](https://github.com/open-sauced/pizza-cli/commit/40b468be69bdffb1fa7170861abf98601acb6c68))

## [1.1.1-beta.2](https://github.com/open-sauced/pizza-cli/compare/v1.1.1-beta.1...v1.1.1-beta.2) (2024-02-03)


### 🐛 Bug Fixes

* avoid requiring CGO for now ([#71](https://github.com/open-sauced/pizza-cli/issues/71)) ([f6d2f1d](https://github.com/open-sauced/pizza-cli/commit/f6d2f1d11bda7760edf585279099f3a874661973))

## [1.1.1-beta.1](https://github.com/open-sauced/pizza-cli/compare/v1.1.0...v1.1.1-beta.1) (2023-11-29)


### 🐛 Bug Fixes

* Force publish of package to build go binaries during release ([#69](https://github.com/open-sauced/pizza-cli/issues/69)) ([02177d5](https://github.com/open-sauced/pizza-cli/commit/02177d5c81c330385f4f73c5d5f2df045c96757e))

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


Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test:
go test ./...

build:
go build -o build/pizza main.go
CGO_ENABLED=0 go build -o build/pizza main.go

install: build
sudo mv build/pizza /usr/local/bin/
Expand Down
38 changes: 21 additions & 17 deletions cmd/insights/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ func NewContributorsCommand() *cobra.Command {
},
}
cmd.Flags().StringVarP(&opts.FilePath, constants.FlagNameFile, "f", "", "Path to yaml file containing an array of git repository urls")
cmd.Flags().Int32VarP(&opts.Period, constants.FlagNamePeriod, "p", 30, "Number of days, used for query filtering")
cmd.Flags().Int32VarP(&opts.Period, constants.FlagNamePeriod, "p", 30, "Number of days, used for query filtering (7,30,90)")
return cmd
}

func (opts *contributorsOptions) run(ctx context.Context) error {
if !api.IsValidRange(opts.Period) {
return fmt.Errorf("invalid period: %d, accepts (7,30,90)", opts.Period)
}

repositories, err := utils.HandleRepositoryValues(opts.Repos, opts.FilePath)
if err != nil {
return err
Expand Down Expand Up @@ -224,7 +228,7 @@ func findAllContributorsInsights(ctx context.Context, opts *contributorsOptions,
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
response, err := findNewRepositoryContributors(ctx, opts.APIClient, repo.Id, opts.Period)
response, err := findNewRepositoryContributors(ctx, opts.APIClient, repo.Name, opts.Period)
if err != nil {
errorChan <- err
return
Expand All @@ -236,7 +240,7 @@ func findAllContributorsInsights(ctx context.Context, opts *contributorsOptions,
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
response, err := findRecentRepositoryContributors(ctx, opts.APIClient, repo.Id, opts.Period)
response, err := findRecentRepositoryContributors(ctx, opts.APIClient, repo.Name, opts.Period)
if err != nil {
errorChan <- err
return
Expand All @@ -248,7 +252,7 @@ func findAllContributorsInsights(ctx context.Context, opts *contributorsOptions,
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
response, err := findAlumniRepositoryContributors(ctx, opts.APIClient, repo.Id, opts.Period)
response, err := findAlumniRepositoryContributors(ctx, opts.APIClient, repo.Name, opts.Period)
if err != nil {
errorChan <- err
return
Expand All @@ -260,7 +264,7 @@ func findAllContributorsInsights(ctx context.Context, opts *contributorsOptions,
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
response, err := findRepeatRepositoryContributors(ctx, opts.APIClient, repo.Id, opts.Period)
response, err := findRepeatRepositoryContributors(ctx, opts.APIClient, repo.Name, opts.Period)
if err != nil {
errorChan <- err
return
Expand All @@ -281,50 +285,50 @@ func findAllContributorsInsights(ctx context.Context, opts *contributorsOptions,
return repoContributorsInsights, nil
}

func findNewRepositoryContributors(ctx context.Context, apiClient *client.APIClient, repoID, period int32) (*client.SearchAllPullRequestContributors200Response, error) {
func findNewRepositoryContributors(ctx context.Context, apiClient *client.APIClient, repo string, period int32) (*client.SearchAllPullRequestContributors200Response, error) {
data, _, err := apiClient.ContributorsServiceAPI.
NewPullRequestContributors(ctx).
RepoIds(fmt.Sprintf("%d", repoID)).
Repos(repo).
Range_(period).
Execute()
if err != nil {
return nil, fmt.Errorf("error while calling 'ContributorsServiceAPI.NewPullRequestContributors' with repository %d': %w", repoID, err)
return nil, fmt.Errorf("error while calling 'ContributorsServiceAPI.NewPullRequestContributors' with repository %s': %w", repo, err)
}
return data, nil
}

func findRecentRepositoryContributors(ctx context.Context, apiClient *client.APIClient, repoID, period int32) (*client.SearchAllPullRequestContributors200Response, error) {
func findRecentRepositoryContributors(ctx context.Context, apiClient *client.APIClient, repo string, period int32) (*client.SearchAllPullRequestContributors200Response, error) {
data, _, err := apiClient.ContributorsServiceAPI.
FindAllRecentPullRequestContributors(ctx).
RepoIds(fmt.Sprintf("%d", repoID)).
Repos(repo).
Range_(period).
Execute()
if err != nil {
return nil, fmt.Errorf("error while calling 'ContributorsServiceAPI.FindAllRecentPullRequestContributors' with repository %d': %w", repoID, err)
return nil, fmt.Errorf("error while calling 'ContributorsServiceAPI.FindAllRecentPullRequestContributors' with repository %s': %w", repo, err)
}
return data, nil
}

func findAlumniRepositoryContributors(ctx context.Context, apiClient *client.APIClient, repoID, period int32) (*client.SearchAllPullRequestContributors200Response, error) {
func findAlumniRepositoryContributors(ctx context.Context, apiClient *client.APIClient, repo string, period int32) (*client.SearchAllPullRequestContributors200Response, error) {
data, _, err := apiClient.ContributorsServiceAPI.
FindAllChurnPullRequestContributors(ctx).
RepoIds(fmt.Sprintf("%d", repoID)).
Repos(repo).
Range_(period).
Execute()
if err != nil {
return nil, fmt.Errorf("error while calling 'ContributorsServiceAPI.FindAllChurnPullRequestContributors' with repository %d': %w", repoID, err)
return nil, fmt.Errorf("error while calling 'ContributorsServiceAPI.FindAllChurnPullRequestContributors' with repository %s': %w", repo, err)
}
return data, nil
}

func findRepeatRepositoryContributors(ctx context.Context, apiClient *client.APIClient, repoID, period int32) (*client.SearchAllPullRequestContributors200Response, error) {
func findRepeatRepositoryContributors(ctx context.Context, apiClient *client.APIClient, repo string, period int32) (*client.SearchAllPullRequestContributors200Response, error) {
data, _, err := apiClient.ContributorsServiceAPI.
FindAllRepeatPullRequestContributors(ctx).
RepoIds(fmt.Sprintf("%d", repoID)).
Repos(repo).
Range_(period).
Execute()
if err != nil {
return nil, fmt.Errorf("error while calling 'ContributorsServiceAPI.FindAllRepeatPullRequestContributors' with repository %d: %w", repoID, err)
return nil, fmt.Errorf("error while calling 'ContributorsServiceAPI.FindAllRepeatPullRequestContributors' with repository %s: %w", repo, err)
}
return data, nil
}
20 changes: 10 additions & 10 deletions cmd/insights/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ func findAllRepositoryInsights(ctx context.Context, opts *repositoriesOptions, r
waitGroup.Add(1)
go func() {
defer waitGroup.Done()
response, err := getPullRequestInsights(ctx, opts.APIClient, repo.Id, opts.Period)
response, err := getPullRequestInsights(ctx, opts.APIClient, repo.Name, opts.Period)
if err != nil {
errorChan <- err
return
}
repoInsights.AllPullRequests = int(response.AllPrs)
repoInsights.AllPullRequests = int(response.PrCount)
repoInsights.AcceptedPullRequests = int(response.AcceptedPrs)
repoInsights.SpamPullRequests = int(response.SpamPrs)
}()
Expand Down Expand Up @@ -232,19 +232,19 @@ func findAllRepositoryInsights(ctx context.Context, opts *repositoriesOptions, r
return repoInsights, nil
}

func getPullRequestInsights(ctx context.Context, apiClient *client.APIClient, repoID, period int32) (*client.DbPRInsight, error) {
data, _, err := apiClient.PullRequestsServiceAPI.
GetPullRequestInsights(ctx).
RepoIds(strconv.Itoa(int(repoID))).
func getPullRequestInsights(ctx context.Context, apiClient *client.APIClient, repo string, period int32) (*client.DbPullRequestGitHubEventsHistogram, error) {
data, _, err := apiClient.HistogramGenerationServiceAPI.
PrsHistogram(ctx).
Repo(repo).
Execute()
if err != nil {
return nil, fmt.Errorf("error while calling 'PullRequestsServiceAPI.GetPullRequestInsights' with repository %d': %w", repoID, err)
return nil, fmt.Errorf("error while calling 'PullRequestsServiceAPI.GetPullRequestInsights' with repository %s': %w", repo, err)
}
index := slices.IndexFunc(data, func(insight client.DbPRInsight) bool {
return insight.Interval == period
index := slices.IndexFunc(data, func(prHisto client.DbPullRequestGitHubEventsHistogram) bool {
return int32(prHisto.Bucket.Unix()) == period
})
if index == -1 {
return nil, fmt.Errorf("could not find pull request insights for repository %d with interval %d", repoID, period)
return nil, fmt.Errorf("could not find pull request insights for repository %s with interval %d", repo, period)
}
return &data[index], nil
}
Expand Down
35 changes: 31 additions & 4 deletions cmd/insights/user-contributions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/csv"
"errors"
"fmt"
"sort"
"strconv"
"sync"

Expand Down Expand Up @@ -38,6 +39,9 @@ type userContributionsOptions struct {

// Output is the formatting style for command output
Output string

// Sort is the column to be used to sort user contributions (total, commits, pr, none)
Sort string
}

// NewUserContributionsCommand returns a new user-contributions command
Expand Down Expand Up @@ -68,6 +72,7 @@ func NewUserContributionsCommand() *cobra.Command {
cmd.Flags().StringVarP(&opts.FilePath, constants.FlagNameFile, "f", "", "Path to yaml file containing an array of git repository urls")
cmd.Flags().Int32VarP(&opts.Period, constants.FlagNamePeriod, "p", 30, "Number of days, used for query filtering")
cmd.Flags().StringSliceVarP(&opts.Users, "users", "u", []string{}, "Inclusive comma separated list of GitHub usernames to filter for")
cmd.Flags().StringVarP(&opts.Sort, "sort", "s", "none", "Sort user contributions by (total, commits, prs)")

return cmd
}
Expand Down Expand Up @@ -130,6 +135,10 @@ func (opts *userContributionsOptions) run(ctx context.Context) error {
return allErrors
}

if opts.Sort != "none" {
sortUserContributions(insights, opts.Sort)
}

for _, insight := range insights {
output, err := insight.BuildOutput(opts.Output)
if err != nil {
Expand Down Expand Up @@ -261,19 +270,19 @@ func findAllUserContributionsInsights(ctx context.Context, opts *userContributio
dataPoints, _, err := opts.
APIClient.
RepositoryServiceAPI.
FindAllContributorsByRepoId(ctx, owner, name).
FindContributorsByOwnerAndRepo(ctx, owner, name).
Range_(opts.Period).
Execute()

if err != nil {
return nil, fmt.Errorf("error while calling 'RepositoryServiceAPI.FindAllContributorsByRepoId' with repository %s/%s': %w", owner, name, err)
}

for _, data := range dataPoints {
_, ok := opts.usersMap[*data.Login]
for _, data := range dataPoints.Data {
_, ok := opts.usersMap[data.Login]
if len(opts.usersMap) == 0 || ok {
repoUserContributionsInsightGroup.Insights = append(repoUserContributionsInsightGroup.Insights, userContributionsInsights{
Login: *data.Login,
Login: data.Login,
Commits: int(data.Commits),
PrsCreated: int(data.PrsCreated),
TotalContributions: int(data.Commits) + int(data.PrsCreated),
Expand All @@ -283,3 +292,21 @@ func findAllUserContributionsInsights(ctx context.Context, opts *userContributio

return repoUserContributionsInsightGroup, nil
}

func sortUserContributions(ucig []*userContributionsInsightGroup, sortBy string) {
for _, group := range ucig {
if group != nil {
sort.SliceStable(group.Insights, func(i, j int) bool {
switch sortBy {
case "total":
return group.Insights[i].TotalContributions > group.Insights[j].TotalContributions
case "prs":
return group.Insights[i].PrsCreated > group.Insights[j].PrsCreated
case "commits":
return group.Insights[i].Commits > group.Insights[j].Commits
}
return group.Insights[i].Login < group.Insights[j].Login
})
}
}
}
18 changes: 9 additions & 9 deletions cmd/show/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (
)

// prItem: type for pull request to satisfy the list.Item interface
type prItem client.DbPullRequest
type prItem client.DbPullRequestGitHubEvents

func (i prItem) FilterValue() string { return i.Title }
func (i prItem) FilterValue() string { return i.PrTitle }
func (i prItem) GetRepoName() string {
if i.FullName != nil {
return *i.FullName
if i.RepoName != "" {
return i.RepoName
}
return ""
}
Expand All @@ -38,12 +38,12 @@ func (d itemDelegate) Render(w io.Writer, m list.Model, index int, listItem list
return
}

prTitle := i.Title
prTitle := i.PrTitle
if len(prTitle) >= 60 {
prTitle = fmt.Sprintf("%s...", prTitle[:60])
}

str := fmt.Sprintf("#%d %s\n%s\n(%s)", i.Number, i.GetRepoName(), prTitle, i.State)
str := fmt.Sprintf("#%d %s\n%s\n(%s)", i.PrNumber, i.GetRepoName(), prTitle, i.PrState)

fn := ItemStyle.Render
if index == m.Index() {
Expand Down Expand Up @@ -114,7 +114,7 @@ func (m ContributorModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if !m.prList.SettingFilter() {
pr, ok := m.prList.SelectedItem().(prItem)
if ok {
err := browser.OpenURL(fmt.Sprintf("https://github.com/%s/pull/%d", pr.GetRepoName(), pr.Number))
err := browser.OpenURL(fmt.Sprintf("https://github.com/%s/pull/%d", pr.GetRepoName(), pr.PrNumber))
if err != nil {
fmt.Println("could not open pull request in browser")
}
Expand Down Expand Up @@ -191,7 +191,7 @@ func (m *ContributorModel) fetchContributorInfo(name string) error {

// fetchContributorPRs: fetches the contributor pull requests and creates pull request list
func (m *ContributorModel) fetchContributorPRs(name string) error {
resp, r, err := m.APIClient.UserServiceAPI.FindContributorPullRequests(m.serverContext, name).Range_(30).Execute()
resp, r, err := m.APIClient.UserServiceAPI.FindContributorPullRequestGitHubEvents(m.serverContext, name).Range_(30).Execute()
if err != nil {
return err
}
Expand All @@ -204,7 +204,7 @@ func (m *ContributorModel) fetchContributorPRs(name string) error {
var items []list.Item
var mergedPullRequests int
for _, pr := range resp.Data {
if strings.ToLower(pr.State) == "merged" {
if pr.PrIsMerged {
mergedPullRequests++
}
items = append(items, prItem(pr))
Expand Down
4 changes: 2 additions & 2 deletions cmd/show/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (m *DashboardModel) FetchAllContributors() error {
// FetchNewContributors: Returns all the new contributors
func (m *DashboardModel) FetchNewContributors() ([]client.DbPullRequestContributor, error) {
resp, r, err := m.APIClient.ContributorsServiceAPI.NewPullRequestContributors(m.serverContext).Page(int32(m.queryOptions[0])).
Limit(int32(m.queryOptions[1])).RepoIds(strconv.Itoa(int(m.RepositoryInfo.Id))).Execute()
Limit(int32(m.queryOptions[1])).Repos(m.RepositoryInfo.FullName).Execute()
if err != nil {
return nil, err
}
Expand All @@ -281,7 +281,7 @@ func (m *DashboardModel) FetchNewContributors() ([]client.DbPullRequestContribut
func (m *DashboardModel) FetchAlumniContributors() ([]client.DbPullRequestContributor, error) {
resp, r, err := m.APIClient.ContributorsServiceAPI.FindAllChurnPullRequestContributors(m.serverContext).
Page(int32(m.queryOptions[0])).Limit(int32(m.queryOptions[1])).
Range_(int32(m.queryOptions[2])).RepoIds(strconv.Itoa(int(m.RepositoryInfo.Id))).Execute()
Range_(int32(m.queryOptions[2])).Repos(m.RepositoryInfo.FullName).Execute()
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/charmbracelet/bubbletea v0.24.2
github.com/charmbracelet/lipgloss v0.9.1
github.com/cli/browser v1.3.0
github.com/open-sauced/go-api/client v0.0.0-20231025234817-a8f01f3b26d8
github.com/open-sauced/go-api/client v0.0.0-20240205155059-a3159bc0517e
github.com/posthog/posthog-go v0.0.0-20230801140217-d607812dee69
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ github.com/open-sauced/go-api/client v0.0.0-20231024233005-61e58f577005 h1:qrsKq
github.com/open-sauced/go-api/client v0.0.0-20231024233005-61e58f577005/go.mod h1:W/TRuLUqYpMvkmElDUQvQ07xlxhK8TOfpwRh8SCAuNA=
github.com/open-sauced/go-api/client v0.0.0-20231025234817-a8f01f3b26d8 h1:qzSaxN4BdovOr2DjXcYJz4LH7RSXEdhw98zAdnJVqJU=
github.com/open-sauced/go-api/client v0.0.0-20231025234817-a8f01f3b26d8/go.mod h1:W/TRuLUqYpMvkmElDUQvQ07xlxhK8TOfpwRh8SCAuNA=
github.com/open-sauced/go-api/client v0.0.0-20240202223515-f3f8157b083d h1:e9c07oVveXyHHhcu85hKHicl2K+ruAcAXX5BUd4StO8=
github.com/open-sauced/go-api/client v0.0.0-20240202223515-f3f8157b083d/go.mod h1:W/TRuLUqYpMvkmElDUQvQ07xlxhK8TOfpwRh8SCAuNA=
github.com/open-sauced/go-api/client v0.0.0-20240205155059-a3159bc0517e h1:3j5r7ArokAO+u8vhgQPklp5qnGxA+MkXluRYt2qTnik=
github.com/open-sauced/go-api/client v0.0.0-20240205155059-a3159bc0517e/go.mod h1:W/TRuLUqYpMvkmElDUQvQ07xlxhK8TOfpwRh8SCAuNA=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posthog/posthog-go v0.0.0-20230801140217-d607812dee69 h1:01dHVodha5BzrMtVmcpPeA4VYbZEsTXQ6m4123zQXJk=
github.com/posthog/posthog-go v0.0.0-20230801140217-d607812dee69/go.mod h1:migYMxlAqcnQy+3eN8mcL0b2tpKy6R+8Zc0lxwk4dKM=
Expand Down
Loading

0 comments on commit fc00730

Please sign in to comment.