Skip to content

Commit

Permalink
Fix changelog generation with default template
Browse files Browse the repository at this point in the history
  • Loading branch information
schneider-felix authored and shyim committed Nov 18, 2024
1 parent cc1d621 commit 522c6ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions internal/changelog/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type Commit struct {
func GenerateChangelog(ctx context.Context, repository string, cfg Config) (string, error) {
var err error

if cfg.Template == "" {
cfg.Template = defaultChangelogTpl
}

if strings.Contains(cfg.Template, "Config.VCSURL") {
cfg.VCSURL, err = git.GetPublicVCSURL(ctx, repository)
}
Expand All @@ -54,10 +58,6 @@ func GenerateChangelog(ctx context.Context, repository string, cfg Config) (stri
}

func renderChangelog(commits []git.GitCommit, cfg Config) (string, error) {
if cfg.Template == "" {
cfg.Template = defaultChangelogTpl
}

var matcher *regexp.Regexp
if cfg.Pattern != "" {
matcher = regexp.MustCompile(cfg.Pattern)
Expand Down
11 changes: 8 additions & 3 deletions internal/changelog/changelog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ func TestGenerateWithoutConfig(t *testing.T) {
},
}

changelog, err := renderChangelog(commits, Config{VCSURL: "https://github.com/FriendsOfShopware/FroshTools/commit"})
changelog, err := renderChangelog(commits, Config{
VCSURL: "https://github.com/FriendsOfShopware/FroshTools/commit",
Template: defaultChangelogTpl,
})

assert.NoError(t, err)

Expand Down Expand Up @@ -57,13 +60,14 @@ func TestIncludeFilters(t *testing.T) {
}

cfg := Config{
Pattern: "^(NEXT-[0-9]+)",
Pattern: "^(NEXT-[0-9]+)",
Template: defaultChangelogTpl,
}

changelog, err := renderChangelog(commits, cfg)

assert.NoError(t, err)
assert.Equal(t, changelog, "- [NEXT-1234 - Fooo](/1234567890)")
assert.Equal(t, "- [NEXT-1234 - Fooo](/1234567890)", changelog)
}

func TestLetAiGenerateText(t *testing.T) {
Expand All @@ -88,6 +92,7 @@ func TestLetAiGenerateText(t *testing.T) {

cfg := Config{
AiEnabled: true,
Template: defaultChangelogTpl,
}

changelog, err := renderChangelog(commits, cfg)
Expand Down

0 comments on commit 522c6ad

Please sign in to comment.