0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-22 08:20:39 +00:00

feat: support multiple prefixes for issueid and breaking change

This commit is contained in:
Beatriz Vieira 2020-02-01 19:43:02 -03:00
parent 7183bc4a1f
commit f275e1ca2e
4 changed files with 22 additions and 14 deletions

View File

@ -18,7 +18,8 @@ you can config using the environment variables
|MINOR_VERSION_TYPES|types used to bump minor version|feat| |MINOR_VERSION_TYPES|types used to bump minor version|feat|
|PATCH_VERSION_TYPES|types used to bump patch version|build,ci,docs,fix,perf,refactor,style,test| |PATCH_VERSION_TYPES|types used to bump patch version|build,ci,docs,fix,perf,refactor,style,test|
|INCLUDE_UNKNOWN_TYPE_AS_PATCH|force patch bump on unknown type|true| |INCLUDE_UNKNOWN_TYPE_AS_PATCH|force patch bump on unknown type|true|
|COMMIT_MESSAGE_METADATA|metadata format on commit message|breakingchange:BREAKING CHANGE,issueid:jira| |BRAKING_CHANGE_PREFIXES|list of prefixes that will be used to identify a breaking change|BREAKING CHANGE:,BREAKING CHANGES:|
|ISSUEID_PREFIXES|list of prefixes that will be used to identify an issue id|jira:,JIRA:,Jira:|
|TAG_PATTERN|tag version pattern|%d.%d.%d| |TAG_PATTERN|tag version pattern|%d.%d.%d|
|RELEASE_NOTES_TAGS|release notes headers for each visible type|fix:Bug Fixes,feat:Features| |RELEASE_NOTES_TAGS|release notes headers for each visible type|fix:Bug Fixes,feat:Features|

View File

@ -12,7 +12,8 @@ type Config struct {
MinorVersionTypes []string `envconfig:"MINOR_VERSION_TYPES" default:"feat"` MinorVersionTypes []string `envconfig:"MINOR_VERSION_TYPES" default:"feat"`
PatchVersionTypes []string `envconfig:"PATCH_VERSION_TYPES" default:"build,ci,docs,fix,perf,refactor,style,test"` PatchVersionTypes []string `envconfig:"PATCH_VERSION_TYPES" default:"build,ci,docs,fix,perf,refactor,style,test"`
IncludeUnknownTypeAsPatch bool `envconfig:"INCLUDE_UNKNOWN_TYPE_AS_PATCH" default:"true"` IncludeUnknownTypeAsPatch bool `envconfig:"INCLUDE_UNKNOWN_TYPE_AS_PATCH" default:"true"`
CommitMessageMetadata map[string]string `envconfig:"COMMIT_MESSAGE_METADATA" default:"breakingchange:BREAKING CHANGE,issueid:jira"` BreakingChangePrefixes []string `envconfig:"BRAKING_CHANGE_PREFIXES" default:"BREAKING CHANGE:,BREAKING CHANGES:"`
IssueIDPrefixes []string `envconfig:"ISSUEID_PREFIXES" default:"jira:,JIRA:,Jira:"`
TagPattern string `envconfig:"TAG_PATTERN" default:"%d.%d.%d"` TagPattern string `envconfig:"TAG_PATTERN" default:"%d.%d.%d"`
ReleaseNotesTags map[string]string `envconfig:"RELEASE_NOTES_TAGS" default:"fix:Bug Fixes,feat:Features"` ReleaseNotesTags map[string]string `envconfig:"RELEASE_NOTES_TAGS" default:"fix:Bug Fixes,feat:Features"`
} }

View File

@ -14,7 +14,7 @@ var Version = ""
func main() { func main() {
cfg := loadConfig() cfg := loadConfig()
git := sv.NewGit(cfg.CommitMessageMetadata, cfg.TagPattern) git := sv.NewGit(cfg.BreakingChangePrefixes, cfg.IssueIDPrefixes, cfg.TagPattern)
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.IncludeUnknownTypeAsPatch, cfg.MajorVersionTypes, cfg.MinorVersionTypes, cfg.PatchVersionTypes) semverProcessor := sv.NewSemVerCommitsProcessor(cfg.IncludeUnknownTypeAsPatch, cfg.MajorVersionTypes, cfg.MinorVersionTypes, cfg.PatchVersionTypes)
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotesTags) releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotesTags)

View File

@ -15,8 +15,8 @@ import (
const ( const (
logSeparator = "##" logSeparator = "##"
endLine = "~~" endLine = "~~"
breakingChangesTag = "BREAKING CHANGE:" breakingChangesKey = "breakingchange"
issueIDTag = "jira:" issueIDKey = "issueid"
) )
// Git commands // Git commands
@ -45,13 +45,16 @@ type GitTag struct {
// GitImpl git command implementation // GitImpl git command implementation
type GitImpl struct { type GitImpl struct {
messageMetadata map[string]string messageMetadata map[string][]string
tagPattern string tagPattern string
} }
// NewGit constructor // NewGit constructor
func NewGit(messageMetadata map[string]string, tagPattern string) *GitImpl { func NewGit(breakinChangePrefixes, issueIDPrefixes []string, tagPattern string) *GitImpl {
return &GitImpl{messageMetadata: messageMetadata, tagPattern: tagPattern} return &GitImpl{
messageMetadata: map[string][]string{breakingChangesKey: breakinChangePrefixes, issueIDKey: issueIDPrefixes},
tagPattern: tagPattern,
}
} }
// Describe runs git describe, it no tag found, return empty // Describe runs git describe, it no tag found, return empty
@ -125,7 +128,7 @@ func parseTagsOutput(input string) ([]GitTag, error) {
return result, nil return result, nil
} }
func parseLogOutput(messageMetadata map[string]string, log string) []GitCommitLog { func parseLogOutput(messageMetadata map[string][]string, log string) []GitCommitLog {
scanner := bufio.NewScanner(strings.NewReader(log)) scanner := bufio.NewScanner(strings.NewReader(log))
scanner.Split(splitAt([]byte(endLine))) scanner.Split(splitAt([]byte(endLine)))
var logs []GitCommitLog var logs []GitCommitLog
@ -137,14 +140,17 @@ func parseLogOutput(messageMetadata map[string]string, log string) []GitCommitLo
return logs return logs
} }
func parseCommitLog(messageMetadata map[string]string, commit string) GitCommitLog { func parseCommitLog(messageMetadata map[string][]string, commit string) GitCommitLog {
content := strings.Split(strings.Trim(commit, "\""), logSeparator) content := strings.Split(strings.Trim(commit, "\""), logSeparator)
commitType, scope, subject := parseCommitLogMessage(content[1]) commitType, scope, subject := parseCommitLogMessage(content[1])
metadata := make(map[string]string) metadata := make(map[string]string)
for k, v := range messageMetadata { for key, prefixes := range messageMetadata {
if tagValue := extractTag(v, content[2]); tagValue != "" { for _, prefix := range prefixes {
metadata[k] = tagValue if tagValue := extractTag(prefix, content[2]); tagValue != "" {
metadata[key] = tagValue
break
}
} }
} }
@ -168,7 +174,7 @@ func parseCommitLogMessage(message string) (string, string, string) {
} }
func extractTag(tag, text string) string { func extractTag(tag, text string) string {
regex := regexp.MustCompile(tag + ": (.*)") regex := regexp.MustCompile(tag + " (.*)")
result := regex.FindStringSubmatch(text) result := regex.FindStringSubmatch(text)
if len(result) < 2 { if len(result) < 2 {
return "" return ""