diff --git a/.goreleaser.yaml b/.goreleaser.yaml index de85c6f5151..4a5f41d2d8e 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -53,16 +53,16 @@ changelog: - go mod tidy groups: - title: Dependency updates - regexp: "^.*(feat|fix)\\(deps\\)*:+.*$" + regexp: '^.*?(feat|fix)\(deps\)!?:.+$' order: 300 - title: 'New Features' - regexp: "^.*feat[(\\w)]*:+.*$" + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' order: 100 - title: 'Bug fixes' - regexp: "^.*fix[(\\w)]*:+.*$" + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' order: 200 - title: 'Documentation updates' - regexp: "^.*docs[(\\w)]*:+.*$" + 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..15f28b73fcc 100644 --- a/internal/pipe/changelog/changelog.go +++ b/internal/pipe/changelog/changelog.go @@ -155,16 +155,27 @@ func formatChangelog(ctx *context.Context, entries []string) (string, error) { if err != nil { return "", fmt.Errorf("failed to group into %q: %w", group.Title, err) } - for i, entry := range entries { + + log.Debugf("group: %#v", group) + i := 0 + for _, entry := range entries { match := regex.MatchString(entry) + log.Debugf("entry: %s match: %b\n", entry, match) if match { item.entries = append(item.entries, li+entry) - // Striking out the matched entry - entries[i] = "" + } else { + // Keep unmatched entry. + entries[i] = entry + i++ } } + entries = entries[:i] } 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 55bc2deab4b..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: "^.*feat[(\\w)]*:+.*$", + Regexp: `^.*?feat(\([[:word:]]+\))??!?:.+$`, Order: 0, }, { Title: "Bug Fixes", - Regexp: "^.*bug[(\\w)]*:+.*$", + Regexp: `^.*?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..fcd602b3bb1 100644 --- a/www/docs/customization/changelog.md +++ b/www/docs/customization/changelog.md @@ -51,14 +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: "[:] ". + # Regex use RE2 syntax as defined here: https://github.com/google/re2/wiki/Syntax. # # Default is no groups. groups: - title: Features - regexp: "^.*feat[(\\w)]*:+.*$" + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' order: 0 - title: 'Bug fixes' - regexp: "^.*fix[(\\w)]*:+.*$" + regexp: '^.*?bug(\([[:word:]]+\))??!?:.+$' order: 1 - title: Others order: 999