You've already forked go-semantic-release
feat(changelog): show authors of commits and show body as header
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) ```
This commit is contained in:
committed by
Felix Wiedmann
parent
03f2eeadaa
commit
0c7338ab13
@@ -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
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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 := "", "", ""
|
||||
@@ -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
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
@@ -201,4 +201,4 @@ func getDefaultMessageBlockMap(txtBlock string, tokenSep []string) map[string][]
|
||||
}
|
||||
|
||||
return msgBlockMap
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
@@ -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
|
||||
}
|
||||
@@ -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"]),
|
||||
@@ -140,4 +142,3 @@ func (a *conventional) analyze(commit shared.Commit, rule Rule) *shared.Analyzed
|
||||
|
||||
return analyzed
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user