summaryrefslogtreecommitdiffstats
path: root/modules/migrations/gitlab.go
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-04-20 14:30:46 +0200
committerGitHub <noreply@github.com>2020-04-20 13:30:46 +0100
commit5bfb9bc2b6a2e10d8f0fcdd2cc1e93de39a58555 (patch)
treee1d16653ac8a7f88a7184c157f3687caacd9f0e4 /modules/migrations/gitlab.go
parent067eff8ebaaf7b05ef8514bc051c72f1f80ddc82 (diff)
downloadgitea-5bfb9bc2b6a2e10d8f0fcdd2cc1e93de39a58555.tar.gz
gitea-5bfb9bc2b6a2e10d8f0fcdd2cc1e93de39a58555.zip
When migrating from Gitlab map Approvals to approving Reviews (#11147)
When migrating from Gitlab map Gitlab Approvals to approving Reviews Co-Authored-By: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/migrations/gitlab.go')
-rw-r--r--modules/migrations/gitlab.go34
1 files changed, 30 insertions, 4 deletions
diff --git a/modules/migrations/gitlab.go b/modules/migrations/gitlab.go
index 02891d504d..8e1c7d0a83 100644
--- a/modules/migrations/gitlab.go
+++ b/modules/migrations/gitlab.go
@@ -32,7 +32,7 @@ func init() {
type GitlabDownloaderFactory struct {
}
-// Match returns ture if the migration remote URL matched this downloader factory
+// Match returns true if the migration remote URL matched this downloader factory
func (f *GitlabDownloaderFactory) Match(opts base.MigrateOptions) (bool, error) {
var matched bool
@@ -492,11 +492,12 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
}
// Add the PR ID to the Issue Count because PR and Issues share ID space in Gitea
- newPRnumber := g.issueCount + int64(pr.IID)
+ newPRNumber := g.issueCount + int64(pr.IID)
allPRs = append(allPRs, &base.PullRequest{
Title: pr.Title,
- Number: int64(newPRnumber),
+ Number: newPRNumber,
+ OriginalNumber: int64(pr.IID),
PosterName: pr.Author.Username,
PosterID: int64(pr.Author.ID),
Content: pr.Description,
@@ -532,5 +533,30 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
// GetReviews returns pull requests review
func (g *GitlabDownloader) GetReviews(pullRequestNumber int64) ([]*base.Review, error) {
- return nil, nil
+ state, _, err := g.client.MergeRequestApprovals.GetApprovalState(g.repoID, int(pullRequestNumber))
+ if err != nil {
+ return nil, err
+ }
+
+ // GitLab's Approvals are equivalent to Gitea's approve reviews
+ approvers := make(map[int]string)
+ for i := range state.Rules {
+ for u := range state.Rules[i].ApprovedBy {
+ approvers[state.Rules[i].ApprovedBy[u].ID] = state.Rules[i].ApprovedBy[u].Username
+ }
+ }
+
+ var reviews = make([]*base.Review, 0, len(approvers))
+ for id, name := range approvers {
+ reviews = append(reviews, &base.Review{
+ ReviewerID: int64(id),
+ ReviewerName: name,
+ // GitLab API doesn't return a creation date
+ CreatedAt: time.Now(),
+ // All we get are approvals
+ State: base.ReviewStateApproved,
+ })
+ }
+
+ return reviews, nil
}