Skip to content

Commit

Permalink
fix: do not group changelog when using github-native (#2781)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Dec 21, 2021
1 parent 04a9176 commit f42e087
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
7 changes: 6 additions & 1 deletion internal/pipe/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/goreleaser/goreleaser/internal/client"
"github.com/goreleaser/goreleaser/internal/git"
"github.com/goreleaser/goreleaser/internal/tmpl"
"github.com/goreleaser/goreleaser/pkg/config"
"github.com/goreleaser/goreleaser/pkg/context"
)

Expand Down Expand Up @@ -71,7 +72,7 @@ func (Pipe) Run(ctx *context.Context) error {
"## Changelog",
}

if len(ctx.Config.Changelog.Groups) > 0 {
if shouldGroup(ctx.Config.Changelog) {
log.Debug("grouping entries")
groups := ctx.Config.Changelog.Groups

Expand Down Expand Up @@ -124,6 +125,10 @@ func (Pipe) Run(ctx *context.Context) error {
return os.WriteFile(path, []byte(ctx.ReleaseNotes), 0o644) //nolint: gosec
}

func shouldGroup(cfg config.Changelog) bool {
return len(cfg.Groups) > 0 && cfg.Use != "github-native"
}

func getAllNonEmpty(ss []string) []string {
var r []string
for _, s := range ss {
Expand Down
29 changes: 29 additions & 0 deletions internal/pipe/changelog/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,32 @@ func TestGroupBadRegex(t *testing.T) {
ctx.Git.CurrentTag = "v0.0.2"
require.EqualError(t, Pipe{}.Run(ctx), `failed to group into "Something": error parsing regexp: missing closing ]: `+"`"+`[(\w`+"`")
}

func TestShouldGroup(t *testing.T) {
t.Run("with groups", func(t *testing.T) {
t.Run("github-native", func(t *testing.T) {
require.False(t, shouldGroup(config.Changelog{
Use: "github-native",
Groups: []config.ChangeLogGroup{{}},
}))
})
for _, u := range []string{"git", "github", "gitlab"} {
t.Run(u, func(t *testing.T) {
require.True(t, shouldGroup(config.Changelog{
Use: u,
Groups: []config.ChangeLogGroup{{}},
}))
})
}
})

t.Run("without groups", func(t *testing.T) {
for _, u := range []string{"git", "github", "gitlab", "github-native"} {
t.Run(u, func(t *testing.T) {
require.False(t, shouldGroup(config.Changelog{
Use: u,
}))
})
}
})
}
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ type Changelog struct {
Filters Filters `yaml:"filters,omitempty"`
Sort string `yaml:"sort,omitempty"`
Skip bool `yaml:"skip,omitempty"` // TODO(caarlos0): rename to Disable to match other pipes
Use string `yaml:"use,omitempty"`
Use string `yaml:"use,omitempty" jsonschema:"enum=git,enum=github,enum=github-native,enum=gitlab,default=git"`
Groups []ChangeLogGroup `yaml:"groups,omitempty"`
}

Expand Down
4 changes: 3 additions & 1 deletion www/docs/customization/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ changelog:
# - `git`: uses `git log`;
# - `github`: uses the compare GitHub API, appending the author login to the changelog.
# - `gitlab`: uses the compare GitLab API, appending the author name and email to the changelog.
# - `github-native`: uses the GitHub release notes generation API.
# - `github-native`: uses the GitHub release notes generation API, disables the groups feature.
#
# Defaults to `git`.
use: github
Expand All @@ -28,6 +28,8 @@ changelog:
# Group commits messages by given regex and title.
# 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.
#
# Default is no groups.
groups:
- title: Features
Expand Down

0 comments on commit f42e087

Please sign in to comment.