Skip to content

Commit

Permalink
Support the newer Github API for /pulls/review_requests/
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillrogovoy committed Apr 28, 2018
1 parent fe1fbb9 commit 3562b9a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
}
Expand Down
7 changes: 4 additions & 3 deletions github/pullRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,23 +35,23 @@ 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
}

if p.ReviewRequests == nil {
users, err := a.ReviewRequests(p.Number)
if err != nil {
return err
return errors.Wrap(err, "review requests")
}
p.ReviewRequests = &users
}

if p.Comments == nil {
comments, err := a.Comments(p.Number)
if err != nil {
return err
return errors.Wrap(err, "comments")
}
p.Comments = &comments
}
Expand Down
11 changes: 8 additions & 3 deletions github/reviewRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 3 additions & 2 deletions github/util/github_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 3562b9a

Please sign in to comment.