Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(changelog): group regexps #3527

Merged
merged 5 commits into from Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions .goreleaser.yaml
Expand Up @@ -53,16 +53,16 @@ changelog:
- go mod tidy
groups:
- title: Dependency updates
regexp: "^.*(feat|fix)\\(deps\\)*:+.*$"
stevenh marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
17 changes: 14 additions & 3 deletions internal/pipe/changelog/changelog.go
Expand Up @@ -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 })
Expand Down
8 changes: 4 additions & 4 deletions internal/pipe/changelog/changelog_test.go
Expand Up @@ -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,
},
{
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions www/docs/customization/changelog.md
Expand Up @@ -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: "<abbrev-commit>[:] <title-commit>".
# 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
Expand Down