diff options
author | zeripath <art27@cantab.net> | 2022-06-09 03:50:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-09 10:50:05 +0800 |
commit | 7948cb3149ab64484a8d4c6644f53f9f39accbef (patch) | |
tree | 57d26b3cd16456876ded4305ce0cb0ee375b9fb9 /services | |
parent | d087554d81e56bff6bde9c68bf610daae15b011e (diff) | |
download | gitea-7948cb3149ab64484a8d4c6644f53f9f39accbef.tar.gz gitea-7948cb3149ab64484a8d4c6644f53f9f39accbef.zip |
Prevent NPE whilst migrating if there is a team request review (#19855)
A pr.Reviewer may be nil when migrating from Gitea if this is a team
request review.
We do not migrate teams therefore we cannot map these requests, but we can
migrate user requests.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'services')
-rw-r--r-- | services/migrations/error.go | 2 | ||||
-rw-r--r-- | services/migrations/gitea_downloader.go | 11 | ||||
-rw-r--r-- | services/migrations/gitea_uploader.go | 2 | ||||
-rw-r--r-- | services/migrations/github.go | 26 |
4 files changed, 37 insertions, 4 deletions
diff --git a/services/migrations/error.go b/services/migrations/error.go index 3b3f975012..d26fa8112c 100644 --- a/services/migrations/error.go +++ b/services/migrations/error.go @@ -8,7 +8,7 @@ package migrations import ( "errors" - "github.com/google/go-github/v39/github" + "github.com/google/go-github/v45/github" ) // ErrRepoNotCreated returns the error that repository not created diff --git a/services/migrations/gitea_downloader.go b/services/migrations/gitea_downloader.go index 3c02e112ca..4ad55894ee 100644 --- a/services/migrations/gitea_downloader.go +++ b/services/migrations/gitea_downloader.go @@ -639,6 +639,11 @@ func (g *GiteaDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Review } for _, pr := range prl { + if pr.Reviewer == nil { + // Presumably this is a team review which we cannot migrate at present but we have to skip this review as otherwise the review will be mapped on to an incorrect user. + // TODO: handle team reviews + continue + } rcl, _, err := g.client.ListPullReviewComments(g.repoOwner, g.repoName, reviewable.GetForeignIndex(), pr.ID) if err != nil { @@ -664,7 +669,7 @@ func (g *GiteaDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Review }) } - allReviews = append(allReviews, &base.Review{ + review := &base.Review{ ID: pr.ID, IssueIndex: reviewable.GetLocalIndex(), ReviewerID: pr.Reviewer.ID, @@ -675,7 +680,9 @@ func (g *GiteaDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Review CreatedAt: pr.Submitted, State: string(pr.State), Comments: reviewComments, - }) + } + + allReviews = append(allReviews, review) } if len(prl) < g.maxPerPage { diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index fec1fc8c7d..408704adef 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -696,6 +696,8 @@ func convertReviewState(state string) models.ReviewType { return models.ReviewTypeReject case base.ReviewStateCommented: return models.ReviewTypeComment + case base.ReviewStateRequestReview: + return models.ReviewTypeRequest default: return models.ReviewTypePending } diff --git a/services/migrations/github.go b/services/migrations/github.go index faf0cf0794..5f5b430fa9 100644 --- a/services/migrations/github.go +++ b/services/migrations/github.go @@ -21,7 +21,7 @@ import ( "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/util" - "github.com/google/go-github/v39/github" + "github.com/google/go-github/v45/github" "golang.org/x/oauth2" ) @@ -778,6 +778,7 @@ func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Rev opt := &github.ListOptions{ PerPage: g.maxPerPage, } + // Get approve/request change reviews for { g.waitAndPickClient() reviews, resp, err := g.getClient().PullRequests.ListReviews(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), opt) @@ -817,5 +818,28 @@ func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Rev } opt.Page = resp.NextPage } + // Get requested reviews + for { + g.waitAndPickClient() + reviewers, resp, err := g.getClient().PullRequests.ListReviewers(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), opt) + if err != nil { + return nil, fmt.Errorf("error while listing repos: %v", err) + } + g.setRate(&resp.Rate) + for _, user := range reviewers.Users { + r := &base.Review{ + ReviewerID: user.GetID(), + ReviewerName: user.GetLogin(), + State: base.ReviewStateRequestReview, + IssueIndex: reviewable.GetLocalIndex(), + } + allReviews = append(allReviews, r) + } + // TODO: Handle Team requests + if resp.NextPage == 0 { + break + } + opt.Page = resp.NextPage + } return allReviews, nil } |