From 9a68c54d53d6bca9f1d2ef8ab981fda11a3ef4b5 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Mon, 4 Nov 2024 14:13:30 -0300 Subject: [PATCH] fix(changelog): first release default to git changelogger (#5242) the `/compare` api doesn't allow to omit the previous reference, nor to use a git commit, so, if `previous tag` is empty, we're now defaulting to the git changelog implementation, which should resolve the problem. closes #5240 --------- Signed-off-by: Carlos Alexandro Becker --- internal/pipe/changelog/changelog.go | 4 ++++ internal/pipe/changelog/changelog_test.go | 21 ++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/internal/pipe/changelog/changelog.go b/internal/pipe/changelog/changelog.go index 0ecb9b5d8..2cb46543d 100644 --- a/internal/pipe/changelog/changelog.go +++ b/internal/pipe/changelog/changelog.go @@ -344,6 +344,10 @@ func getChangeloger(ctx *context.Context) (changeloger, error) { case useGit, "": return gitChangeloger{}, nil case useGitLab, useGitea, useGitHub: + if ctx.Git.PreviousTag == "" { + log.Warnf("there's no previous tag, using 'git' instead of '%s'", ctx.Config.Changelog.Use) + return gitChangeloger{}, nil + } return newSCMChangeloger(ctx) case useGitHubNative: return newGithubChangeloger(ctx) diff --git a/internal/pipe/changelog/changelog_test.go b/internal/pipe/changelog/changelog_test.go index 21045f82c..08ec45685 100644 --- a/internal/pipe/changelog/changelog_test.go +++ b/internal/pipe/changelog/changelog_test.go @@ -645,18 +645,29 @@ func TestGetChangeloger(t *testing.T) { Changelog: config.Changelog{ Use: useGitHub, }, - }, testctx.GitHubTokenType) + }, testctx.GitHubTokenType, testctx.WithPreviousTag("v1.2.3")) c, err := getChangeloger(ctx) require.NoError(t, err) require.IsType(t, &scmChangeloger{}, c) }) + t.Run(useGitHub+" no previous", func(t *testing.T) { + ctx := testctx.NewWithCfg(config.Project{ + Changelog: config.Changelog{ + Use: useGitHub, + }, + }, testctx.GitHubTokenType) + c, err := getChangeloger(ctx) + require.NoError(t, err) + require.IsType(t, gitChangeloger{}, c) + }) + t.Run(useGitHubNative, func(t *testing.T) { ctx := testctx.NewWithCfg(config.Project{ Changelog: config.Changelog{ Use: useGitHubNative, }, - }, testctx.GitHubTokenType) + }, testctx.GitHubTokenType, testctx.WithPreviousTag("v1.2.3")) c, err := getChangeloger(ctx) require.NoError(t, err) require.IsType(t, &githubNativeChangeloger{}, c) @@ -681,7 +692,7 @@ func TestGetChangeloger(t *testing.T) { Changelog: config.Changelog{ Use: useGitLab, }, - }, testctx.GitLabTokenType) + }, testctx.GitLabTokenType, testctx.WithPreviousTag("v1.2.3")) c, err := getChangeloger(ctx) require.NoError(t, err) require.IsType(t, &scmChangeloger{}, c) @@ -695,7 +706,7 @@ func TestGetChangeloger(t *testing.T) { Changelog: config.Changelog{ Use: useGitHub, }, - }, testctx.GitHubTokenType) + }, testctx.GitHubTokenType, testctx.WithPreviousTag("v1.2.3")) c, err := getChangeloger(ctx) require.EqualError(t, err, "unsupported repository URL: https://gist.github.com/") require.Nil(t, c) @@ -717,7 +728,7 @@ func TestGetChangeloger(t *testing.T) { GiteaURLs: config.GiteaURLs{ API: srv.URL, }, - }, testctx.GiteaTokenType) + }, testctx.GiteaTokenType, testctx.WithPreviousTag("v1.2.3")) c, err := getChangeloger(ctx) require.NoError(t, err) require.IsType(t, &scmChangeloger{}, c)