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 <loic@dachary.org>
Co-authored-by: Loïc Dachary <loic@dachary.org>
This commit is contained in:
singuliere 2022-03-06 20:00:41 +01:00 committed by GitHub
parent b24e8d38af
commit cc643284de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 3 deletions

View file

@ -178,7 +178,9 @@ func (c *compareDump) assertEquals(repoBefore, repoAfter *repo_model.Repository)
assert.GreaterOrEqual(c.t, len(issues), 1) assert.GreaterOrEqual(c.t, len(issues), 1)
for _, issue := range issues { for _, issue := range issues {
filename := filepath.Join("comments", fmt.Sprintf("%d.yml", issue.Number)) filename := filepath.Join("comments", fmt.Sprintf("%d.yml", issue.Number))
comments, ok := c.assertEqual(filename, []base.Comment{}, compareFields{}).([]*base.Comment) comments, ok := c.assertEqual(filename, []base.Comment{}, compareFields{
"Index": {ignore: true},
}).([]*base.Comment)
assert.True(c.t, ok) assert.True(c.t, ok)
for _, comment := range comments { for _, comment := range comments {
assert.EqualValues(c.t, issue.Number, comment.IssueIndex) assert.EqualValues(c.t, issue.Number, comment.IssueIndex)

View file

@ -9,7 +9,8 @@ import "time"
// Comment is a standard comment information // Comment is a standard comment information
type Comment struct { type Comment struct {
IssueIndex int64 `yaml:"issue_index"` IssueIndex int64 `yaml:"issue_index"`
Index int64
PosterID int64 `yaml:"poster_id"` PosterID int64 `yaml:"poster_id"`
PosterName string `yaml:"poster_name"` PosterName string `yaml:"poster_name"`
PosterEmail string `yaml:"poster_email"` PosterEmail string `yaml:"poster_email"`

View file

@ -371,6 +371,7 @@ func (d *CodebaseDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool,
poster := d.tryGetUser(note.UserID.Value) poster := d.tryGetUser(note.UserID.Value)
comments = append(comments, &base.Comment{ comments = append(comments, &base.Comment{
IssueIndex: issue.TicketID.Value, IssueIndex: issue.TicketID.Value,
Index: note.ID.Value,
PosterID: poster.ID, PosterID: poster.ID,
PosterName: poster.Name, PosterName: poster.Name,
PosterEmail: poster.Email, PosterEmail: poster.Email,
@ -481,7 +482,11 @@ func (d *CodebaseDownloader) GetPullRequests(page, perPage int) ([]*base.PullReq
Type string `xml:"type,attr"` Type string `xml:"type,attr"`
Comment []struct { Comment []struct {
Content string `xml:"content"` Content string `xml:"content"`
UserID struct { ID struct {
Value int64 `xml:",chardata"`
Type string `xml:"type,attr"`
} `xml:"id"`
UserID struct {
Value int64 `xml:",chardata"` Value int64 `xml:",chardata"`
Type string `xml:"type,attr"` Type string `xml:"type,attr"`
} `xml:"user-id"` } `xml:"user-id"`
@ -528,6 +533,7 @@ func (d *CodebaseDownloader) GetPullRequests(page, perPage int) ([]*base.PullReq
poster := d.tryGetUser(comment.UserID.Value) poster := d.tryGetUser(comment.UserID.Value)
comments = append(comments, &base.Comment{ comments = append(comments, &base.Comment{
IssueIndex: number, IssueIndex: number,
Index: comment.ID.Value,
PosterID: poster.ID, PosterID: poster.ID,
PosterName: poster.Name, PosterName: poster.Name,
PosterEmail: poster.Email, PosterEmail: poster.Email,

View file

@ -473,6 +473,7 @@ func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comm
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: opts.Context.LocalID(), IssueIndex: opts.Context.LocalID(),
Index: comment.ID,
PosterID: comment.Poster.ID, PosterID: comment.Poster.ID,
PosterName: comment.Poster.UserName, PosterName: comment.Poster.UserName,
PosterEmail: comment.Poster.Email, PosterEmail: comment.Poster.Email,

View file

@ -532,6 +532,7 @@ func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*bas
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: issueContext.LocalID(), IssueIndex: issueContext.LocalID(),
Index: comment.GetID(),
PosterID: comment.GetUser().GetID(), PosterID: comment.GetUser().GetID(),
PosterName: comment.GetUser().GetLogin(), PosterName: comment.GetUser().GetLogin(),
PosterEmail: comment.GetUser().GetEmail(), PosterEmail: comment.GetUser().GetEmail(),
@ -607,6 +608,7 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment,
issueIndex, _ := strconv.ParseInt((*comment.IssueURL)[idx+1:], 10, 64) issueIndex, _ := strconv.ParseInt((*comment.IssueURL)[idx+1:], 10, 64)
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: issueIndex, IssueIndex: issueIndex,
Index: comment.GetID(),
PosterID: comment.GetUser().GetID(), PosterID: comment.GetUser().GetID(),
PosterName: comment.GetUser().GetLogin(), PosterName: comment.GetUser().GetLogin(),
PosterEmail: comment.GetUser().GetEmail(), PosterEmail: comment.GetUser().GetEmail(),

View file

@ -485,6 +485,7 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
for _, note := range comment.Notes { for _, note := range comment.Notes {
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: context.LocalID(), IssueIndex: context.LocalID(),
Index: int64(note.ID),
PosterID: int64(note.Author.ID), PosterID: int64(note.Author.ID),
PosterName: note.Author.Username, PosterName: note.Author.Username,
PosterEmail: note.Author.Email, PosterEmail: note.Author.Email,
@ -496,6 +497,7 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
c := comment.Notes[0] c := comment.Notes[0]
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: context.LocalID(), IssueIndex: context.LocalID(),
Index: int64(c.ID),
PosterID: int64(c.Author.ID), PosterID: int64(c.Author.ID),
PosterName: c.Author.Username, PosterName: c.Author.Username,
PosterEmail: c.Author.Email, PosterEmail: c.Author.Email,

View file

@ -236,6 +236,7 @@ func (g *GogsDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comme
} }
allComments = append(allComments, &base.Comment{ allComments = append(allComments, &base.Comment{
IssueIndex: opts.Context.LocalID(), IssueIndex: opts.Context.LocalID(),
Index: comment.ID,
PosterID: comment.Poster.ID, PosterID: comment.Poster.ID,
PosterName: comment.Poster.Login, PosterName: comment.Poster.Login,
PosterEmail: comment.Poster.Email, PosterEmail: comment.Poster.Email,

View file

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