From bd98343e4b65bf68594bba93a7066bf11ef6e84d Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Thu, 29 Dec 2022 14:07:23 -0300 Subject: [PATCH] fix: improve changelog a bit (#3673) revert a bit of the changes made in #3668 to improve mergeability with pro. Signed-off-by: Carlos A Becker --- internal/pipe/changelog/changelog.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/pipe/changelog/changelog.go b/internal/pipe/changelog/changelog.go index 47a021a2e..002bda370 100644 --- a/internal/pipe/changelog/changelog.go +++ b/internal/pipe/changelog/changelog.go @@ -375,10 +375,13 @@ type changeloger interface { type gitChangeloger struct{} +var validSHA1 = regexp.MustCompile(`^[a-fA-F0-9]{40}$`) + func (g gitChangeloger) Log(ctx *context.Context) (string, error) { args := []string{"log", "--pretty=oneline", "--abbrev-commit", "--no-decorate", "--no-color"} - if ctx.Git.PreviousTag == "" { - args = append(args, ctx.Git.FirstCommit, ctx.Git.CurrentTag) + prev, current := comparePair(ctx) + if validSHA1.MatchString(prev) { + args = append(args, prev, current) } else { args = append(args, fmt.Sprintf("tags/%s..tags/%s", ctx.Git.PreviousTag, ctx.Git.CurrentTag)) } @@ -391,10 +394,8 @@ type scmChangeloger struct { } func (c *scmChangeloger) Log(ctx *context.Context) (string, error) { - if ctx.Git.PreviousTag == "" { - return c.client.Changelog(ctx, c.repo, ctx.Git.FirstCommit, ctx.Git.PreviousTag) - } - return c.client.Changelog(ctx, c.repo, ctx.Git.PreviousTag, ctx.Git.PreviousTag) + prev, current := comparePair(ctx) + return c.client.Changelog(ctx, c.repo, prev, current) } type githubNativeChangeloger struct { @@ -405,3 +406,12 @@ type githubNativeChangeloger struct { func (c *githubNativeChangeloger) Log(ctx *context.Context) (string, error) { return c.client.GenerateReleaseNotes(ctx, c.repo, ctx.Git.PreviousTag, ctx.Git.CurrentTag) } + +func comparePair(ctx *context.Context) (prev string, current string) { + prev = ctx.Git.PreviousTag + current = ctx.Git.CurrentTag + if prev == "" { + prev = ctx.Git.FirstCommit + } + return +}