Skip to content

Commit

Permalink
feat(changelog): show authors of commits and show body as header
Browse files Browse the repository at this point in the history
Enable new features in `.release.yml` like

```yml

changelog:
  showAuthors: false  ## Show authors in changelog
  showBodyAsHeader: false  ## Show all bodies of the commits as header of changelog (useful for squash commit flow to show long text in release)

```
  • Loading branch information
Nightapes authored and fwiedmann committed Apr 11, 2022
1 parent 03f2eea commit 0c7338a
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 482 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ jobs:
build:
strategy:
matrix:
go: ["1.16", "1.17"]
go: ["1.17", "1.18"]
env:
DEFAULT_GO: "1.18"
name: Build with go version ${{ matrix.go }}
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -53,7 +55,7 @@ jobs:
docker tag nightapes/go-semantic-release:development-${{matrix.go}} docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:development-${{matrix.go}}
docker push docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:development-${{matrix.go}}
- uses: actions/upload-artifact@v1
if: matrix.go == '1.17'
if: matrix.go == env.DEFAULT_GO
with:
name: build
path: build
Expand Down
2 changes: 2 additions & 0 deletions .release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ changelog:
docker:
latest: true
repository: "nightapes/go-semantic-release"
showAuthors: true

hooks:
preRelease:
- docker build -t nightapes/go-semantic-release:latest .
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ changelog:
printAll: false ## Print all valid commits to changelog
title: "v{{.Version}} ({{.Now.Format "2006-01-02"}})" ## Used for releases (go template)
templatePath: "./examples/changelog.tmpl" ## Path to a template file (go template)
showAuthors: false ## Show authors in changelog
showBodyAsHeader: false ## Show all bodies of the commits as header of changelog (useful for squash commit flow to show long text in release)
```

##### Docker
Expand Down
47 changes: 34 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
module github.com/Nightapes/go-semantic-release

go 1.16
go 1.17

require (
github.com/Masterminds/semver v1.5.0
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20220113124808-70ae35bab23f // indirect
github.com/go-git/go-billy/v5 v5.3.1
github.com/go-git/go-git/v5 v5.4.2
github.com/google/go-github/v25 v25.1.3
github.com/google/go-querystring v1.1.0 // indirect
github.com/kevinburke/ssh_config v1.1.0 // indirect
github.com/pkg/errors v0.9.1
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.3.0
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.14.0 // indirect
github.com/tidwall/sjson v1.2.4
github.com/xanzy/ssh-agent v0.3.1 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20220407094043-a94812496cf5 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.12.1 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/gjson v1.14.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/xanzy/ssh-agent v0.3.1 // indirect
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 // indirect
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3 // indirect
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
399 changes: 18 additions & 381 deletions go.sum

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions internal/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var defaultTokenSeparators = [2]string{": ", " #"}
type Analyzer struct {
analyzeCommits analyzeCommits
ChangelogConfig config.ChangelogConfig
AnalyzerConfig config.AnalyzerConfig
AnalyzerConfig config.AnalyzerConfig
}

// Rule for commits
Expand All @@ -41,7 +41,7 @@ type analyzeCommits interface {
// New Analyzer struct for given commit format
func New(format string, analyzerConfig config.AnalyzerConfig, chglogConfig config.ChangelogConfig) (*Analyzer, error) {
analyzer := &Analyzer{
AnalyzerConfig: analyzerConfig,
AnalyzerConfig: analyzerConfig,
ChangelogConfig: chglogConfig,
}

Expand Down Expand Up @@ -112,9 +112,9 @@ func getRegexMatchedMap(regEx, url string) (paramsMap map[string]string) {
//
// getMessageBlocksFromTexts converts strings to an array of MessageBlock
//
func getMessageBlocksFromTexts(txtArray, separators []string) []shared.MessageBlock {
func getMessageBlocksFromTexts(txtArray, separators []string) []shared.MessageBlock {
blocks := make([]shared.MessageBlock, len(txtArray))
for i, line := range txtArray{
for i, line := range txtArray {
blocks[i] = parseMessageBlock(line, separators)
}
return blocks
Expand All @@ -128,9 +128,9 @@ func parseMessageBlock(msg string, separators []string) shared.MessageBlock {
Label: "",
Content: msg,
}
if token, sep := findFooterToken(msg, separators); len(token) > 0{
if token, sep := findFooterToken(msg, separators); len(token) > 0 {
msgBlock.Label = token
content := strings.Replace(msg, token + sep, "", 1)
content := strings.Replace(msg, token+sep, "", 1)
msgBlock.Content = strings.TrimSpace(content)
}
return msgBlock
Expand Down Expand Up @@ -158,7 +158,7 @@ func findFooterToken(text string, separators []string) (token string, sep string
// - A footer is detected when it starts with a token ending with a separator
// - A footer ends when another footer is found or text ends
//
func getDefaultMessageBlockMap(txtBlock string, tokenSep []string) map[string][]shared.MessageBlock{
func getDefaultMessageBlockMap(txtBlock string, tokenSep []string) map[string][]shared.MessageBlock {
msgBlockMap := make(map[string][]shared.MessageBlock)
footers := make([]string, 0)
body, footerBlock, line := "", "", ""
Expand All @@ -169,7 +169,7 @@ func getDefaultMessageBlockMap(txtBlock string, tokenSep []string) map[string][]
line = scanner.Text()
if token, _ := findFooterToken(line, tokenSep); len(token) > 0 {
// if footer was already found from before
if len(footerBlock) > 0{
if len(footerBlock) > 0 {
footers = append(footers, strings.TrimSpace(footerBlock))
}
footerFound = true
Expand All @@ -179,7 +179,7 @@ func getDefaultMessageBlockMap(txtBlock string, tokenSep []string) map[string][]
//'\n' is removed when reading from scanner
if !footerFound {
body += line + "\n"
}else{
} else {
footerBlock += line + "\n"
}
}
Expand All @@ -188,11 +188,11 @@ func getDefaultMessageBlockMap(txtBlock string, tokenSep []string) map[string][]
}

body = strings.TrimSpace(body)
if len(body) > 0{
msgBlockMap["body"] = []shared.MessageBlock {{
if len(body) > 0 {
msgBlockMap["body"] = []shared.MessageBlock{{
Label: "",
Content: body,
} }
}}
}

footerBlocks := getMessageBlocksFromTexts(footers, tokenSep)
Expand All @@ -201,4 +201,4 @@ func getDefaultMessageBlockMap(txtBlock string, tokenSep []string) map[string][]
}

return msgBlockMap
}
}
20 changes: 12 additions & 8 deletions internal/analyzer/angular.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
)

type angular struct {
rules []Rule
regex string
log *log.Entry
config config.AnalyzerConfig
rules []Rule
regex string
log *log.Entry
config config.AnalyzerConfig
}

// ANGULAR identifier
const ANGULAR = "angular"

var angularFooterTokenSep = defaultTokenSeparators

func newAngular() *angular {
Expand Down Expand Up @@ -99,17 +100,20 @@ func (a *angular) analyze(commit shared.Commit, rule Rule) *shared.AnalyzedCommi
}
matches := getRegexMatchedMap(a.regex, header)

if len(matches) == 0 || matches["type"] != rule.Tag{
if len(matches) == 0 || matches["type"] != rule.Tag {
a.log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
return nil
}

msgBlockMap := getDefaultMessageBlockMap(body, tokenSep)

log.Debugf("Found commit from Author %s", commit.Author)

analyzed := &shared.AnalyzedCommit{
Commit: commit,
Tag: rule.Tag,
TagString: rule.TagString,
Commit: commit,
Author: commit.Author,
Tag: rule.Tag,
TagString: rule.TagString,
Scope: shared.Scope(matches["scope"]),
Subject: strings.TrimSpace(matches["subject"]),
MessageBlocks: msgBlockMap,
Expand Down
17 changes: 9 additions & 8 deletions internal/analyzer/conventional.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ import (
)

type conventional struct {
rules []Rule
regex string
log *log.Entry
config config.AnalyzerConfig
rules []Rule
regex string
log *log.Entry
config config.AnalyzerConfig
}

// CONVENTIONAL identifier
const CONVENTIONAL = "conventional"

var conventionalFooterTokenSep = defaultTokenSeparators

func newConventional(config config.AnalyzerConfig) *conventional {
return &conventional{
config: config,
regex: `^(?P<type>\w*)(?:\((?P<scope>.*)\))?(?P<breaking>\!)?: (?P<subject>.*)`,
log: log.WithField("analyzer", CONVENTIONAL),
regex: `^(?P<type>\w*)(?:\((?P<scope>.*)\))?(?P<breaking>\!)?: (?P<subject>.*)`,
log: log.WithField("analyzer", CONVENTIONAL),
rules: []Rule{
{
Tag: "feat",
Expand Down Expand Up @@ -101,7 +102,7 @@ func (a *conventional) analyze(commit shared.Commit, rule Rule) *shared.Analyzed

matches := getRegexMatchedMap(a.regex, header)

if len(matches) == 0 || matches["type"] != rule.Tag{
if len(matches) == 0 || matches["type"] != rule.Tag {
a.log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
return nil
}
Expand All @@ -110,6 +111,7 @@ func (a *conventional) analyze(commit shared.Commit, rule Rule) *shared.Analyzed

analyzed := &shared.AnalyzedCommit{
Commit: commit,
Author: commit.Author,
Tag: rule.Tag,
TagString: rule.TagString,
Scope: shared.Scope(matches["scope"]),
Expand Down Expand Up @@ -140,4 +142,3 @@ func (a *conventional) analyze(commit shared.Commit, rule Rule) *shared.Analyzed

return analyzed
}

Loading

0 comments on commit 0c7338a

Please sign in to comment.