Skip to content

Commit

Permalink
fix(changelog): github pattern matching
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stevenh committed Nov 6, 2022
1 parent 491b067 commit 079b5bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .goreleaser.yaml
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions internal/pipe/changelog/changelog.go
Expand Up @@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions internal/pipe/changelog/changelog_test.go
Expand Up @@ -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,
},
{
Expand Down
6 changes: 3 additions & 3 deletions www/docs/customization/changelog.md
Expand Up @@ -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: "<abbrev-commit> <title-commit>".
# 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: '^[[:xdigit:]]+ feat(\([[:word:]]+\))??!?:.+$'
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 0
- title: 'Bug fixes'
regexp: '^[[:xdigit:]]+ bug(\([[:word:]]+\))??!?:.+$'
regexp: '^.*?bug(\([[:word:]]+\))??!?:.+$'
order: 1
- title: Others
order: 999
Expand Down

0 comments on commit 079b5bd

Please sign in to comment.