From 61d47a4b731432838bf7a5cc106b51a990f68dc9 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Thu, 3 Nov 2022 23:48:38 +0000 Subject: [PATCH 1/5] fix(changelog): group regexps Fix the regular expressions used in changelog group processing to valid golang (RE2) regexps. These previously used PCRE character class \w which is not supported in RE2 which is what golang regexp uses. Document that format matches not just title as some may thing but the format " ". This also include "!" as defined by conventional commits. --- .goreleaser.yaml | 8 ++++---- internal/pipe/changelog/changelog_test.go | 8 ++++---- www/docs/customization/changelog.md | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index de85c6f5151..2fb41c2eea6 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -53,16 +53,16 @@ changelog: - go mod tidy groups: - title: Dependency updates - regexp: "^.*(feat|fix)\\(deps\\)*:+.*$" + regexp: '^[0-9a-h]+ (feat|fix)\(deps\)!?:.+$' order: 300 - title: 'New Features' - regexp: "^.*feat[(\\w)]*:+.*$" + regexp: '^[0-9a-h]+ feat(\([[:word:]]+\))??!?:.+$' order: 100 - title: 'Bug fixes' - regexp: "^.*fix[(\\w)]*:+.*$" + regexp: '^[0-9a-h]+ fix(\([[:word:]]+\))??!?:.+$' order: 200 - title: 'Documentation updates' - regexp: "^.*docs[(\\w)]*:+.*$" + regexp: ^[0-9a-h]+ doc(\([[:word:]]+\))??!?:.+$ order: 400 - title: Other work order: 9999 diff --git a/internal/pipe/changelog/changelog_test.go b/internal/pipe/changelog/changelog_test.go index 55bc2deab4b..2538e068b8f 100644 --- a/internal/pipe/changelog/changelog_test.go +++ b/internal/pipe/changelog/changelog_test.go @@ -638,12 +638,12 @@ func TestGroup(t *testing.T) { }, { Title: "Features", - Regexp: "^.*feat[(\\w)]*:+.*$", + Regexp: `^[0-9a-h]+ feat(\([[:word:]]+\))??!?:.+$`, Order: 0, }, { Title: "Bug Fixes", - Regexp: "^.*bug[(\\w)]*:+.*$", + Regexp: `^[0-9a-h]+ bug(\([[:word:]]+\))??!?:.+$`, Order: 1, }, { @@ -680,13 +680,13 @@ func TestGroupBadRegex(t *testing.T) { Groups: []config.ChangeLogGroup{ { Title: "Something", - Regexp: "^.*feat[(\\w", // unterminated regex + Regexp: "^.*feat[a-z", // unterminated regex }, }, }, }) ctx.Git.CurrentTag = "v0.0.2" - require.EqualError(t, Pipe{}.Run(ctx), `failed to group into "Something": error parsing regexp: missing closing ]: `+"`"+`[(\w`+"`") + require.EqualError(t, Pipe{}.Run(ctx), "failed to group into \"Something\": error parsing regexp: missing closing ]: `[a-z`") } func TestChangelogFormat(t *testing.T) { diff --git a/www/docs/customization/changelog.md b/www/docs/customization/changelog.md index 30f19561218..694e690d071 100644 --- a/www/docs/customization/changelog.md +++ b/www/docs/customization/changelog.md @@ -51,14 +51,15 @@ changelog: # Order value defines the order of the groups. # Proving no regex means all commits will be grouped under the default group. # Groups are disabled when using github-native, as it already groups things by itself. + # Matches are performed against strings of the form: " ". # # Default is no groups. groups: - title: Features - regexp: "^.*feat[(\\w)]*:+.*$" + regexp: '^[0-9a-h]+ feat(\([[:word:]]+\))??!?:.+$' order: 0 - title: 'Bug fixes' - regexp: "^.*fix[(\\w)]*:+.*$" + regexp: '^[0-9a-h]+ bug(\([[:word:]]+\))??!?:.+$' order: 1 - title: Others order: 999 From d9cdc6ad0fbec2d6580fe2ce7fb066df4ad09fe2 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Fri, 4 Nov 2022 00:24:22 +0000 Subject: [PATCH 2/5] chore(changelog): note regexp is re2 syntax Note changelog group regexp parameters are in RE2 syntax. --- www/docs/customization/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/www/docs/customization/changelog.md b/www/docs/customization/changelog.md index 694e690d071..b6e62937a6b 100644 --- a/www/docs/customization/changelog.md +++ b/www/docs/customization/changelog.md @@ -52,6 +52,7 @@ changelog: # Proving no regex means all commits will be grouped under the default group. # Groups are disabled when using github-native, as it already groups things by itself. # Matches are performed against strings of the form: " ". + # Regex use RE2 syntax as defined here: https://github.com/google/re2/wiki/Syntax. # # Default is no groups. groups: From ba5bcdae4d0f85bbe6a3953f7fc3740497914f7b Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Fri, 4 Nov 2022 00:58:41 +0000 Subject: [PATCH 3/5] fix: use xdigit for abbrev-commit match Use [[:xdigit:]] to match the abbrev-commit, which is clearer as to the intent and correct as the previous version had a typo anyway. --- .goreleaser.yaml | 8 ++++---- www/docs/customization/changelog.md | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 2fb41c2eea6..75b854bbc71 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -53,16 +53,16 @@ changelog: - go mod tidy groups: - title: Dependency updates - regexp: '^[0-9a-h]+ (feat|fix)\(deps\)!?:.+$' + regexp: '^[[:xdigit:]]+ (feat|fix)\(deps\)!?:.+$' order: 300 - title: 'New Features' - regexp: '^[0-9a-h]+ feat(\([[:word:]]+\))??!?:.+$' + regexp: '^[[:xdigit:]]+ feat(\([[:word:]]+\))??!?:.+$' order: 100 - title: 'Bug fixes' - regexp: '^[0-9a-h]+ fix(\([[:word:]]+\))??!?:.+$' + regexp: '^[[:xdigit:]]+ fix(\([[:word:]]+\))??!?:.+$' order: 200 - title: 'Documentation updates' - regexp: ^[0-9a-h]+ doc(\([[:word:]]+\))??!?:.+$ + regexp: ^[[:xdigit:]]+ doc(\([[:word:]]+\))??!?:.+$ order: 400 - title: Other work order: 9999 diff --git a/www/docs/customization/changelog.md b/www/docs/customization/changelog.md index b6e62937a6b..bc169579a8f 100644 --- a/www/docs/customization/changelog.md +++ b/www/docs/customization/changelog.md @@ -57,10 +57,10 @@ changelog: # Default is no groups. groups: - title: Features - regexp: '^[0-9a-h]+ feat(\([[:word:]]+\))??!?:.+$' + regexp: '^[[:xdigit:]]+ feat(\([[:word:]]+\))??!?:.+$' order: 0 - title: 'Bug fixes' - regexp: '^[0-9a-h]+ bug(\([[:word:]]+\))??!?:.+$' + regexp: '^[[:xdigit:]]+ bug(\([[:word:]]+\))??!?:.+$' order: 1 - title: Others order: 999 From 6c52a8a398ab3a8df251cd589ee7e3954127c702 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Sun, 6 Nov 2022 23:52:38 +0000 Subject: [PATCH 4/5] fix(changelog): github pattern matching GitHub has different output than the tests, including a colon after the commit reference, so make the pattern resilient to that and other nuisances by making it a full wild card but non greedy. Also: * Remove processed entries instead of striking them out, allowing early exit when we're done. * Add group match debugging to users can see what's going on with --debug. --- .goreleaser.yaml | 8 ++++---- internal/pipe/changelog/changelog.go | 11 +++++++++-- internal/pipe/changelog/changelog_test.go | 4 ++-- www/docs/customization/changelog.md | 6 +++--- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 75b854bbc71..4a5f41d2d8e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -53,16 +53,16 @@ changelog: - go mod tidy groups: - title: Dependency updates - regexp: '^[[:xdigit:]]+ (feat|fix)\(deps\)!?:.+$' + regexp: '^.*?(feat|fix)\(deps\)!?:.+$' order: 300 - title: 'New Features' - regexp: '^[[:xdigit:]]+ feat(\([[:word:]]+\))??!?:.+$' + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' order: 100 - title: 'Bug fixes' - regexp: '^[[:xdigit:]]+ fix(\([[:word:]]+\))??!?:.+$' + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' order: 200 - title: 'Documentation updates' - regexp: ^[[:xdigit:]]+ doc(\([[:word:]]+\))??!?:.+$ + regexp: ^.*?doc(\([[:word:]]+\))??!?:.+$ order: 400 - title: Other work order: 9999 diff --git a/internal/pipe/changelog/changelog.go b/internal/pipe/changelog/changelog.go index 8c384009365..3edd59c6567 100644 --- a/internal/pipe/changelog/changelog.go +++ b/internal/pipe/changelog/changelog.go @@ -155,16 +155,23 @@ func formatChangelog(ctx *context.Context, entries []string) (string, error) { if err != nil { return "", fmt.Errorf("failed to group into %q: %w", group.Title, err) } + + log.Debugf("group: %#v", group) for i, entry := range entries { match := regex.MatchString(entry) + log.Debugf("match[%d]: %s = %v\n", i, entry, match) if match { item.entries = append(item.entries, li+entry) - // Striking out the matched entry - entries[i] = "" + // Remove matched entry. + entries = append(entries[:i], entries[i+1:]...) } } } groups = append(groups, item) + + if len(entries) == 0 { + break // No more entries to process. + } } sort.Slice(groups, func(i, j int) bool { return groups[i].order < groups[j].order }) diff --git a/internal/pipe/changelog/changelog_test.go b/internal/pipe/changelog/changelog_test.go index 2538e068b8f..e00aa909eba 100644 --- a/internal/pipe/changelog/changelog_test.go +++ b/internal/pipe/changelog/changelog_test.go @@ -638,12 +638,12 @@ func TestGroup(t *testing.T) { }, { Title: "Features", - Regexp: `^[0-9a-h]+ feat(\([[:word:]]+\))??!?:.+$`, + Regexp: `^.*?feat(\([[:word:]]+\))??!?:.+$`, Order: 0, }, { Title: "Bug Fixes", - Regexp: `^[0-9a-h]+ bug(\([[:word:]]+\))??!?:.+$`, + Regexp: `^.*?bug(\([[:word:]]+\))??!?:.+$`, Order: 1, }, { diff --git a/www/docs/customization/changelog.md b/www/docs/customization/changelog.md index bc169579a8f..fcd602b3bb1 100644 --- a/www/docs/customization/changelog.md +++ b/www/docs/customization/changelog.md @@ -51,16 +51,16 @@ changelog: # Order value defines the order of the groups. # Proving no regex means all commits will be grouped under the default group. # Groups are disabled when using github-native, as it already groups things by itself. - # Matches are performed against strings of the form: " ". + # Matches are performed against strings of the form: "[:] ". # Regex use RE2 syntax as defined here: https://github.com/google/re2/wiki/Syntax. # # Default is no groups. groups: - title: Features - regexp: '^[[:xdigit:]]+ feat(\([[:word:]]+\))??!?:.+$' + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' order: 0 - title: 'Bug fixes' - regexp: '^[[:xdigit:]]+ bug(\([[:word:]]+\))??!?:.+$' + regexp: '^.*?bug(\([[:word:]]+\))??!?:.+$' order: 1 - title: Others order: 999 From ffe9559d8c37c1976536aa77d98d3cd6cc66bdde Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Mon, 7 Nov 2022 11:14:32 +0000 Subject: [PATCH 5/5] fix(changelog): invalid index access Fix invalid invalid index access in changelog processing when removing processed items. --- internal/pipe/changelog/changelog.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/pipe/changelog/changelog.go b/internal/pipe/changelog/changelog.go index 3edd59c6567..15f28b73fcc 100644 --- a/internal/pipe/changelog/changelog.go +++ b/internal/pipe/changelog/changelog.go @@ -157,15 +157,19 @@ func formatChangelog(ctx *context.Context, entries []string) (string, error) { } log.Debugf("group: %#v", group) - for i, entry := range entries { + i := 0 + for _, entry := range entries { match := regex.MatchString(entry) - log.Debugf("match[%d]: %s = %v\n", i, entry, match) + log.Debugf("entry: %s match: %b\n", entry, match) if match { item.entries = append(item.entries, li+entry) - // Remove matched entry. - entries = append(entries[:i], entries[i+1:]...) + } else { + // Keep unmatched entry. + entries[i] = entry + i++ } } + entries = entries[:i] } groups = append(groups, item)