Skip to content

Commit cc64328

Browse files
singuliereLoïc Dachary
and
Loïc Dachary
authored
Add Index to comment for migrations and mirroring (#18806)
Comments have an id (see Gitea[0], GitLab[1], GitHub[2], etc.), and the comment migration format must represent it during migrations so that it can be used during mirroring or incremental migrations. [0] https://try.gitea.io/api/swagger#/issue/issueGetComment [1] https://docs.gitlab.com/ee/api/discussions.html#get-single-issue-discussion-item [2] https://docs.github.com/en/rest/reference/issues#get-an-issue-comment Signed-off-by: Loïc Dachary <[email protected]> Co-authored-by: Loïc Dachary <[email protected]>
1 parent b24e8d3 commit cc64328

File tree

8 files changed

+20
-3
lines changed

8 files changed

+20
-3
lines changed

integrations/dump_restore_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ func (c *compareDump) assertEquals(repoBefore, repoAfter *repo_model.Repository)
178178
assert.GreaterOrEqual(c.t, len(issues), 1)
179179
for _, issue := range issues {
180180
filename := filepath.Join("comments", fmt.Sprintf("%d.yml", issue.Number))
181-
comments, ok := c.assertEqual(filename, []base.Comment{}, compareFields{}).([]*base.Comment)
181+
comments, ok := c.assertEqual(filename, []base.Comment{}, compareFields{
182+
"Index": {ignore: true},
183+
}).([]*base.Comment)
182184
assert.True(c.t, ok)
183185
for _, comment := range comments {
184186
assert.EqualValues(c.t, issue.Number, comment.IssueIndex)

modules/migration/comment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import "time"
99

1010
// Comment is a standard comment information
1111
type Comment struct {
12-
IssueIndex int64 `yaml:"issue_index"`
12+
IssueIndex int64 `yaml:"issue_index"`
13+
Index int64
1314
PosterID int64 `yaml:"poster_id"`
1415
PosterName string `yaml:"poster_name"`
1516
PosterEmail string `yaml:"poster_email"`

services/migrations/codebase.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ func (d *CodebaseDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool,
371371
poster := d.tryGetUser(note.UserID.Value)
372372
comments = append(comments, &base.Comment{
373373
IssueIndex: issue.TicketID.Value,
374+
Index: note.ID.Value,
374375
PosterID: poster.ID,
375376
PosterName: poster.Name,
376377
PosterEmail: poster.Email,
@@ -481,7 +482,11 @@ func (d *CodebaseDownloader) GetPullRequests(page, perPage int) ([]*base.PullReq
481482
Type string `xml:"type,attr"`
482483
Comment []struct {
483484
Content string `xml:"content"`
484-
UserID struct {
485+
ID struct {
486+
Value int64 `xml:",chardata"`
487+
Type string `xml:"type,attr"`
488+
} `xml:"id"`
489+
UserID struct {
485490
Value int64 `xml:",chardata"`
486491
Type string `xml:"type,attr"`
487492
} `xml:"user-id"`
@@ -528,6 +533,7 @@ func (d *CodebaseDownloader) GetPullRequests(page, perPage int) ([]*base.PullReq
528533
poster := d.tryGetUser(comment.UserID.Value)
529534
comments = append(comments, &base.Comment{
530535
IssueIndex: number,
536+
Index: comment.ID.Value,
531537
PosterID: poster.ID,
532538
PosterName: poster.Name,
533539
PosterEmail: poster.Email,

services/migrations/gitea_downloader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comm
473473

474474
allComments = append(allComments, &base.Comment{
475475
IssueIndex: opts.Context.LocalID(),
476+
Index: comment.ID,
476477
PosterID: comment.Poster.ID,
477478
PosterName: comment.Poster.UserName,
478479
PosterEmail: comment.Poster.Email,

services/migrations/github.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*bas
532532

533533
allComments = append(allComments, &base.Comment{
534534
IssueIndex: issueContext.LocalID(),
535+
Index: comment.GetID(),
535536
PosterID: comment.GetUser().GetID(),
536537
PosterName: comment.GetUser().GetLogin(),
537538
PosterEmail: comment.GetUser().GetEmail(),
@@ -607,6 +608,7 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment,
607608
issueIndex, _ := strconv.ParseInt((*comment.IssueURL)[idx+1:], 10, 64)
608609
allComments = append(allComments, &base.Comment{
609610
IssueIndex: issueIndex,
611+
Index: comment.GetID(),
610612
PosterID: comment.GetUser().GetID(),
611613
PosterName: comment.GetUser().GetLogin(),
612614
PosterEmail: comment.GetUser().GetEmail(),

services/migrations/gitlab.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
485485
for _, note := range comment.Notes {
486486
allComments = append(allComments, &base.Comment{
487487
IssueIndex: context.LocalID(),
488+
Index: int64(note.ID),
488489
PosterID: int64(note.Author.ID),
489490
PosterName: note.Author.Username,
490491
PosterEmail: note.Author.Email,
@@ -496,6 +497,7 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
496497
c := comment.Notes[0]
497498
allComments = append(allComments, &base.Comment{
498499
IssueIndex: context.LocalID(),
500+
Index: int64(c.ID),
499501
PosterID: int64(c.Author.ID),
500502
PosterName: c.Author.Username,
501503
PosterEmail: c.Author.Email,

services/migrations/gogs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func (g *GogsDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comme
236236
}
237237
allComments = append(allComments, &base.Comment{
238238
IssueIndex: opts.Context.LocalID(),
239+
Index: comment.ID,
239240
PosterID: comment.Poster.ID,
240241
PosterName: comment.Poster.Login,
241242
PosterEmail: comment.Poster.Email,

services/migrations/onedev.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
379379
}
380380

381381
rawComments := make([]struct {
382+
ID int64 `json:"id"`
382383
Date time.Time `json:"date"`
383384
UserID int64 `json:"userId"`
384385
Content string `json:"content"`
@@ -429,6 +430,7 @@ func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
429430
poster := d.tryGetUser(comment.UserID)
430431
comments = append(comments, &base.Comment{
431432
IssueIndex: context.LocalID(),
433+
Index: comment.ID,
432434
PosterID: poster.ID,
433435
PosterName: poster.Name,
434436
PosterEmail: poster.Email,

0 commit comments

Comments
 (0)