diff --git a/config/config.go b/config/config.go index 152c6de62..22da2ed87 100644 --- a/config/config.go +++ b/config/config.go @@ -195,7 +195,6 @@ type Docker struct { // Filters config type Filters struct { - Include []string `yaml:",omitempty"` Exclude []string `yaml:",omitempty"` } diff --git a/pipeline/changelog/changelog.go b/pipeline/changelog/changelog.go index 25a3b7589..6e721b075 100644 --- a/pipeline/changelog/changelog.go +++ b/pipeline/changelog/changelog.go @@ -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 { diff --git a/pipeline/changelog/changelog_test.go b/pipeline/changelog/changelog_test.go index fa4abfb26..78c729d73 100644 --- a/pipeline/changelog/changelog_test.go +++ b/pipeline/changelog/changelog_test.go @@ -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) {