8000 feat(gitea): implement `Changelog` function (#4794) · goreleaser/goreleaser@c8488dc · GitHub
[go: up one dir, main page]

Skip to content

Commit c8488dc

Browse files
appleboycaarlos0
andauthored
feat(gitea): implement Changelog function (#4794)
- Add `strings` package import to `gitea.go` - Implement `Changelog` function in `gitea.go` - Update `useGitea` constant in `changelog.go` - Add test for `useGitea` in `changelog_test.go` - Update `changelog.md` with information about `gitea` customization ref: * Server API: go-gitea/gitea#30349 * SDK: https://gitea.com/gitea/go-sdk/pulls/659 --------- Signed-off-by: appleboy <appleboy.tw@gmail.com> Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
1 parent faadd02 commit c8488dc

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

internal/client/gitea.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"os"
1010
"strconv"
11+
"strings"
1112

1213
"code.gitea.io/sdk/gitea"
1314
"github.com/caarlos0/log"
@@ -73,8 +74,24 @@ func newGitea(ctx *context.Context, token string) (*giteaClient, error) {
7374
return &giteaClient{client: client}, nil
7475
}
7576

76-
func (c *giteaClient) Changelog(_ *context.Context, _ Repo, _, _ string) (string, error) {
77-
return "", ErrNotImplemented
77+
// Changelog fetches the changelog between two revisions.
78+
func (c *giteaClient) Changelog(_ *context.Context, repo Repo, prev, current string) (string, error) {
79+
result, _, err := c.client.CompareCommits(repo.Owner, repo.Name, prev, current)
80+
if err != nil {
81+
return "", err
82+
}
83+
var log []string
84+
85+
for _, commit := range result.Commits {
86+
log = append(log, fmt.Sprintf(
87+
"%s: %s (@%s <%s>)",
88+
commit.SHA[:7],
89+
strings.Split(commit.RepoCommit.Message, "\n")[0],
90+
commit.Author.UserName,
91+
commit.RepoCommit.Author.Email,
92+
))
93+
}
94+
return strings.Join(log, "\n"), nil
7895
}
7996

8097
// CloseMilestone closes a given milestone.

internal/pipe/changelog/changelog.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (u useChangelog) formatable() bool {
3232
const (
3333
useGit = "git"
3434
useGitHub = "github"
35+
useGitea = "gitea"
3536
useGitLab = "gitlab"
3637
useGitHubNative = "github-native"
3738
)
@@ -347,6 +348,8 @@ func getChangeloger(ctx *context.Context) (changeloger, error) {
347348
fallthrough
348349
case useGitLab:
349350
return newSCMChangeloger(ctx)
351+
case useGitea:
352+
return newSCMChangeloger(ctx)
350353
case useGitHubNative:
351354
return newGithubChangeloger(ctx)
352355
default:

internal/pipe/changelog/changelog_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,18 @@ func TestGetChangeloger(t *testing.T) {
663663
require.Nil(t, c)
664664
})
665665

666+
t.Run(useGitea, func(t *testing.T) {
667+
ctx := context.New(config.Project{
668+
Changelog: config.Changelog{
669+
Use: useGitea,
670+
},
671+
})
672+
ctx.TokenType = context.TokenTypeGitea
673+
c, err := getChangeloger(ctx)
674+
require.NoError(t, err)
675+
require.IsType(t, c, &scmChangeloger{})
676+
})
677+
666678
t.Run("invalid", func(t *testing.T) {
667679
c, err := getChangeloger(testctx.NewWithCfg(config.Project{
668680
Changelog: config.Changelog{
@@ -815,7 +827,7 @@ func TestChangelogFormat(t *testing.T) {
815827
return config.Project{Changelog: config.Changelog{Use: u}}
816828
}
817829

818-
for _, use := range []string{useGit, useGitHub, useGitLab} {
830+
for _, use := range []string{useGit, useGitHub, useGitLab, useGitea} {
819831
t.Run(use, func(t *testing.T) {
820832
out, err := formatChangelog(
821833
testctx.NewWithCfg(makeConf(use)),
@@ -873,7 +885,7 @@ func TestChangelogFormat(t *testing.T) {
873885
* aea123 foo
874886
* aef653 bar`, out)
875887
})
876-
for _, use := range []string{useGit, useGitHub, useGitLab} {
888+
for _, use := range []string{useGit, useGitHub, useGitLab, useGitea} {
877889
t.Run(use, func(t *testing.T) {
878890
out, err := formatChangelog(
879891
testctx.NewWithCfg(makeConf(use)),

www/docs/customization/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ changelog:
2121
# - `git`: uses `git log`;
2222
# - `github`: uses the compare GitHub API, appending the author login to the changelog.
2323
# - `gitlab`: uses the compare GitLab API, appending the author name and email to the changelog.
24+
# - `gitea`: uses the compare Gitea API, appending the author username and email to the changelog.
2425
# - `github-native`: uses the GitHub release notes generation API, disables the groups feature.
2526
#
2627
# Default: 'git'

0 commit comments

Comments
 (0)
0