From 6c52a8a398ab3a8df251cd589ee7e3954127c702 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Sun, 6 Nov 2022 23:52:38 +0000 Subject: [PATCH] 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