diff --git a/cmd/insights/contributors.go b/cmd/insights/contributors.go index fab046f..e9f2dd5 100644 --- a/cmd/insights/contributors.go +++ b/cmd/insights/contributors.go @@ -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 @@ -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 @@ -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 @@ -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 @@ -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(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 } diff --git a/cmd/insights/repositories.go b/cmd/insights/repositories.go index b93568f..cb03509 100644 --- a/cmd/insights/repositories.go +++ b/cmd/insights/repositories.go @@ -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) }() @@ -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 } diff --git a/cmd/insights/user-contributions.go b/cmd/insights/user-contributions.go index 4ea03b6..4f6e312 100644 --- a/cmd/insights/user-contributions.go +++ b/cmd/insights/user-contributions.go @@ -270,7 +270,7 @@ func findAllUserContributionsInsights(ctx context.Context, opts *userContributio dataPoints, _, err := opts. APIClient. RepositoryServiceAPI. - FindAllContributorsByRepoId(ctx, owner, name). + FindContributorsByOwnerAndRepo(ctx, owner, name). Range_(opts.Period). Execute() @@ -278,11 +278,11 @@ func findAllUserContributionsInsights(ctx context.Context, opts *userContributio 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), diff --git a/cmd/show/contributors.go b/cmd/show/contributors.go index e021b2f..7e198cf 100644 --- a/cmd/show/contributors.go +++ b/cmd/show/contributors.go @@ -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 "" } @@ -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() { @@ -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") } @@ -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 } @@ -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)) diff --git a/cmd/show/dashboard.go b/cmd/show/dashboard.go index 14efb55..92dece7 100644 --- a/cmd/show/dashboard.go +++ b/cmd/show/dashboard.go @@ -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 } @@ -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 } diff --git a/go.mod b/go.mod index 12817ed..0445ee7 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 9e024aa..628dc94 100644 --- a/go.sum +++ b/go.sum @@ -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=