Properly migrate target branch change GitLab comment (#29340)
GitLab generates "system notes" whenever an event happens within the platform. Unlike Gitea, those events are stored and retrieved as text comments with no semantic details. The only way to tell whether a comment was generated in this manner is the `system` flag on the note type. This PR adds detection for a new specific kind of event: Changing the target branch of a PR. When detected, it is downloaded using Gitea's type for this event, and eventually uploaded into Gitea in the expected format, i.e. with no text content in the comment. This PR also updates the template used to render comments to add support for migrated comments of this type. ref: https://gitlab.com/gitlab-org/gitlab/-/blob/11bd6dc826e0bea2832324a1d7356949a9398884/app/services/system_notes/merge_requests_service.rb#L102
This commit is contained in:
committed by
GitHub
parent
b79c30435f
commit
6e5966597c
@@ -11,6 +11,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -519,6 +520,8 @@ func (g *GitlabDownloader) GetComments(commentable base.Commentable) ([]*base.Co
|
||||
return allComments, true, nil
|
||||
}
|
||||
|
||||
var targetBranchChangeRegexp = regexp.MustCompile("^changed target branch from `(.*?)` to `(.*?)`$")
|
||||
|
||||
func (g *GitlabDownloader) convertNoteToComment(localIndex int64, note *gitlab.Note) *base.Comment {
|
||||
comment := &base.Comment{
|
||||
IssueIndex: localIndex,
|
||||
@@ -528,11 +531,16 @@ func (g *GitlabDownloader) convertNoteToComment(localIndex int64, note *gitlab.N
|
||||
PosterEmail: note.Author.Email,
|
||||
Content: note.Body,
|
||||
Created: *note.CreatedAt,
|
||||
Meta: map[string]any{},
|
||||
}
|
||||
|
||||
// Try to find the underlying event of system notes.
|
||||
if note.System {
|
||||
if strings.HasPrefix(note.Body, "enabled an automatic merge") {
|
||||
if match := targetBranchChangeRegexp.FindStringSubmatch(note.Body); match != nil {
|
||||
comment.CommentType = issues_model.CommentTypeChangeTargetBranch.String()
|
||||
comment.Meta["OldRef"] = match[1]
|
||||
comment.Meta["NewRef"] = match[2]
|
||||
} else if strings.HasPrefix(note.Body, "enabled an automatic merge") {
|
||||
comment.CommentType = issues_model.CommentTypePRScheduledToAutoMerge.String()
|
||||
} else if note.Body == "canceled the automatic merge" {
|
||||
comment.CommentType = issues_model.CommentTypePRUnScheduledToAutoMerge.String()
|
||||
|
||||
Reference in New Issue
Block a user