mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
fix: github changeloger should use short commits
This commit is contained in:
parent
ff0eeaca35
commit
fe3284285c
@ -13,6 +13,7 @@ import (
|
||||
"github.com/caarlos0/log"
|
||||
"github.com/google/go-github/v47/github"
|
||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||
"github.com/goreleaser/goreleaser/pkg/config"
|
||||
"github.com/goreleaser/goreleaser/pkg/context"
|
||||
@ -63,10 +64,19 @@ func (c *githubClient) GenerateReleaseNotes(ctx *context.Context, repo Repo, pre
|
||||
return notes.Body, err
|
||||
}
|
||||
|
||||
func commitAbbrevLen(ctx *context.Context) int {
|
||||
hash, err := git.Clean(git.Run(ctx, "rev-parse", "--short", "HEAD", "--quiet"))
|
||||
if err != nil || len(hash) > 40 {
|
||||
return 40 // max sha1 len
|
||||
}
|
||||
return len(hash)
|
||||
}
|
||||
|
||||
func (c *githubClient) Changelog(ctx *context.Context, repo Repo, prev, current string) (string, error) {
|
||||
var log []string
|
||||
|
||||
commitlen := commitAbbrevLen(ctx)
|
||||
opts := &github.ListOptions{PerPage: 100}
|
||||
|
||||
for {
|
||||
result, resp, err := c.client.Repositories.CompareCommits(ctx, repo.Owner, repo.Name, prev, current, opts)
|
||||
if err != nil {
|
||||
@ -75,7 +85,7 @@ func (c *githubClient) Changelog(ctx *context.Context, repo Repo, prev, current
|
||||
for _, commit := range result.Commits {
|
||||
log = append(log, fmt.Sprintf(
|
||||
"%s: %s (@%s)",
|
||||
commit.GetSHA(),
|
||||
commit.GetSHA()[0:commitlen-1],
|
||||
strings.Split(commit.Commit.GetMessage(), "\n")[0],
|
||||
commit.GetAuthor().GetLogin(),
|
||||
))
|
||||
@ -83,7 +93,6 @@ func (c *githubClient) Changelog(ctx *context.Context, repo Repo, prev, current
|
||||
if resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
opts.Page = resp.NextPage
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ func TestChangelog(t *testing.T) {
|
||||
|
||||
log, err := client.Changelog(ctx, repo, "v1.0.0", "v1.1.0")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "6dcb09b5b57875f334f61aebed695e2e4193db5e: Fix all the bugs (@octocat)", log)
|
||||
require.Equal(t, "6dcb09b: Fix all the bugs (@octocat)", log)
|
||||
}
|
||||
|
||||
func TestReleaseNotes(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user