Skip to content

Commit 3bc68d9

Browse files
Nightapesfwiedmann
authored andcommitted
feat(changelog): add npm helper text to changelog
1 parent c7d6c7c commit 3bc68d9

File tree

3 files changed

+147
-28
lines changed

3 files changed

+147
-28
lines changed

internal/changelog/changelog.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ introduced by commit:
3232
{{ end -}}
3333
{{ end -}}
3434
{{ end -}}`
35-
const defaultCommitListSubTemplate string = `{{ define "commitList" }}` + defaultCommitList + "{{ end }}"
36-
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
37-
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
35+
const defaultCommitListSubTemplate = `{{ define "commitList" }}` + defaultCommitList + "{{ end }}"
36+
const defaultChangelogTitle = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
37+
const defaultChangelog = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
3838
{{ template "commitList" .CommitsContent -}}
3939
4040
{{ if .HasDocker}}
@@ -50,18 +50,37 @@ or
5050
5151
{{$.Backtick}}docker run {{.DockerRepository}}:latest{{$.Backtick}}
5252
{{ end -}}
53+
{{ end -}}
54+
55+
{{ if .HasNPM}}
56+
## NodeJS Package
57+
58+
New NodeJS package is released under [{{.NPMPackageName}}]({{.NPMRepository}})
59+
60+
### Usage
61+
62+
{{$.Backtick}}yarn add {{.NPMPackageName}}@{{.Version}}{{$.Backtick}}
63+
64+
or
65+
66+
{{$.Backtick}}npm install -save {{.NPMPackageName}}@{{.Version}}{{$.Backtick}}
67+
5368
{{ end -}}
5469
`
5570

5671
type changelogContent struct {
57-
Commits string
72+
Commits string
5873
CommitsContent commitsContent
5974
Version string
6075
Now time.Time
6176
Backtick string
6277
HasDocker bool
6378
HasDockerLatest bool
6479
DockerRepository string
80+
HasNPM bool
81+
IsYarn bool
82+
NPMRepository string
83+
NPMPackageName string
6584
}
6685

