1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-30 04:50:45 +02:00

refactor: improve a bit the git changeloger

also explained things a bit more

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2024-11-13 09:09:26 -03:00
parent ebe225a80b
commit 297615b9b7
No known key found for this signature in database

View File

@ -432,11 +432,14 @@ type gitChangeloger struct{}
func (g gitChangeloger) Log(ctx *context.Context) (string, error) {
args := []string{"log", "--pretty=oneline", "--no-decorate", "--no-color"}
prev, current := comparePair(ctx)
prev, current := ctx.Git.PreviousTag, ctx.Git.CurrentTag
if current == "" {
current = ctx.Git.Commit
}
// if prev is empty, we don't pass any more args and log everything.
// if prev is empty, it means we don't have a previous tag, so we don't
// pass any more args, which should everything.
// if current is empty, it shouldn't matter, as it will then log
// `{prev}..`, which should log everything from prev to HEAD.
if prev != "" {
args = append(args, fmt.Sprintf("%s..%s", prev, current))
}
@ -449,7 +452,7 @@ type scmChangeloger struct {
}
func (c *scmChangeloger) Log(ctx *context.Context) (string, error) {
prev, current := comparePair(ctx)
prev, current := ctx.Git.PreviousTag, ctx.Git.CurrentTag
items, err := c.client.Changelog(ctx, c.repo, prev, current)
if err != nil {
return "", err
@ -479,9 +482,3 @@ 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
return
}