1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-17 20:47:50 +02:00

feat: added the filter ability to changelog pipe

We can now ignore some commits from the changelog by providing the
`changelog.filters.excludes` array of strings in the config
file.

Refs #284
This commit is contained in:
Carlos Alexandro Becker 2017-10-15 20:40:53 -02:00 committed by Carlos Alexandro Becker
parent 29a8ae36be
commit 4afd58e49c
3 changed files with 30 additions and 3 deletions

View File

@ -195,7 +195,6 @@ type Docker struct {
// Filters config
type Filters struct {
Include []string `yaml:",omitempty"`
Exclude []string `yaml:",omitempty"`
}

View File

@ -3,6 +3,7 @@ package changelog
import (
"fmt"
"strings"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/git"
@ -29,10 +30,23 @@ func (Pipe) Run(ctx *context.Context) error {
if err != nil {
return err
}
ctx.ReleaseNotes = fmt.Sprintf("## Changelog\n\n%v", log)
var entries = strings.Split(log, "\n")
for _, filter := range ctx.Config.Changelog.Filters.Exclude {
entries = filterLog(filter, entries)
}
ctx.ReleaseNotes = fmt.Sprintf("## Changelog\n\n%v", strings.Join(entries, "\n"))
return nil
}
func filterLog(filter string, entries []string) (result []string) {
for _, entry := range entries {
if !strings.Contains(entry, filter) {
result = append(result, entry)
}
}
return result
}
func getChangelog(tag string) (string, error) {
prev, err := previous(tag)
if err != nil {

View File

@ -34,8 +34,20 @@ func TestChangelog(t *testing.T) {
testlib.GitTag(t, "v0.0.1")
testlib.GitCommit(t, "added feature 1")
testlib.GitCommit(t, "fixed bug 2")
testlib.GitCommit(t, "ignored: whatever")
testlib.GitCommit(t, "docs: whatever")
testlib.GitCommit(t, "feat: added that thing")
testlib.GitTag(t, "v0.0.2")
var ctx = context.New(config.Project{})
var ctx = context.New(config.Project{
Changelog: config.Changelog{
Filters: config.Filters{
Exclude: []string{
"docs:",
"ignored:",
},
},
},
})
ctx.Git.CurrentTag = "v0.0.2"
assert.NoError(t, Pipe{}.Run(ctx))
assert.Equal(t, "v0.0.2", ctx.Git.CurrentTag)
@ -43,6 +55,8 @@ func TestChangelog(t *testing.T) {
assert.NotContains(t, ctx.ReleaseNotes, "first")
assert.Contains(t, ctx.ReleaseNotes, "added feature 1")
assert.Contains(t, ctx.ReleaseNotes, "fixed bug 2")
assert.NotContains(t, ctx.ReleaseNotes, "docs")
assert.NotContains(t, ctx.ReleaseNotes, "ignored")
}
func TestChangelogOfFirstRelease(t *testing.T) {