mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
feat: also support regexp
Support for filtering commits with regexp. Refs #284
This commit is contained in:
parent
aca23027da
commit
28c16f206c
@ -43,11 +43,12 @@ You can customize how the changelog is generated using the
|
||||
# .goreleaser.yml
|
||||
changelog:
|
||||
filters:
|
||||
# commit messages containing the words listed here will be removed from
|
||||
# commit messages matching the regexp listed here will be removed from
|
||||
# the changelog
|
||||
exclude:
|
||||
- docs
|
||||
- '^docs:'
|
||||
- typo
|
||||
- (?i)foo
|
||||
```
|
||||
|
||||
## Custom release notes
|
||||
|
@ -3,11 +3,13 @@ package changelog
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/goreleaser/goreleaser/context"
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
"github.com/goreleaser/goreleaser/pipeline"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Pipe for checksums
|
||||
@ -32,21 +34,30 @@ func (Pipe) Run(ctx *context.Context) error {
|
||||
}
|
||||
var entries = strings.Split(log, "\n")
|
||||
for _, filter := range ctx.Config.Changelog.Filters.Exclude {
|
||||
entries = filterLog(filter, entries)
|
||||
r, err := regexp.Compile(filter)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "couldn't compile regexp %s", filter)
|
||||
}
|
||||
entries = remove(r, entries)
|
||||
}
|
||||
ctx.ReleaseNotes = fmt.Sprintf("## Changelog\n\n%v", strings.Join(entries, "\n"))
|
||||
return nil
|
||||
}
|
||||
|
||||
func filterLog(filter string, entries []string) (result []string) {
|
||||
func remove(filter *regexp.Regexp, entries []string) (result []string) {
|
||||
for _, entry := range entries {
|
||||
if !strings.Contains(entry, filter) {
|
||||
if !match(filter, entry) {
|
||||
result = append(result, entry)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func match(filter *regexp.Regexp, line string) bool {
|
||||
s := strings.Join(strings.SplitAfter(line, " ")[1:], "")
|
||||
return filter.MatchString(s)
|
||||
}
|
||||
|
||||
func getChangelog(tag string) (string, error) {
|
||||
prev, err := previous(tag)
|
||||
if err != nil {
|
||||
|
@ -36,7 +36,10 @@ func TestChangelog(t *testing.T) {
|
||||
testlib.GitCommit(t, "fixed bug 2")
|
||||
testlib.GitCommit(t, "ignored: whatever")
|
||||
testlib.GitCommit(t, "docs: whatever")
|
||||
testlib.GitCommit(t, "something about cArs we dont need")
|
||||
testlib.GitCommit(t, "feat: added that thing")
|
||||
testlib.GitCommit(t, "Merge pull request #999 from goreleaser/some-branch")
|
||||
testlib.GitCommit(t, "this is not a Merge pull request")
|
||||
testlib.GitTag(t, "v0.0.2")
|
||||
var ctx = context.New(config.Project{
|
||||
Changelog: config.Changelog{
|
||||
@ -44,6 +47,8 @@ func TestChangelog(t *testing.T) {
|
||||
Exclude: []string{
|
||||
"docs:",
|
||||
"ignored:",
|
||||
"(?i)cars",
|
||||
"^Merge pull request",
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -57,6 +62,8 @@ func TestChangelog(t *testing.T) {
|
||||
assert.Contains(t, ctx.ReleaseNotes, "fixed bug 2")
|
||||
assert.NotContains(t, ctx.ReleaseNotes, "docs")
|
||||
assert.NotContains(t, ctx.ReleaseNotes, "ignored")
|
||||
assert.NotContains(t, ctx.ReleaseNotes, "cArs")
|
||||
assert.NotContains(t, ctx.ReleaseNotes, "from goreleaser/some-branch")
|
||||
}
|
||||
|
||||
func TestChangelogOfFirstRelease(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user