Append to existing trailers in generated squash commit message #15980

Merged
lunny merged 12 commits from squash-append-to-existing-trailers into main 2021-06-25 17:01:43 +00:00
Contributor

If the PR description already contains a trailer section (for example with a Signed-off-by: header), then just append the gitea-generated trailers (Co-authered-by, Reviewed-on, ...) to this existing section.

If the PR description already contains a trailer section (for example with a Signed-off-by: header), then just append the gitea-generated trailers (Co-authered-by, Reviewed-on, ...) to this existing section.
zeripath reviewed 2021-05-26 18:51:41 +00:00
Contributor

Compile regexps once. Recompiling them every request is a bad idea.

Compile regexps once. Recompiling them every request is a bad idea.
zeripath requested changes 2021-05-26 18:52:07 +00:00
zeripath left a comment
Contributor

as per comment

as per comment
zeripath reviewed 2021-06-21 18:29:46 +00:00
Contributor

OK testing from git interpret-trailers I think this needs to be, at least:

var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+[:=][^\n]+\n)*(?:[\w-]+: [^\n]+)\n*$`)

However trailers can be folded, see https://git-scm.com/docs/git-interpret-trailers

When reading trailers, there can be whitespaces after the token, the separator and the value. There can also be whitespaces inside the token and the value. The value may be split over multiple lines with each subsequent line starting with whitespace, like the "folding" in RFC 822.

Which would make this:

var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+[:=][^\n]+\n(?: [^\n]*\n)*)*(?:[\w-]+: [^\n]+(?:\n [^\n]*)*)\n*$`)

(I think)

OK testing from git interpret-trailers I think this needs to be, at least: ```suggestion var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+[:=][^\n]+\n)*(?:[\w-]+: [^\n]+)\n*$`) ``` However trailers can be folded, see https://git-scm.com/docs/git-interpret-trailers > When reading trailers, there can be whitespaces after the token, the separator and the value. There can also be whitespaces inside the token and the value. The value may be split over multiple lines with each subsequent line starting with whitespace, like the "folding" in RFC 822. Which would make this: ```suggestion var commitMessageTrailersPattern = regexp.MustCompile(`(?:^|\n\n)(?:[\w-]+[:=][^\n]+\n(?: [^\n]*\n)*)*(?:[\w-]+: [^\n]+(?:\n [^\n]*)*)\n*$`) ``` (I think)
zeripath reviewed 2021-06-21 18:33:30 +00:00
Contributor
echo -n 'Fix #1546                                                                         [19:26:27]

Signed-off-by: Not a trailer

Signed-off-by:Alice <alice@example.com>
Signed-off-by:   Bob <bob@example.com>
' | git interpret-trailers --parse
echo -n 'Fix #1546                                                                         [19:26:27]

Signed-off-by:Not a trailer

Signed-off-by:Alice <alice@example.com>
Signed-off-by:   Bob <bob@example.com>' | git interpret-trailers --parse
echo -n 'Fix #1546

Signed-off-by:Not a trailer

Signed-off-by:Alice <alice@example.com>
Signed-off-by:   Bob <bob@example.com>


' | git interpret-trailers --parse
echo -n 'Fix #1546

Signed-off-by:Not a trailer

Signed-off-by:Alice <alice@example.com>
Folded: This is a folded value
 with folded results
   preceding spaces?
Signed-off-by:   Bob <bob@example.com>' | git interpret-trailers --parse
``` echo -n 'Fix #1546 [19:26:27] Signed-off-by: Not a trailer Signed-off-by:Alice <alice@example.com> Signed-off-by: Bob <bob@example.com> ' | git interpret-trailers --parse ``` ``` echo -n 'Fix #1546 [19:26:27] Signed-off-by:Not a trailer Signed-off-by:Alice <alice@example.com> Signed-off-by: Bob <bob@example.com>' | git interpret-trailers --parse ``` ``` echo -n 'Fix #1546 Signed-off-by:Not a trailer Signed-off-by:Alice <alice@example.com> Signed-off-by: Bob <bob@example.com> ' | git interpret-trailers --parse ``` ``` echo -n 'Fix #1546 Signed-off-by:Not a trailer Signed-off-by:Alice <alice@example.com> Folded: This is a folded value with folded results preceding spaces? Signed-off-by: Bob <bob@example.com>' | git interpret-trailers --parse ```
zeripath approved these changes 2021-06-21 20:43:17 +00:00
noerw (Migrated from github.com) approved these changes 2021-06-25 11:08:30 +00:00
noerw (Migrated from github.com) commented 2021-06-25 11:08:18 +00:00

tiny typo

	assert.False(t, commitMessageTrailersPattern.MatchString("Message body not correctly separated from trailer section by empty line.\nSigned-off-by: Bob <bob@example.com>"))
tiny typo ```suggestion assert.False(t, commitMessageTrailersPattern.MatchString("Message body not correctly separated from trailer section by empty line.\nSigned-off-by: Bob <bob@example.com>")) ```
This repo is archived. You cannot comment on pull requests.
No reviewers
No Milestone
No project
No Assignees
3 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: lunny/gitea#15980
No description provided.