6786
type commitsContent struct {
@@ -130,13 +149,16 @@ func (c *Changelog) GenerateChangelog(templateConfig shared.ChangelogTemplateCon
130149
}
131150

132151
changelogContent := changelogContent{
133-
CommitsContent: commitsContent,
152+
CommitsContent: commitsContent,
134153
Version: templateConfig.Version,
135154
Now: c.releaseTime,
136155
Backtick: "`",
137156
HasDocker: c.config.Changelog.Docker.Repository != "",
138157
HasDockerLatest: c.config.Changelog.Docker.Latest,
139158
DockerRepository: c.config.Changelog.Docker.Repository,
159+
HasNPM: c.config.Changelog.NPM.PackageName != "",
160+
NPMPackageName: c.config.Changelog.NPM.PackageName,
161+
NPMRepository: c.config.Changelog.NPM.Repository,
140162
}
141163

142164
chglogTemplate := defaultCommitListSubTemplate + defaultChangelog
@@ -168,8 +190,8 @@ func (c *Changelog) GenerateChangelog(templateConfig shared.ChangelogTemplateCon
168190
log.Tracef("Commits %s", renderedCommitList)
169191
changelogContent.Commits = renderedCommitList
170192

171-
extraFuncMap := template.FuncMap {
172-
"commitUrl": func() string {return templateConfig.CommitURL},
193+
extraFuncMap := template.FuncMap{
194+
"commitUrl": func() string { return templateConfig.CommitURL },
173195
}
174196
log.Debugf("Render changelog")
175197
renderedContent, err := generateTemplate(chglogTemplate, changelogContent, extraFuncMap)
@@ -180,10 +202,10 @@ func (c *Changelog) GenerateChangelog(templateConfig shared.ChangelogTemplateCon
180202
func generateTemplate(text string, values interface{}, extraFuncMap template.FuncMap) (string, error) {
181203

182204
funcMap := template.FuncMap{
183-
"replace": replace,
184-
"lower": lower,
185-
"upper": upper,
186-
"capitalize": capitalize,
205+
"replace": replace,
206+
"lower": lower,
207+
"upper": upper,
208+
"capitalize": capitalize,
187209
"addPrefixToLines": addPrefixToLines,
188210
}
189211

internal/changelog/changelog_test.go

Lines changed: 107 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestChangelog(t *testing.T) {
4141
Tag: "feat",
4242
TagString: "Features",
4343
Print: true,
44-
Subject: "my first commit",
44+
Subject: "my first commit",
4545
MessageBlocks: map[string][]shared.MessageBlock{},
4646
},
4747
},
@@ -66,7 +66,7 @@ func TestChangelog(t *testing.T) {
6666
Tag: "feat",
6767
TagString: "Features",
6868
Print: true,
69-
Subject: "my first commit",
69+
Subject: "my first commit",
7070
MessageBlocks: map[string][]shared.MessageBlock{},
7171
},
7272
},
@@ -92,7 +92,7 @@ func TestChangelog(t *testing.T) {
9292
Tag: "feat",
9393
TagString: "Features",
9494
Print: true,
95-
Subject: "my first commit",
95+
Subject: "my first commit",
9696
MessageBlocks: map[string][]shared.MessageBlock{},
9797
},
9898
{
@@ -107,10 +107,10 @@ func TestChangelog(t *testing.T) {
107107
TagString: "Features",
108108
Print: true,
109109
ParsedBreakingChangeMessage: "change api to v2",
110-
IsBreaking: true,
111-
Subject: "my first break",
110+
IsBreaking: true,
111+
Subject: "my first break",
112112
MessageBlocks: map[string][]shared.MessageBlock{
113-
"body" : { shared.MessageBlock{
113+
"body": {shared.MessageBlock{
114114
Label: "BREAKING CHANGE",
115115
Content: "change api to v2",
116116
},
@@ -141,10 +141,10 @@ func TestChangelog(t *testing.T) {
141141
TagString: "Features",
142142
Print: true,
143143
ParsedBreakingChangeMessage: "hey from the change",
144-
IsBreaking: true,
145-
Subject: "my first break",
144+
IsBreaking: true,
145+
Subject: "my first break",
146146
MessageBlocks: map[string][]shared.MessageBlock{
147-
"body" : { shared.MessageBlock{
147+
"body": {shared.MessageBlock{
148148
Label: "BREAKING CHANGE",
149149
Content: "hey from the change",
150150
},
@@ -162,7 +162,7 @@ func TestChangelog(t *testing.T) {
162162
Tag: "feat",
163163
TagString: "Features",
164164
Print: true,
165-
Subject: "my first commit",
165+
Subject: "my first commit",
166166
MessageBlocks: map[string][]shared.MessageBlock{},
167167
},
168168
{
@@ -176,7 +176,7 @@ func TestChangelog(t *testing.T) {
176176
Tag: "feat",
177177
TagString: "Features",
178178
Print: true,
179-
Subject: "my second commit",
179+
Subject: "my second commit",
180180
MessageBlocks: map[string][]shared.MessageBlock{},
181181
},
182182
{
@@ -191,10 +191,10 @@ func TestChangelog(t *testing.T) {
191191
TagString: "Features",
192192
Print: true,
193193
ParsedBreakingChangeMessage: "change api to v2",
194-
IsBreaking: true,
195-
Subject: "my new commit",
194+
IsBreaking: true,
195+
Subject: "my new commit",
196196
MessageBlocks: map[string][]shared.MessageBlock{
197-
"body": { shared.MessageBlock{
197+
"body": {shared.MessageBlock{
198198
Label: "BREAKING CHANGE",
199199
Content: "change api to v2",
200200
}},
@@ -212,9 +212,9 @@ func TestChangelog(t *testing.T) {
212212
TagString: "Features",
213213
Print: true,
214214
ParsedBreakingChangeMessage: "my next commit",
215-
IsBreaking: true,
216-
Subject: "my next commit",
217-
MessageBlocks: map[string][]shared.MessageBlock{},
215+
IsBreaking: true,
216+
Subject: "my next commit",
217+
MessageBlocks: map[string][]shared.MessageBlock{},
218218
},
219219
},
220220
},
@@ -256,3 +256,93 @@ func TestChangelog(t *testing.T) {
256256
}
257257

258258
}
259+
260+
func TestChangelogExtensions(t *testing.T) {
261+
262+
testConfigs := []struct {
263+
testCase string
264+
result *shared.GeneratedChangelog
265+
releaseConfig *config.ReleaseConfig
266+
}{
267+
{
268+
testCase: "docker",
269+
releaseConfig: &config.ReleaseConfig{
270+
Changelog: config.ChangelogConfig{
271+
Docker: config.ChangelogDocker{
272+
Latest: true,
273+
Repository: "mydocker.de",
274+
},
275+
NPM: config.ChangelogNPM{},
276+
},
277+
},
278+
result: &shared.GeneratedChangelog{Title: "v1.0.0 (2019-07-19)", Content: "# v1.0.0 (2019-07-19)\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n\n## Docker image\n\nNew docker image is released under `mydocker.de:1.0.0`\n\n### Usage\n\n`docker run mydocker.de:1.0.0`\n\nor\n\n`docker run mydocker.de:latest`\n"},
279+
},
280+
{
281+
testCase: "npm",
282+
releaseConfig: &config.ReleaseConfig{
283+
Changelog: config.ChangelogConfig{
284+
Docker: config.ChangelogDocker{},
285+
NPM: config.ChangelogNPM{
286+
Repository: "https://github.com/Nightapes/ngx-validators/packages/102720",
287+
PackageName: "ngx-validators",
288+
},
289+
},
290+
},
291+
result: &shared.GeneratedChangelog{Title: "v1.0.0 (2019-07-19)", Content: "# v1.0.0 (2019-07-19)\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n\n## NodeJS Package\n\nNew NodeJS package is released under [ngx-validators](https://github.com/Nightapes/ngx-validators/packages/102720)\n\n### Usage\n\n`yarn add [email protected]`\n\nor\n\n`npm install -save [email protected]`\n\n"},
292+
},
293+
}
294+
295+
analyzedCommits := map[shared.Release][]shared.AnalyzedCommit{
296+
"minor": {
297+
{
298+
Commit: shared.Commit{
299+
Message: "feat(internal/changelog): my first commit",
300+
Author: "me",
301+
Hash: "12345667",
302+
},
303+
Scope: "internal/changelog",
304+
ParsedMessage: "my first commit",
305+
Tag: "feat",
306+
TagString: "Features",
307+
Print: true,
308+
Subject: "my first commit",
309+
MessageBlocks: map[string][]shared.MessageBlock{},
310+
},
311+
},
312+
}
313+
314+
for _, config := range testConfigs {
315+
t.Run(config.testCase, func(t *testing.T) {
316+
templateConfig := shared.ChangelogTemplateConfig{
317+
CommitURL: "https://commit.url",
318+
CompareURL: "https://compare.url",
319+
Hash: "hash",
320+
Version: "1.0.0",
321+
}
322+
cl := changelog.New(config.releaseConfig, []analyzer.Rule{
323+
{
324+
Tag: "feat",
325+
TagString: "Features",
326+
Release: "minor",
327+
Changelog: true,
328+
},
329+
{
330+
Tag: "fix",
331+
TagString: "Bug fixes",
332+
Release: "patch",
333+
Changelog: true,
334+
},
335+
{
336+
Tag: "build",
337+
TagString: "Build",
338+
Release: "none",
339+
Changelog: false,
340+
},
341+
}, time.Date(2019, 7, 19, 0, 0, 0, 0, time.UTC))
342+
generatedChangelog, err := cl.GenerateChangelog(templateConfig, analyzedCommits)
343+
assert.NoError(t, err)
344+
assert.Equalf(t, config.result, generatedChangelog, "Testcase %s should have generated changelog", config.testCase)
345+
})
346+
}
347+
348+
}

pkg/semanticrelease/semantic-release.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package semanticrelease
22

33
import (
4+
"github.com/Nightapes/go-semantic-release/internal/integrations"
45
"io/ioutil"
56
"time"
67

@@ -226,6 +227,12 @@ func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error
226227
return err
227228
}
228229

230+
integrations := integrations.New(&s.config.Integrations, releaseVersion)
231+
if err := integrations.Run(); err != nil {
232+
log.Debugf("Error during integrations run")
233+
return err
234+
}
235+
229236
hook := hooks.New(s.config, releaseVersion)
230237
if err := hook.PreRelease(); err != nil {
231238
log.Debugf("Error during pre release hook")

0 commit comments

Comments
 (0)