Skip to content

Commit e0458f8

Browse files
Kimmo Saarichristophwitzko
authored andcommitted
feat: Added support for Commit message with ! to draw attention to breaking change
1 parent 80e0ed6 commit e0458f8

File tree

4 files changed

+86
-6
lines changed

4 files changed

+86
-6
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,42 @@
55

66
A [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) analyzer for [go-semantic-release](https://github.com/go-semantic-release/semantic-release).
77

8+
## How the commit messages are analyzed
9+
10+
### Bump major version (0.1.2 -> 1.0.0)
11+
- By adding `BREAKING CHANGE` or `BREAKING CHANGES` in the commit message footer, e.g.:
12+
```
13+
feat: allow provided config object to extend other configs
14+
15+
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
16+
```
17+
- By adding `!` at the end of the commit type, e.g.:
18+
```
19+
refactor!: drop support for Node 6
20+
```
21+
22+
### Bump minor version (0.1.2 -> 0.2.0)
23+
- By using type `feat`, e.g.:
24+
```
25+
feat(lang): add polish language
26+
```
27+
28+
### Bump patch version (0.1.2 -> 0.1.3)
29+
- By using type `fix`, e.g.:
30+
```
31+
fix: correct minor typos in code
32+
33+
see the issue for details
34+
35+
on typos fixed.
36+
37+
Reviewed-by: Z
38+
Refs #133
39+
```
40+
41+
## References
42+
- [Conventional Commit v1.0.0 - Examples](https://www.conventionalcommits.org/en/v1.0.0/#examples)
43+
844
## Licence
945

1046
The [MIT License (MIT)](http://opensource.org/licenses/MIT)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9
5858
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
5959
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
6060
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
61+
github.com/go-semantic-release/semantic-release v1.22.1 h1:tVeMBvHLNfNV5cS7vK6ZFcozV/u4BtZ+pAvROKibQmw=
6162
github.com/go-semantic-release/semantic-release/v2 v2.5.0 h1:QDE5x/D/Rt7c1fcgZ3EGAgKOaBuK30R+SX4oPL8b6QI=
6263
github.com/go-semantic-release/semantic-release/v2 v2.5.0/go.mod h1:2YcQ8CPUnSXnw5Krcakz8gDMrkd+eF69DySp8jAIbQI=
64+
github.com/go-semantic-release/semantic-release/v2 v2.6.0 h1:hau9IVTeBjxEE7pQoKyhlATWRDjlKY8R/4RXdpa5FRE=
6365
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
6466
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
6567
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=

pkg/analyzer/commit_analyzer.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
var CAVERSION = "dev"
11-
var commitPattern = regexp.MustCompile(`^(\w*)(?:\((.*)\))?\: (.*)$`)
11+
var commitPattern = regexp.MustCompile(`^(\w*)(!)?(?:\((.*)\))?\: (.*)$`)
1212
var breakingPattern = regexp.MustCompile("BREAKING CHANGES?")
1313

1414
type DefaultCommitAnalyzer struct{}
@@ -34,12 +34,24 @@ func (da *DefaultCommitAnalyzer) analyzeSingleCommit(rawCommit *semrel.RawCommit
3434
return c
3535
}
3636
c.Type = strings.ToLower(found[0][1])
37-
c.Scope = found[0][2]
38-
c.Message = found[0][3]
37+
breakingChange := found[0][2]
38+
c.Scope = found[0][3]
39+
c.Message = found[0][4]
40+
41+
isMajorChange := breakingPattern.MatchString(rawCommit.RawMessage)
42+
isMinorChange := c.Type == "feat"
43+
isPatchChange := c.Type == "fix"
44+
45+
if len(breakingChange) > 0 {
46+
isMajorChange = true
47+
isMinorChange = false
48+
isPatchChange = false
49+
}
50+
3951
c.Change = &semrel.Change{
40-
Major: breakingPattern.MatchString(rawCommit.RawMessage),
41-
Minor: c.Type == "feat",
42-
Patch: c.Type == "fix",
52+
Major: isMajorChange,
53+
Minor: isMinorChange,
54+
Patch: isPatchChange,
4355
}
4456
return c
4557
}

pkg/analyzer/commit_analyzer_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,36 @@ func TestDefaultAnalyzer(t *testing.T) {
5858
"",
5959
&semrel.Change{Major: true, Minor: false, Patch: false},
6060
},
61+
{
62+
createRawCommit("e", "feat!: modified login endpoint"),
63+
"feat",
64+
"",
65+
&semrel.Change{Major: true, Minor: false, Patch: false},
66+
},
67+
{
68+
createRawCommit("f", "fix!: fixed a typo"),
69+
"fix",
70+
"",
71+
&semrel.Change{Major: true, Minor: false, Patch: false},
72+
},
73+
{
74+
createRawCommit("g", "refactor!: drop support for Node 6\n\nBREAKING CHANGE: refactor to use JavaScript features not available in Node 6."),
75+
"refactor",
76+
"",
77+
&semrel.Change{Major: true, Minor: false, Patch: false},
78+
},
79+
{
80+
createRawCommit("h", "docs: added more documentation"),
81+
"docs",
82+
"",
83+
&semrel.Change{Major: false, Minor: false, Patch: false},
84+
},
85+
{
86+
createRawCommit("i", "chore: moved README.md to root"),
87+
"chore",
88+
"",
89+
&semrel.Change{Major: false, Minor: false, Patch: false},
90+
},
6191
}
6292

6393
defaultAnalyzer := &DefaultCommitAnalyzer{}

0 commit comments

Comments
 (0)