mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-12 15:00:39 +00:00
feat: support multiple prefixes for issueid and breaking change
This commit is contained in:
parent
7183bc4a1f
commit
f275e1ca2e
@ -18,7 +18,8 @@ you can config using the environment variables
|
||||
|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|
|
||||
|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|
|
||||
|RELEASE_NOTES_TAGS|release notes headers for each visible type|fix:Bug Fixes,feat:Features|
|
||||
|
||||
|
@ -12,7 +12,8 @@ type Config struct {
|
||||
MinorVersionTypes []string `envconfig:"MINOR_VERSION_TYPES" default:"feat"`
|
||||
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"`
|
||||
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"`
|
||||
ReleaseNotesTags map[string]string `envconfig:"RELEASE_NOTES_TAGS" default:"fix:Bug Fixes,feat:Features"`
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ var Version = ""
|
||||
func main() {
|
||||
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)
|
||||
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotesTags)
|
||||
|
||||
|
28
sv/git.go
28
sv/git.go
@ -15,8 +15,8 @@ import (
|
||||
const (
|
||||
logSeparator = "##"
|
||||
endLine = "~~"
|
||||
breakingChangesTag = "BREAKING CHANGE:"
|
||||
issueIDTag = "jira:"
|
||||
breakingChangesKey = "breakingchange"
|
||||
issueIDKey = "issueid"
|
||||
)
|
||||
|
||||
// Git commands
|
||||
@ -45,13 +45,16 @@ type GitTag struct {
|
||||
|
||||
// GitImpl git command implementation
|
||||
type GitImpl struct {
|
||||
messageMetadata map[string]string
|
||||
messageMetadata map[string][]string
|
||||
tagPattern string
|
||||
}
|
||||
|
||||
// NewGit constructor
|
||||
func NewGit(messageMetadata map[string]string, tagPattern string) *GitImpl {
|
||||
return &GitImpl{messageMetadata: messageMetadata, tagPattern: tagPattern}
|
||||
func NewGit(breakinChangePrefixes, issueIDPrefixes []string, tagPattern string) *GitImpl {
|
||||
return &GitImpl{
|
||||
messageMetadata: map[string][]string{breakingChangesKey: breakinChangePrefixes, issueIDKey: issueIDPrefixes},
|
||||
tagPattern: tagPattern,
|
||||
}
|
||||
}
|
||||
|
||||
// Describe runs git describe, it no tag found, return empty
|
||||
@ -125,7 +128,7 @@ func parseTagsOutput(input string) ([]GitTag, error) {
|
||||
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.Split(splitAt([]byte(endLine)))
|
||||
var logs []GitCommitLog
|
||||
@ -137,14 +140,17 @@ func parseLogOutput(messageMetadata map[string]string, log string) []GitCommitLo
|
||||
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)
|
||||
commitType, scope, subject := parseCommitLogMessage(content[1])
|
||||
|
||||
metadata := make(map[string]string)
|
||||
for k, v := range messageMetadata {
|
||||
if tagValue := extractTag(v, content[2]); tagValue != "" {
|
||||
metadata[k] = tagValue
|
||||
for key, prefixes := range messageMetadata {
|
||||
for _, prefix := range prefixes {
|
||||
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 {
|
||||
regex := regexp.MustCompile(tag + ": (.*)")
|
||||
regex := regexp.MustCompile(tag + " (.*)")
|
||||
result := regex.FindStringSubmatch(text)
|
||||
if len(result) < 2 {
|
||||
return ""
|
||||
|
Loading…
Reference in New Issue
Block a user