Skip to content
Snippets Groups Projects
Commit e0458f81 authored by Kimmo Saari's avatar Kimmo Saari Committed by Christoph Witzko
Browse files

feat: Added support for `Commit message with ! to draw attention to breaking change`

parent 80e0ed61
Branches
Tags
No related merge requests found
......@@ -5,6 +5,42 @@
A [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) analyzer for [go-semantic-release](https://github.com/go-semantic-release/semantic-release).
## How the commit messages are analyzed
### Bump major version (0.1.2 -> 1.0.0)
- By adding `BREAKING CHANGE` or `BREAKING CHANGES` in the commit message footer, e.g.:
```
feat: allow provided config object to extend other configs
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
```
- By adding `!` at the end of the commit type, e.g.:
```
refactor!: drop support for Node 6
```
### Bump minor version (0.1.2 -> 0.2.0)
- By using type `feat`, e.g.:
```
feat(lang): add polish language
```
### Bump patch version (0.1.2 -> 0.1.3)
- By using type `fix`, e.g.:
```
fix: correct minor typos in code
see the issue for details
on typos fixed.
Reviewed-by: Z
Refs #133
```
## References
- [Conventional Commit v1.0.0 - Examples](https://www.conventionalcommits.org/en/v1.0.0/#examples)
## Licence
The [MIT License (MIT)](http://opensource.org/licenses/MIT)
......
......@@ -8,7 +8,7 @@ import (
)
var CAVERSION = "dev"
var commitPattern = regexp.MustCompile(`^(\w*)(?:\((.*)\))?\: (.*)$`)
var commitPattern = regexp.MustCompile(`^(\w*)(!)?(?:\((.*)\))?\: (.*)$`)
var breakingPattern = regexp.MustCompile("BREAKING CHANGES?")
type DefaultCommitAnalyzer struct{}
......@@ -34,12 +34,24 @@ func (da *DefaultCommitAnalyzer) analyzeSingleCommit(rawCommit *semrel.RawCommit
return c
}
c.Type = strings.ToLower(found[0][1])
c.Scope = found[0][2]
c.Message = found[0][3]
breakingChange := found[0][2]
c.Scope = found[0][3]
c.Message = found[0][4]
isMajorChange := breakingPattern.MatchString(rawCommit.RawMessage)
isMinorChange := c.Type == "feat"
isPatchChange := c.Type == "fix"
if len(breakingChange) > 0 {
isMajorChange = true
isMinorChange = false
isPatchChange = false
}
c.Change = &semrel.Change{
Major: breakingPattern.MatchString(rawCommit.RawMessage),
Minor: c.Type == "feat",
Patch: c.Type == "fix",
Major: isMajorChange,
Minor: isMinorChange,
Patch: isPatchChange,
}
return c
}
......
......@@ -58,6 +58,36 @@ func TestDefaultAnalyzer(t *testing.T) {
"",
&semrel.Change{Major: true, Minor: false, Patch: false},
},
{
createRawCommit("e", "feat!: modified login endpoint"),
"feat",
"",
&semrel.Change{Major: true, Minor: false, Patch: false},
},
{
createRawCommit("f", "fix!: fixed a typo"),
"fix",
"",
&semrel.Change{Major: true, Minor: false, Patch: false},
},
{
createRawCommit("g", "refactor!: drop support for Node 6\n\nBREAKING CHANGE: refactor to use JavaScript features not available in Node 6."),
"refactor",
"",
&semrel.Change{Major: true, Minor: false, Patch: false},
},
{
createRawCommit("h", "docs: added more documentation"),
"docs",
"",
&semrel.Change{Major: false, Minor: false, Patch: false},
},
{
createRawCommit("i", "chore: moved README.md to root"),
"chore",
"",
&semrel.Change{Major: false, Minor: false, Patch: false},
},
}
defaultAnalyzer := &DefaultCommitAnalyzer{}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment