mirror of
https://github.com/go-gitea/gitea.git
synced 2026-06-15 20:25:18 +02:00
add more edge case for git commit message trailer
This commit is contained in:
@@ -70,7 +70,7 @@ func (c *CommitMessage) MessageTrailer() CommitMessageTrailerValues {
|
||||
|
||||
var commitMessageTrailerSplit = sync.OnceValue(func() *regexp.Regexp {
|
||||
// the sep is either something like "\n---\n" or "\n\n" in the body, or at the start of the body like "---\n"
|
||||
return regexp.MustCompile(`(?s)^(?P<content>.*?)(?P<sep>^|^\n|^-{3,}\n|\n-{3,}\n|\n\n)(?P<trailer>(?:[A-Za-z0-9][-A-Za-z0-9]*:[^\n]*\n?)*)$`)
|
||||
return regexp.MustCompile(`(?s)^(?P<content>.*?)(?P<sep>^|^\n|^-{3,}\n|\n-{3,}\n|\n\n)(?P<trailer>(?:[A-Za-z0-9][-A-Za-z0-9]*:[^\n]*\n?)*\n*)$`)
|
||||
})
|
||||
|
||||
func CommitMessageSplitTrailer(s string) (content, sep, trailer string) {
|
||||
|
||||
@@ -26,6 +26,7 @@ func TestCommitMessageTrailer(t *testing.T) {
|
||||
{"a", "a", "", ""},
|
||||
{"a\n\nk", "a\n\nk", "", ""},
|
||||
{"a\n\nk:v", "a", "\n\n", "k:v"},
|
||||
{"a\n\nk:v\n\n", "a", "\n\n", "k:v\n\n"},
|
||||
{"a\n--\nk:v", "a\n--\nk:v", "", ""},
|
||||
{"a\n---\nk:v", "a", "\n---\n", "k:v"},
|
||||
|
||||
|
||||
@@ -44,13 +44,7 @@ func TestPullRequest_FormatSquashMergeCommitMessages(t *testing.T) {
|
||||
|
||||
defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultMergeMessageSize, 0)()
|
||||
|
||||
// all commits
|
||||
assert.Equal(t, "* commit msg 1\n\n* commit msg 2\n\nCommit description.\n\n",
|
||||
formatSquashMergeCommitMessages([]*git.Commit{newest, oldest}))
|
||||
|
||||
// PR-description mode: pass all-but-oldest so the oldest is not duplicated
|
||||
assert.Equal(t, "* commit msg 2\n\nCommit description.\n\n",
|
||||
formatSquashMergeCommitMessages([]*git.Commit{newest}))
|
||||
assert.Equal(t, "* commit msg 1\n\n* commit msg 2\n\nCommit description.\n\n", formatSquashMergeCommitMessages([]*git.Commit{newest, oldest}))
|
||||
|
||||
utf8Msg := &git.Commit{CommitMessage: git.CommitMessage{MessageRaw: "🌞"}}
|
||||
setting.Repository.PullRequest.DefaultMergeMessageSize = 3
|
||||
@@ -127,6 +121,7 @@ func TestBuildSquashMergeCommitMessages(t *testing.T) {
|
||||
{"title", []string{"the-user"}, "title\n---------\nCo-authored-by: the-user\n"},
|
||||
{"title\n\nKey: val", []string{"the-user"}, "title\n\nKey: val\nCo-authored-by: the-user\n"},
|
||||
{"title\n\n----\nKey: val", []string{"the-user"}, "title\n\n----\nKey: val\nCo-authored-by: the-user\n"},
|
||||
{"title\n\n----\nKey: val\n\n", []string{"the-user"}, "title\n\n----\nKey: val\nCo-authored-by: the-user\n"},
|
||||
|
||||
{"title\n\nbody", nil, "title\n\nbody"},
|
||||
{"title\n\nbody", []string{"the-user"}, "title\n\nbody\n---------\nCo-authored-by: the-user\n"},
|
||||
|
||||
Reference in New Issue
Block a user