mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-23 15:53:07 -05:00
Migrations: Gitlab Add Reactions Support for Issues & MergeRequests (#12695)
* fix migrations: gitlab_test * more stable test * Get Reactions to Pulls * Reactions for Issues * Comments are still hard Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
parent
7af2ccd511
commit
ad4a644fb3
2 changed files with 120 additions and 23 deletions
|
@ -327,7 +327,6 @@ func (g *GitlabDownloader) GetAsset(tag string, id int64) (io.ReadCloser, error)
|
||||||
|
|
||||||
// GetIssues returns issues according start and limit
|
// GetIssues returns issues according start and limit
|
||||||
// Note: issue label description and colors are not supported by the go-gitlab library at this time
|
// Note: issue label description and colors are not supported by the go-gitlab library at this time
|
||||||
// TODO: figure out how to transfer issue reactions
|
|
||||||
func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, error) {
|
func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, error) {
|
||||||
state := "all"
|
state := "all"
|
||||||
sort := "asc"
|
sort := "asc"
|
||||||
|
@ -361,6 +360,22 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
|
||||||
milestone = issue.Milestone.Title
|
milestone = issue.Milestone.Title
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var reactions []*base.Reaction
|
||||||
|
var awardPage = 1
|
||||||
|
for {
|
||||||
|
awards, _, err := g.client.AwardEmoji.ListIssueAwardEmoji(g.repoID, issue.IID, &gitlab.ListAwardEmojiOptions{Page: awardPage, PerPage: perPage}, gitlab.WithContext(g.ctx))
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, fmt.Errorf("error while listing issue awards: %v", err)
|
||||||
|
}
|
||||||
|
if len(awards) < perPage {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
for i := range awards {
|
||||||
|
reactions = append(reactions, g.awardToReaction(awards[i]))
|
||||||
|
}
|
||||||
|
awardPage++
|
||||||
|
}
|
||||||
|
|
||||||
allIssues = append(allIssues, &base.Issue{
|
allIssues = append(allIssues, &base.Issue{
|
||||||
Title: issue.Title,
|
Title: issue.Title,
|
||||||
Number: int64(issue.IID),
|
Number: int64(issue.IID),
|
||||||
|
@ -371,6 +386,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
|
||||||
State: issue.State,
|
State: issue.State,
|
||||||
Created: *issue.CreatedAt,
|
Created: *issue.CreatedAt,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
|
Reactions: reactions,
|
||||||
Closed: issue.ClosedAt,
|
Closed: issue.ClosedAt,
|
||||||
IsLocked: issue.DiscussionLocked,
|
IsLocked: issue.DiscussionLocked,
|
||||||
Updated: *issue.UpdatedAt,
|
Updated: *issue.UpdatedAt,
|
||||||
|
@ -384,6 +400,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetComments returns comments according issueNumber
|
// GetComments returns comments according issueNumber
|
||||||
|
// TODO: figure out how to transfer comment reactions
|
||||||
func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, error) {
|
func (g *GitlabDownloader) GetComments(issueNumber int64) ([]*base.Comment, error) {
|
||||||
var allComments = make([]*base.Comment, 0, 100)
|
var allComments = make([]*base.Comment, 0, 100)
|
||||||
|
|
||||||
|
@ -501,6 +518,22 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
|
||||||
milestone = pr.Milestone.Title
|
milestone = pr.Milestone.Title
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var reactions []*base.Reaction
|
||||||
|
var awardPage = 1
|
||||||
|
for {
|
||||||
|
awards, _, err := g.client.AwardEmoji.ListMergeRequestAwardEmoji(g.repoID, pr.IID, &gitlab.ListAwardEmojiOptions{Page: awardPage, PerPage: perPage}, gitlab.WithContext(g.ctx))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error while listing merge requests awards: %v", err)
|
||||||
|
}
|
||||||
|
if len(awards) < perPage {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
for i := range awards {
|
||||||
|
reactions = append(reactions, g.awardToReaction(awards[i]))
|
||||||
|
}
|
||||||
|
awardPage++
|
||||||
|
}
|
||||||
|
|
||||||
// Add the PR ID to the Issue Count because PR and Issues share ID space in Gitea
|
// 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)
|
||||||
|
|
||||||
|
@ -520,6 +553,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
|
||||||
MergeCommitSHA: pr.MergeCommitSHA,
|
MergeCommitSHA: pr.MergeCommitSHA,
|
||||||
MergedTime: mergeTime,
|
MergedTime: mergeTime,
|
||||||
IsLocked: locked,
|
IsLocked: locked,
|
||||||
|
Reactions: reactions,
|
||||||
Head: base.PullRequestBranch{
|
Head: base.PullRequestBranch{
|
||||||
Ref: pr.SourceBranch,
|
Ref: pr.SourceBranch,
|
||||||
SHA: pr.SHA,
|
SHA: pr.SHA,
|
||||||
|
@ -570,3 +604,11 @@ func (g *GitlabDownloader) GetReviews(pullRequestNumber int64) ([]*base.Review,
|
||||||
|
|
||||||
return reviews, nil
|
return reviews, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *GitlabDownloader) awardToReaction(award *gitlab.AwardEmoji) *base.Reaction {
|
||||||
|
return &base.Reaction{
|
||||||
|
UserID: int64(award.User.ID),
|
||||||
|
UserName: award.User.Username,
|
||||||
|
Content: award.Name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
||||||
PosterName: "lafriks",
|
PosterName: "lafriks",
|
||||||
State: "closed",
|
State: "closed",
|
||||||
Created: time.Date(2019, 11, 28, 8, 43, 35, 459000000, time.UTC),
|
Created: time.Date(2019, 11, 28, 8, 43, 35, 459000000, time.UTC),
|
||||||
Updated: time.Date(2019, 11, 28, 8, 46, 23, 275000000, time.UTC),
|
Updated: time.Date(2019, 11, 28, 8, 46, 23, 304000000, time.UTC),
|
||||||
Labels: []*base.Label{
|
Labels: []*base.Label{
|
||||||
{
|
{
|
||||||
Name: "bug",
|
Name: "bug",
|
||||||
|
@ -139,8 +139,18 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
||||||
Name: "discussion",
|
Name: "discussion",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Reactions: nil,
|
Reactions: []*base.Reaction{
|
||||||
Closed: &closed1,
|
{
|
||||||
|
UserID: 1241334,
|
||||||
|
UserName: "lafriks",
|
||||||
|
Content: "thumbsup",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
UserID: 1241334,
|
||||||
|
UserName: "lafriks",
|
||||||
|
Content: "open_mouth",
|
||||||
|
}},
|
||||||
|
Closed: &closed1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Number: 2,
|
Number: 2,
|
||||||
|
@ -157,8 +167,38 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
||||||
Name: "duplicate",
|
Name: "duplicate",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Reactions: nil,
|
Reactions: []*base.Reaction{
|
||||||
Closed: &closed2,
|
{
|
||||||
|
UserID: 1241334,
|
||||||
|
UserName: "lafriks",
|
||||||
|
Content: "thumbsup",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
UserID: 1241334,
|
||||||
|
UserName: "lafriks",
|
||||||
|
Content: "thumbsdown",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
UserID: 1241334,
|
||||||
|
UserName: "lafriks",
|
||||||
|
Content: "laughing",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
UserID: 1241334,
|
||||||
|
UserName: "lafriks",
|
||||||
|
Content: "tada",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
UserID: 1241334,
|
||||||
|
UserName: "lafriks",
|
||||||
|
Content: "confused",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
UserID: 1241334,
|
||||||
|
UserName: "lafriks",
|
||||||
|
Content: "hearts",
|
||||||
|
}},
|
||||||
|
Closed: &closed2,
|
||||||
},
|
},
|
||||||
}, issues)
|
}, issues)
|
||||||
|
|
||||||
|
@ -171,7 +211,6 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
||||||
PosterID: 1241334,
|
PosterID: 1241334,
|
||||||
PosterName: "lafriks",
|
PosterName: "lafriks",
|
||||||
Created: time.Date(2019, 11, 28, 8, 44, 52, 501000000, time.UTC),
|
Created: time.Date(2019, 11, 28, 8, 44, 52, 501000000, time.UTC),
|
||||||
Updated: time.Date(2019, 11, 28, 8, 44, 52, 501000000, time.UTC),
|
|
||||||
Content: "This is a comment",
|
Content: "This is a comment",
|
||||||
Reactions: nil,
|
Reactions: nil,
|
||||||
},
|
},
|
||||||
|
@ -207,20 +246,29 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
||||||
|
|
||||||
assert.EqualValues(t, []*base.PullRequest{
|
assert.EqualValues(t, []*base.PullRequest{
|
||||||
{
|
{
|
||||||
Number: 4,
|
Number: 4,
|
||||||
Title: "Test branch",
|
OriginalNumber: 2,
|
||||||
Content: "do not merge this PR",
|
Title: "Test branch",
|
||||||
Milestone: "1.0.0",
|
Content: "do not merge this PR",
|
||||||
PosterID: 1241334,
|
Milestone: "1.0.0",
|
||||||
PosterName: "lafriks",
|
PosterID: 1241334,
|
||||||
State: "opened",
|
PosterName: "lafriks",
|
||||||
Created: time.Date(2019, 11, 28, 15, 56, 54, 104000000, time.UTC),
|
State: "opened",
|
||||||
Updated: time.Date(2019, 11, 28, 15, 56, 54, 104000000, time.UTC),
|
Created: time.Date(2019, 11, 28, 15, 56, 54, 104000000, time.UTC),
|
||||||
Labels: []*base.Label{
|
Labels: []*base.Label{
|
||||||
{
|
{
|
||||||
Name: "bug",
|
Name: "bug",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Reactions: []*base.Reaction{{
|
||||||
|
UserID: 4575606,
|
||||||
|
UserName: "real6543",
|
||||||
|
Content: "thumbsup",
|
||||||
|
}, {
|
||||||
|
UserID: 4575606,
|
||||||
|
UserName: "real6543",
|
||||||
|
Content: "tada",
|
||||||
|
}},
|
||||||
PatchURL: "https://gitlab.com/gitea/test_repo/-/merge_requests/2.patch",
|
PatchURL: "https://gitlab.com/gitea/test_repo/-/merge_requests/2.patch",
|
||||||
Head: base.PullRequestBranch{
|
Head: base.PullRequestBranch{
|
||||||
Ref: "feat/test",
|
Ref: "feat/test",
|
||||||
|
@ -244,13 +292,20 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
||||||
|
|
||||||
rvs, err := downloader.GetReviews(1)
|
rvs, err := downloader.GetReviews(1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if assert.Len(t, prs, 2) {
|
if assert.Len(t, rvs, 2) {
|
||||||
assert.EqualValues(t, 527793, rvs[0].ReviewerID)
|
for i := range rvs {
|
||||||
assert.EqualValues(t, "axifive", rvs[0].ReviewerName)
|
switch rvs[i].ReviewerID {
|
||||||
assert.EqualValues(t, "APPROVED", rvs[0].State)
|
case 4102996:
|
||||||
assert.EqualValues(t, 4102996, rvs[1].ReviewerID)
|
assert.EqualValues(t, "zeripath", rvs[i].ReviewerName)
|
||||||
assert.EqualValues(t, "zeripath", rvs[1].ReviewerName)
|
assert.EqualValues(t, "APPROVED", rvs[i].State)
|
||||||
assert.EqualValues(t, "APPROVED", rvs[1].State)
|
case 527793:
|
||||||
|
assert.EqualValues(t, "axifive", rvs[i].ReviewerName)
|
||||||
|
assert.EqualValues(t, "APPROVED", rvs[i].State)
|
||||||
|
default:
|
||||||
|
t.Errorf("Unexpected Reviewer ID: %d", rvs[i].ReviewerID)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
rvs, err = downloader.GetReviews(2)
|
rvs, err = downloader.GetReviews(2)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
Loading…
Reference in a new issue