Skip to content

Commit

Permalink
fix(changelog): group regexps
Browse files Browse the repository at this point in the history
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 "<abbrev-commit> <title-commit>".

This also include "!" as defined by conventional commits.
  • Loading branch information
stevenh committed Nov 3, 2022
1 parent 914d3d5 commit 708f44f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
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\\)*:+.*$"
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
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: `^[0-9a-h]+ feat(\([[:word:]]+\))??!?:.+$`,
Order: 0,
},
{
Title: "Bug Fixes",
Regexp: "^.*bug[(\\w)]*:+.*$",
Regexp: `^[0-9a-h]+ 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
5 changes: 3 additions & 2 deletions www/docs/customization/changelog.md
Expand Up @@ -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: "<abbrev-commit> <title-commit>".
#
# 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
Expand Down

0 comments on commit 708f44f

Please sign in to comment.