Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix changelog generation with default template #439

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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