Skip to content

Commit

Permalink
WIP: v2 upgrade
Browse files Browse the repository at this point in the history
Signed-off-by: John McBride <[email protected]>
  • Loading branch information
jpmcb committed Jan 27, 2024
1 parent ae5a165 commit 9ca5a30
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
32 changes: 16 additions & 16 deletions cmd/insights/contributors.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,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 @@ -240,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 @@ -252,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 @@ -264,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 @@ -285,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(fmt.Sprintf("%s", 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(fmt.Sprintf("%s", 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(fmt.Sprintf("%d", 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(fmt.Sprintf("%s", 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
}
1 change: 0 additions & 1 deletion cmd/insights/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ func NewInsightsCommand() *cobra.Command {
}
cmd.AddCommand(NewContributorsCommand())
cmd.AddCommand(NewRepositoriesCommand())
cmd.AddCommand(NewUserContributionsCommand())
return cmd
}
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
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-20240126152609-035f25ad832e
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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ 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-20240126152609-035f25ad832e h1:imbVJdCDEF6sGTZNBnRb/rH5e4DXBa7/S9D6maoxCnE=
github.com/open-sauced/go-api/client v0.0.0-20240126152609-035f25ad832e/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

0 comments on commit 9ca5a30

Please sign in to comment.