-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly migrate automatic merge GitLab comments (#27873)
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 two specific kinds of events: Scheduling and un-scheduling of automatic merges on a PR. When detected, they are downloaded using Gitea's type for these events, 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 these two types. ref: https://gitlab.com/gitlab-org/gitlab/-/blob/11bd6dc826e0bea2832324a1d7356949a9398884/app/services/system_notes/merge_requests_service.rb#L6-L17 --------- Co-authored-by: silverwind <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
- Loading branch information
1 parent
e9b1373
commit a70c00b
Showing
5 changed files
with
111 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -517,6 +517,71 @@ func TestAwardsToReactions(t *testing.T) { | |
}, reactions) | ||
} | ||
|
||
func TestNoteToComment(t *testing.T) { | ||
downloader := &GitlabDownloader{} | ||
|
||
now := time.Now() | ||
makeTestNote := func(id int, body string, system bool) gitlab.Note { | ||
return gitlab.Note{ | ||
ID: id, | ||
Author: struct { | ||
ID int `json:"id"` | ||
Username string `json:"username"` | ||
Email string `json:"email"` | ||
Name string `json:"name"` | ||
State string `json:"state"` | ||
AvatarURL string `json:"avatar_url"` | ||
WebURL string `json:"web_url"` | ||
}{ | ||
ID: 72, | ||
Email: "[email protected]", | ||
Username: "test", | ||
}, | ||
Body: body, | ||
CreatedAt: &now, | ||
System: system, | ||
} | ||
} | ||
notes := []gitlab.Note{ | ||
makeTestNote(1, "This is a regular comment", false), | ||
makeTestNote(2, "enabled an automatic merge for abcd1234", true), | ||
makeTestNote(3, "canceled the automatic merge", true), | ||
} | ||
comments := []base.Comment{{ | ||
IssueIndex: 17, | ||
Index: 1, | ||
PosterID: 72, | ||
PosterName: "test", | ||
PosterEmail: "[email protected]", | ||
CommentType: "", | ||
Content: "This is a regular comment", | ||
Created: now, | ||
}, { | ||
IssueIndex: 17, | ||
Index: 2, | ||
PosterID: 72, | ||
PosterName: "test", | ||
PosterEmail: "[email protected]", | ||
CommentType: "pull_scheduled_merge", | ||
Content: "enabled an automatic merge for abcd1234", | ||
Created: now, | ||
}, { | ||
IssueIndex: 17, | ||
Index: 3, | ||
PosterID: 72, | ||
PosterName: "test", | ||
PosterEmail: "[email protected]", | ||
CommentType: "pull_cancel_scheduled_merge", | ||
Content: "canceled the automatic merge", | ||
Created: now, | ||
}} | ||
|
||
for i, note := range notes { | ||
actualComment := *downloader.convertNoteToComment(17, ¬e) | ||
assert.EqualValues(t, actualComment, comments[i]) | ||
} | ||
} | ||
|
||
func TestGitlabIIDResolver(t *testing.T) { | ||
r := gitlabIIDResolver{} | ||
r.recordIssueIID(1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters