Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: v2 API upgrade #73

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(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
8 changes: 4 additions & 4 deletions cmd/insights/user-contributions.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,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 Down
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