Skip to content

Commit 94341dd

Browse files
committed
fix(repo): Changelog generation
1 parent 17630ce commit 94341dd

File tree

8 files changed

+63
-14
lines changed

8 files changed

+63
-14
lines changed

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.25.2
44

55
require (
66
github.com/Masterminds/semver/v3 v3.4.0
7-
github.com/go-git/go-git/v5 v5.16.2
8-
github.com/gofrs/flock v0.12.1
7+
github.com/go-git/go-git/v5 v5.16.3
8+
github.com/gofrs/flock v0.13.0
99
github.com/google/go-github/v74 v74.0.0
1010
github.com/google/uuid v1.6.0
1111
github.com/sethvargo/go-retry v0.3.0
@@ -14,7 +14,8 @@ require (
1414
github.com/spf13/viper v1.21.0
1515
github.com/stretchr/testify v1.11.1
1616
go.uber.org/zap v1.27.0
17-
golang.org/x/oauth2 v0.31.0
17+
golang.org/x/oauth2 v0.32.0
18+
golang.org/x/sync v0.17.0
1819
)
1920

2021
require (
@@ -50,8 +51,7 @@ require (
5051
go.yaml.in/yaml/v3 v3.0.4 // indirect
5152
golang.org/x/crypto v0.37.0 // indirect
5253
golang.org/x/net v0.39.0 // indirect
53-
golang.org/x/sync v0.17.0 // indirect
54-
golang.org/x/sys v0.32.0 // indirect
54+
golang.org/x/sys v0.37.0 // indirect
5555
golang.org/x/text v0.28.0 // indirect
5656
gopkg.in/warnings.v0 v0.1.2 // indirect
5757
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ github.com/go-git/go-billy/v5 v5.6.2 h1:6Q86EsPXMa7c3YZ3aLAQsMA0VlWmy43r6FHqa/UN
3535
github.com/go-git/go-billy/v5 v5.6.2/go.mod h1:rcFC2rAsp/erv7CMz9GczHcuD0D32fWzH+MJAU+jaUU=
3636
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
3737
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
38-
github.com/go-git/go-git/v5 v5.16.2 h1:fT6ZIOjE5iEnkzKyxTHK1W4HGAsPhqEqiSAssSO77hM=
39-
github.com/go-git/go-git/v5 v5.16.2/go.mod h1:4Ge4alE/5gPs30F2H1esi2gPd69R0C39lolkucHBOp8=
38+
github.com/go-git/go-git/v5 v5.16.3 h1:Z8BtvxZ09bYm/yYNgPKCzgWtaRqDTgIKRgIRHBfU6Z8=
39+
github.com/go-git/go-git/v5 v5.16.3/go.mod h1:4Ge4alE/5gPs30F2H1esi2gPd69R0C39lolkucHBOp8=
4040
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
4141
github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
42-
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
43-
github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0=
42+
github.com/gofrs/flock v0.13.0 h1:95JolYOvGMqeH31+FC7D2+uULf6mG61mEZ/A8dRYMzw=
43+
github.com/gofrs/flock v0.13.0/go.mod h1:jxeyy9R1auM5S6JYDBhDt+E2TCo7DkratH4Pgi8P+Z0=
4444
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ=
4545
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw=
4646
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
@@ -127,8 +127,8 @@ golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbR
127127
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
128128
golang.org/x/net v0.39.0 h1:ZCu7HMWDxpXpaiKdhzIfaltL9Lp31x/3fCP11bc6/fY=
129129
golang.org/x/net v0.39.0/go.mod h1:X7NRbYVEA+ewNkCNyJ513WmMdQ3BineSwVtN2zD/d+E=
130-
golang.org/x/oauth2 v0.31.0 h1:8Fq0yVZLh4j4YA47vHKFTa9Ew5XIrCP8LC6UeNZnLxo=
131-
golang.org/x/oauth2 v0.31.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
130+
golang.org/x/oauth2 v0.32.0 h1:jsCblLleRMDrxMN29H3z/k1KliIvpLgCkE6R8FXXNgY=
131+
golang.org/x/oauth2 v0.32.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
132132
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
133133
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
134134
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -137,8 +137,8 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
137137
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
138138
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
139139
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
140-
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
141-
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
140+
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
141+
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
142142
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
143143
golang.org/x/term v0.31.0 h1:erwDkOK1Msy6offm1mOgvspSkslFnIGsFnxOKoufg3o=
144144
golang.org/x/term v0.31.0/go.mod h1:R4BeIy7D95HzImkxGkTW1UQTtP54tio2RyHz7PwK0aw=

internal/orchestrator/mocks_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ func (m *mockCliffService) GenerateChangelog(ctx context.Context, version, mode
155155
return args.String(0), args.Error(1)
156156
}
157157

158+
func (m *mockCliffService) GenerateFullChangelog(ctx context.Context) (string, error) {
159+
for _, call := range m.ExpectedCalls {
160+
if call.Method == "GenerateFullChangelog" {
161+
args := m.Called(ctx)
162+
return args.String(0), args.Error(1)
163+
}
164+
}
165+
return "# Mock changelog\n", nil
166+
}
167+
158168
// Mock for NpmService
159169
type mockNpmService struct{ mock.Mock }
160170

internal/orchestrator/pr_release.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,14 @@ func (o *PRReleaseOrchestrator) generateChangelog(ctx context.Context, version,
258258
if err != nil {
259259
return "", err
260260
}
261+
262+
fullChangelog, err := o.cliffSvc.GenerateFullChangelog(ctx)
263+
if err != nil {
264+
return "", fmt.Errorf("failed to build complete changelog: %w", err)
265+
}
266+
261267
// Write changelog to file using filesystem repository
262-
if err := afero.WriteFile(o.fsRepo, "CHANGELOG.md", []byte(changelog), FilePermissionsReadWrite); err != nil {
268+
if err := afero.WriteFile(o.fsRepo, "CHANGELOG.md", []byte(fullChangelog), FilePermissionsReadWrite); err != nil {
263269
return "", fmt.Errorf("failed to write changelog: %w", err)
264270
}
265271
// Also create release notes

internal/orchestrator/pr_release_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ func TestPRReleaseOrchestrator_Execute(t *testing.T) {
4747

4848
// Setup expectations for generateChangelog
4949
changelog := "## v1.1.0\n\n### Features\n- New feature added\n### Bug Fixes\n- Fixed critical bug"
50+
fullChangelog := "# Changelog\n\n" + changelog + "\n\n## v1.0.0\n\n### Misc\n- Previous entry"
5051
cliffSvc.On("GenerateChangelog", mock.Anything, "v1.1.0", "unreleased").Return(changelog, nil).Once()
52+
cliffSvc.On("GenerateFullChangelog", mock.Anything).Return(fullChangelog, nil).Once()
5153

5254
// Setup expectations for commitChanges
5355
gitRepo.On("ConfigureUser", mock.Anything, "github-actions[bot]", "github-actions[bot]@users.noreply.github.com").
@@ -85,8 +87,18 @@ func TestPRReleaseOrchestrator_Execute(t *testing.T) {
8587
// Verify files were created
8688
changelogExists, _ := afero.Exists(fsRepo, "CHANGELOG.md")
8789
assert.True(t, changelogExists, "CHANGELOG.md should be created")
90+
if changelogExists {
91+
data, err := afero.ReadFile(fsRepo, "CHANGELOG.md")
92+
require.NoError(t, err)
93+
assert.Equal(t, fullChangelog, string(data))
94+
}
8895
releaseNotesExists, _ := afero.Exists(fsRepo, "RELEASE_NOTES.md")
8996
assert.True(t, releaseNotesExists, "RELEASE_NOTES.md should be created")
97+
if releaseNotesExists {
98+
data, err := afero.ReadFile(fsRepo, "RELEASE_NOTES.md")
99+
require.NoError(t, err)
100+
assert.Equal(t, changelog, string(data))
101+
}
90102
})
91103

92104
t.Run("Should skip PR creation when no changes exist and force flag is false", func(t *testing.T) {

internal/service/cliff.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ import (
1111
type CliffService interface {
1212
CalculateNextVersion(ctx context.Context, latestTag string) (*domain.Version, error)
1313
GenerateChangelog(ctx context.Context, version, mode string) (string, error)
14+
GenerateFullChangelog(ctx context.Context) (string, error)
1415
}

internal/service/cliff_impl.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,18 @@ func (s *cliffService) GenerateChangelog(ctx context.Context, version, mode stri
181181

182182
return changelog, nil
183183
}
184+
185+
// GenerateFullChangelog renders the complete changelog using git-cliff.
186+
func (s *cliffService) GenerateFullChangelog(ctx context.Context) (string, error) {
187+
output, err := s.executeCommand(ctx, "git-cliff", "-o", "-")
188+
if err != nil {
189+
return "", fmt.Errorf("failed to execute git-cliff: %w", err)
190+
}
191+
192+
changelog := string(output)
193+
if strings.TrimSpace(changelog) == "" {
194+
return "", fmt.Errorf("git-cliff returned empty changelog")
195+
}
196+
197+
return changelog, nil
198+
}

internal/usecase/check_changes_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func (m *mockCliffService) GenerateChangelog(ctx context.Context, version, mode
6161
return args.String(0), args.Error(1)
6262
}
6363

64+
func (m *mockCliffService) GenerateFullChangelog(ctx context.Context) (string, error) {
65+
args := m.Called(ctx)
66+
return args.String(0), args.Error(1)
67+
}
68+
6469
func (m *mockCliffService) CalculateNextVersion(ctx context.Context, currentVersion string) (*domain.Version, error) {
6570
args := m.Called(ctx, currentVersion)
6671
if args.Get(0) == nil {

0 commit comments

Comments
 (0)