From 3562b9af7f26d42b2ba2cde7a4db5f029fa89d8f Mon Sep 17 00:00:00 2001 From: Kirill Rogovoy Date: Sat, 28 Apr 2018 12:43:52 +0700 Subject: [PATCH] Support the newer Github API for /pulls/review_requests/ --- cmd/main.go | 3 ++- github/pullRequest.go | 7 ++++--- github/reviewRequest.go | 11 ++++++++--- github/util/github_util.go | 5 +++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 0909f2c..675fdda 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -17,6 +17,7 @@ import ( "github.com/kirillrogovoy/pullkee/github/util" "github.com/kirillrogovoy/pullkee/metric" "github.com/kirillrogovoy/pullkee/progress" + "github.com/pkg/errors" ) // Main is the entry function called by the "main" package @@ -89,7 +90,7 @@ func getPulls(f flags, a github.API, c cache.Cache) []github.PullRequest { for i := range pulls { if err := <-ch; err != nil { - reportErrorAndExit(err) + reportErrorAndExit(errors.Wrap(err, "filling details for a pull request")) } bar.Set(float64(i+1) / float64(len(pulls))) } diff --git a/github/pullRequest.go b/github/pullRequest.go index 4eea816..da92dc5 100644 --- a/github/pullRequest.go +++ b/github/pullRequest.go @@ -7,6 +7,7 @@ import ( "time" "github.com/kirillrogovoy/pullkee/github/page" + "github.com/pkg/errors" ) // PullRequest is a representation of the Pull Request the Github API returns @@ -34,7 +35,7 @@ func (p *PullRequest) FillDetails(a API) error { if p.DiffSize == nil { size, err := a.DiffSize(p.Number) if err != nil { - return err + return errors.Wrap(err, "diff size") } p.DiffSize = &size } @@ -42,7 +43,7 @@ func (p *PullRequest) FillDetails(a API) error { if p.ReviewRequests == nil { users, err := a.ReviewRequests(p.Number) if err != nil { - return err + return errors.Wrap(err, "review requests") } p.ReviewRequests = &users } @@ -50,7 +51,7 @@ func (p *PullRequest) FillDetails(a API) error { if p.Comments == nil { comments, err := a.Comments(p.Number) if err != nil { - return err + return errors.Wrap(err, "comments") } p.Comments = &comments } diff --git a/github/reviewRequest.go b/github/reviewRequest.go index 10091fb..da253fd 100644 --- a/github/reviewRequest.go +++ b/github/reviewRequest.go @@ -2,14 +2,19 @@ package github import "fmt" +// ReviewRequestsResponse is a representation of the /requested_reviewers API response +type ReviewRequestsResponse struct { + Users []User `json:"users"` +} + // ReviewRequests fetches a list of users which were requested to do a review func (a APIv3) ReviewRequests(number int) ([]User, error) { url := fmt.Sprintf("https://api.github.com/repos/%s/pulls/%d/requested_reviewers", a.RepoName, number) - users := []User{} - err := a.Get(url, &users) + response := ReviewRequestsResponse{} + err := a.Get(url, &response) if err != nil { return nil, err } - return users, nil + return response.Users, nil } diff --git a/github/util/github_util.go b/github/util/github_util.go index 538798a..98b7799 100644 --- a/github/util/github_util.go +++ b/github/util/github_util.go @@ -7,6 +7,7 @@ import ( "github.com/kirillrogovoy/pullkee/cache" "github.com/kirillrogovoy/pullkee/github" + "github.com/pkg/errors" ) // Pulls fetches the list of pull requests directly from the API @@ -31,7 +32,7 @@ func FillDetails( cacheKey := fmt.Sprintf("pr%d", p.Number) found, err := c.Get(cacheKey, &p) if err != nil { - reportFsError(err) + reportFsError(errors.Wrap(err, "getting cache")) } if !found { @@ -44,7 +45,7 @@ func FillDetails( // since p is a copy of i-th elem, we explicitly assign it to prs[i] to make the actual change prs[i] = p if err := c.Set(cacheKey, p); err != nil { - reportFsError(err) + reportFsError(errors.Wrap(err, "setting cache")) } ch <- nil }