From d2041cf52956a662937d4c6e9329bcc165c3e561 Mon Sep 17 00:00:00 2001 From: Omar Jarjur Date: Mon, 19 Dec 2016 10:45:09 -0800 Subject: [PATCH 1/2] Fix build breakage caused by an upstream API change --- batch/batch.go | 4 ++-- mirror/conversions.go | 14 +++++++------- mirror/readall.go | 18 +++++++++--------- mirror/readall_test.go | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/batch/batch.go b/batch/batch.go index 53f2a99..6dd5db9 100644 --- a/batch/batch.go +++ b/batch/batch.go @@ -42,8 +42,8 @@ import ( "github.com/google/git-appraise/repository" "github.com/google/go-github/github" - "github-mirror/auth" - "github-mirror/mirror" + "github.com/google/git-pull-request-mirror/auth" + "github.com/google/git-pull-request-mirror/mirror" ) var remoteRepository = flag.String("target", "", "Github repository to read data from") diff --git a/mirror/conversions.go b/mirror/conversions.go index 99948a9..5717cfc 100644 --- a/mirror/conversions.go +++ b/mirror/conversions.go @@ -49,7 +49,7 @@ func ConvertTime(t time.Time) string { } // ConvertStatus converts a commit status fetched from the GitHub API into a CI report. -func ConvertStatus(repoStatus github.RepoStatus) (*ci.Report, error) { +func ConvertStatus(repoStatus *github.RepoStatus) (*ci.Report, error) { result := ci.Report{} if repoStatus.UpdatedAt != nil { result.Timestamp = ConvertTime(*repoStatus.UpdatedAt) @@ -80,7 +80,7 @@ func ConvertStatus(repoStatus github.RepoStatus) (*ci.Report, error) { } // ConvertPullRequest converts a pull request fetched from the GitHub API into a review request. -func ConvertPullRequest(pr github.PullRequest) (*request.Request, error) { +func ConvertPullRequest(pr *github.PullRequest) (*request.Request, error) { if pr.Number == nil || pr.User.Login == nil || pr.Base == nil || pr.Base.Ref == nil || pr.Base.SHA == nil || (pr.CreatedAt == nil && pr.UpdatedAt == nil) { @@ -121,7 +121,7 @@ func ConvertPullRequest(pr github.PullRequest) (*request.Request, error) { } // ConvertIssueComment converts a comment on the issue associated with a pull request into a git-appraise review comment. -func ConvertIssueComment(issueComment github.IssueComment) (*comment.Comment, error) { +func ConvertIssueComment(issueComment *github.IssueComment) (*comment.Comment, error) { if issueComment.User == nil || issueComment.User.Login == nil || issueComment.Body == nil || (issueComment.UpdatedAt == nil && issueComment.CreatedAt == nil) { return nil, ErrInsufficientInfo @@ -144,7 +144,7 @@ func ConvertIssueComment(issueComment github.IssueComment) (*comment.Comment, er } // ConvertDiffComment converts a comment on the diff associated with a pull request into a git-appraise review comment. -func ConvertDiffComment(diffComment github.PullRequestComment) (*comment.Comment, error) { +func ConvertDiffComment(diffComment *github.PullRequestComment) (*comment.Comment, error) { if diffComment.User == nil || diffComment.User.Login == nil || diffComment.Body == nil || (diffComment.UpdatedAt == nil && diffComment.CreatedAt == nil) || diffComment.OriginalCommitID == nil { @@ -190,7 +190,7 @@ func ConvertDiffComment(diffComment github.PullRequestComment) (*comment.Comment // // This method requires a local clone of the repository in order to compute the locations of // the different commits in the review. -func ConvertPullRequestToReview(pr github.PullRequest, issueComments []github.IssueComment, diffComments []github.PullRequestComment, repo repository.Repo) (*review.Review, error) { +func ConvertPullRequestToReview(pr *github.PullRequest, issueComments []*github.IssueComment, diffComments []*github.PullRequestComment, repo repository.Repo) (*review.Review, error) { request, err := ConvertPullRequest(pr) if err != nil { return nil, err @@ -242,7 +242,7 @@ func ConvertPullRequestToReview(pr github.PullRequest, issueComments []github.Is } // commentStartLine takes a PullRequestComment and returns the comment's start line. -func commentStartLine(diffComment github.PullRequestComment) (uint32, error) { +func commentStartLine(diffComment *github.PullRequestComment) (uint32, error) { // This takes some contortions to figure out. The diffComment has a "position" // field, but that is not the position of the comment. Instead, that is the // position of the comment within the diff. Furthermore, this diff is a unified diff, @@ -288,7 +288,7 @@ func commentStartLine(diffComment github.PullRequestComment) (uint32, error) { } // computeReviewStartingCommit computes the first commit in the review. -func computeReviewStartingCommit(pr github.PullRequest, repo repository.Repo) (string, error) { +func computeReviewStartingCommit(pr *github.PullRequest, repo repository.Repo) (string, error) { if pr.Base == nil || pr.Base.SHA == nil || pr.Head == nil || pr.Head.SHA == nil { return "", ErrInsufficientInfo diff --git a/mirror/readall.go b/mirror/readall.go index b2cb428..1fbf75e 100644 --- a/mirror/readall.go +++ b/mirror/readall.go @@ -43,16 +43,16 @@ var ( // Can be stubbed out in testing; satisfied by github.Client.Repositories type repositoriesService interface { - ListStatuses(owner, repo, ref string, opt *github.ListOptions) ([]github.RepoStatus, *github.Response, error) + ListStatuses(owner, repo, ref string, opt *github.ListOptions) ([]*github.RepoStatus, *github.Response, error) } type pullRequestsService interface { - List(owner string, repo string, opt *github.PullRequestListOptions) ([]github.PullRequest, *github.Response, error) - ListComments(owner string, repo string, number int, opt *github.PullRequestListCommentsOptions) ([]github.PullRequestComment, *github.Response, error) + List(owner string, repo string, opt *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error) + ListComments(owner string, repo string, number int, opt *github.PullRequestListCommentsOptions) ([]*github.PullRequestComment, *github.Response, error) } type issuesService interface { - ListComments(owner string, repo string, number int, opt *github.IssueListCommentsOptions) ([]github.IssueComment, *github.Response, error) + ListComments(owner string, repo string, number int, opt *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error) } type retryableRequest func() (*github.Response, error) @@ -204,8 +204,8 @@ func GetAllPullRequests(local repository.Repo, remoteUser, remoteRepo string, cl return output, nil } -func fetchPullRequests(remoteUser, remoteRepo string, prs pullRequestsService) ([]github.PullRequest, error) { - var results []github.PullRequest +func fetchPullRequests(remoteUser, remoteRepo string, prs pullRequestsService) ([]*github.PullRequest, error) { + var results []*github.PullRequest err := executeListRequest(func(listOpts github.ListOptions) (*github.Response, error) { opts := &github.PullRequestListOptions{ State: "all", @@ -224,8 +224,8 @@ func fetchPullRequests(remoteUser, remoteRepo string, prs pullRequestsService) ( } // fetchComments fetches all of the comments for each issue it gets and then converts them. -func fetchComments(pr github.PullRequest, remoteUser, remoteRepo string, prs pullRequestsService, is issuesService) ([]github.IssueComment, []github.PullRequestComment, error) { - var issueComments []github.IssueComment +func fetchComments(pr *github.PullRequest, remoteUser, remoteRepo string, prs pullRequestsService, is issuesService) ([]*github.IssueComment, []*github.PullRequestComment, error) { + var issueComments []*github.IssueComment err := executeListRequest(func(listOpts github.ListOptions) (*github.Response, error) { listOptions := &github.IssueListCommentsOptions{ ListOptions: listOpts, @@ -239,7 +239,7 @@ func fetchComments(pr github.PullRequest, remoteUser, remoteRepo string, prs pul if err != nil { return nil, nil, err } - var diffComments []github.PullRequestComment + var diffComments []*github.PullRequestComment err = executeListRequest(func(listOpts github.ListOptions) (*github.Response, error) { listOptions := &github.PullRequestListCommentsOptions{ ListOptions: listOpts, diff --git a/mirror/readall_test.go b/mirror/readall_test.go index 0845b23..562d080 100644 --- a/mirror/readall_test.go +++ b/mirror/readall_test.go @@ -63,7 +63,7 @@ type repoServiceStub struct { Responses []repoServiceResponse } -func (s *repoServiceStub) ListStatuses(owner, repo, ref string, opt *github.ListOptions) ([]github.RepoStatus, *github.Response, error) { +func (s *repoServiceStub) ListStatuses(owner, repo, ref string, opt *github.ListOptions) ([]*github.RepoStatus, *github.Response, error) { if s.Index >= len(s.Responses) { } r := s.Responses[s.Index] @@ -102,7 +102,7 @@ func TestFetchReports(t *testing.T) { expectedReports = append(expectedReports, *successReport) expectedReports = append(expectedReports, *failureReport) responses = append(responses, repoServiceResponse{ - Results: []github.RepoStatus{ + Results: []*github.RepoStatus{ successResult, failureResult, }, From 3682b58e08a80931a3e4cba7a2abb8fb656731b8 Mon Sep 17 00:00:00 2001 From: Omar Jarjur Date: Mon, 19 Dec 2016 11:06:20 -0800 Subject: [PATCH 2/2] Fix the import paths in the app, and one small bug --- app/operations.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/operations.go b/app/operations.go index 3262588..13ef71e 100644 --- a/app/operations.go +++ b/app/operations.go @@ -31,7 +31,7 @@ import ( "google.golang.org/appengine" "google.golang.org/appengine/log" - "github-mirror/mirror" + "github.com/google/git-pull-request-mirror/mirror" ) const ( @@ -423,7 +423,7 @@ func restartAbandonedOperations() { repos, err := getAllRepoData(c) if err != nil { - log.Errorf(c, "Can't load repos: %s", err.Error) + log.Errorf(c, "Can't load repos: %s", err.Error()) return }