Skip to content

Commit

Permalink
fix: improve changelog a bit (#3673)
Browse files Browse the repository at this point in the history
revert a bit of the changes made in #3668 to improve mergeability with
pro.

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Dec 29, 2022
1 parent c714e13 commit bd98343
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions internal/pipe/changelog/changelog.go
Expand Up @@ -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))
}
Expand All @@ -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 {
Expand All @@ -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
}

0 comments on commit bd98343

Please sign in to comment.