You've already forked go-semantic-release
feat(analyzer): add 'DRAFT' as messeage identifier
This commit is contained in:
@@ -24,7 +24,7 @@ type Rule struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type analyzeCommit interface {
|
type analyzeCommit interface {
|
||||||
analyze(commit gitutil.Commit, tag Rule) (AnalyzedCommit, bool, error)
|
analyze(commit gitutil.Commit, tag Rule) (AnalyzedCommit, bool, bool, error)
|
||||||
getRules() []Rule
|
getRules() []Rule
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +34,7 @@ type AnalyzedCommit struct {
|
|||||||
ParsedMessage string
|
ParsedMessage string
|
||||||
Scope string
|
Scope string
|
||||||
ParsedBreakingChangeMessage string
|
ParsedBreakingChangeMessage string
|
||||||
|
ParsedDraftMessage string
|
||||||
Tag string
|
Tag string
|
||||||
TagString string
|
TagString string
|
||||||
Print bool
|
Print bool
|
||||||
@@ -68,11 +69,12 @@ func (a *Analyzer) Analyze(commits []gitutil.Commit) map[string][]AnalyzedCommit
|
|||||||
analyzedCommits["major"] = make([]AnalyzedCommit, 0)
|
analyzedCommits["major"] = make([]AnalyzedCommit, 0)
|
||||||
analyzedCommits["minor"] = make([]AnalyzedCommit, 0)
|
analyzedCommits["minor"] = make([]AnalyzedCommit, 0)
|
||||||
analyzedCommits["patch"] = make([]AnalyzedCommit, 0)
|
analyzedCommits["patch"] = make([]AnalyzedCommit, 0)
|
||||||
|
analyzedCommits["draft"] = make([]AnalyzedCommit, 0)
|
||||||
analyzedCommits["none"] = make([]AnalyzedCommit, 0)
|
analyzedCommits["none"] = make([]AnalyzedCommit, 0)
|
||||||
|
|
||||||
for _, commit := range commits {
|
for _, commit := range commits {
|
||||||
for _, rule := range a.analyzeCommit.getRules() {
|
for _, rule := range a.analyzeCommit.getRules() {
|
||||||
analyzedCommit, hasBreakingChange, err := a.analyzeCommit.analyze(commit, rule)
|
analyzedCommit, hasBreakingChange, isDraft, err := a.analyzeCommit.analyze(commit, rule)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if a.Config.PrintAll {
|
if a.Config.PrintAll {
|
||||||
analyzedCommit.Print = true
|
analyzedCommit.Print = true
|
||||||
@@ -81,6 +83,8 @@ func (a *Analyzer) Analyze(commits []gitutil.Commit) map[string][]AnalyzedCommit
|
|||||||
}
|
}
|
||||||
if hasBreakingChange {
|
if hasBreakingChange {
|
||||||
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit)
|
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit)
|
||||||
|
} else if isDraft {
|
||||||
|
analyzedCommits["draft"] = append(analyzedCommits["draft"], analyzedCommit)
|
||||||
} else {
|
} else {
|
||||||
analyzedCommits[rule.Release] = append(analyzedCommits[rule.Release], analyzedCommit)
|
analyzedCommits[rule.Release] = append(analyzedCommits[rule.Release], analyzedCommit)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func (a *angular) getRules() []Rule {
|
|||||||
return a.rules
|
return a.rules
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, bool, error) {
|
func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, bool, bool, error) {
|
||||||
|
|
||||||
analyzed := AnalyzedCommit{
|
analyzed := AnalyzedCommit{
|
||||||
Commit: commit,
|
Commit: commit,
|
||||||
@@ -92,21 +92,35 @@ func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, boo
|
|||||||
analyzed.Scope = matches[0][2]
|
analyzed.Scope = matches[0][2]
|
||||||
|
|
||||||
message := strings.Join(matches[0][3:], "")
|
message := strings.Join(matches[0][3:], "")
|
||||||
splitted := strings.SplitN(message, "BREAKING CHANGE:", 1)
|
breakingChange := strings.SplitN(message, "BREAKING CHANGE:", 1)
|
||||||
|
draft := strings.SplitN(message, "DRAFT:", 1)
|
||||||
|
|
||||||
if len(splitted) == 1 {
|
if len(breakingChange) == 1 && len(draft) == 1 {
|
||||||
analyzed.ParsedMessage = splitted[0]
|
analyzed.ParsedMessage = breakingChange[0]
|
||||||
log.Tracef("%s: found %s", commit.Message, rule.Tag)
|
log.Tracef("%s: found %s", commit.Message, rule.Tag)
|
||||||
return analyzed, false, nil
|
return analyzed, false, false, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
analyzed.ParsedMessage = splitted[0]
|
|
||||||
analyzed.ParsedBreakingChangeMessage = splitted[1]
|
if len(breakingChange) > 1 {
|
||||||
|
|
||||||
|
analyzed.ParsedMessage = breakingChange[0]
|
||||||
|
analyzed.ParsedBreakingChangeMessage = breakingChange[1]
|
||||||
|
|
||||||
log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||||
return analyzed, true, nil
|
|
||||||
|
return analyzed, true, false, nil
|
||||||
|
|
||||||
|
} else if len(draft) > 1 {
|
||||||
|
analyzed.ParsedMessage = draft[0]
|
||||||
|
analyzed.ParsedDraftMessage = draft[1]
|
||||||
|
log.Tracef(" %s, DRAFT found", commit.Message)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
|
log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
|
||||||
return analyzed, false, fmt.Errorf("not found")
|
return analyzed, false, false, fmt.Errorf("not found")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ type ReleaseVersion struct {
|
|||||||
//ReleaseVersionEntry struct
|
//ReleaseVersionEntry struct
|
||||||
type ReleaseVersionEntry struct {
|
type ReleaseVersionEntry struct {
|
||||||
Commit string
|
Commit string
|
||||||
Version *semver.Version
|
Draft bool
|
||||||
|
*semver.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
//GeneratedChangelog struct
|
//GeneratedChangelog struct
|
||||||
@@ -23,7 +24,7 @@ type GeneratedChangelog struct {
|
|||||||
Content string
|
Content string
|
||||||
}
|
}
|
||||||
|
|
||||||
//GenerateChangelogConfig struct
|
//ChangelogTemplateConfig struct
|
||||||
type ChangelogTemplateConfig struct {
|
type ChangelogTemplateConfig struct {
|
||||||
CommitURL string
|
CommitURL string
|
||||||
CompareURL string
|
CompareURL string
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ func (s *SemanticRelease) GetNextVersion(force bool) (*shared.ReleaseVersion, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result := a.Analyze(commits)
|
result := a.Analyze(commits)
|
||||||
|
var isDraft bool = false
|
||||||
for branch, releaseType := range s.config.Branch {
|
for branch, releaseType := range s.config.Branch {
|
||||||
if currentBranch == branch || strings.HasPrefix(currentBranch, branch) {
|
if currentBranch == branch || strings.HasPrefix(currentBranch, branch) {
|
||||||
log.Debugf("Found branch config for branch %s with release type %s", currentBranch, releaseType)
|
log.Debugf("Found branch config for branch %s with release type %s", currentBranch, releaseType)
|
||||||
@@ -115,6 +115,9 @@ func (s *SemanticRelease) GetNextVersion(force bool) (*shared.ReleaseVersion, er
|
|||||||
} else if len(result["patch"]) > 0 {
|
} else if len(result["patch"]) > 0 {
|
||||||
newVersion = newVersion.IncPatch()
|
newVersion = newVersion.IncPatch()
|
||||||
}
|
}
|
||||||
|
if len(result["draft"]) > 0 {
|
||||||
|
isDraft = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,6 +126,7 @@ func (s *SemanticRelease) GetNextVersion(force bool) (*shared.ReleaseVersion, er
|
|||||||
Next: shared.ReleaseVersionEntry{
|
Next: shared.ReleaseVersionEntry{
|
||||||
Commit: hash,
|
Commit: hash,
|
||||||
Version: &newVersion,
|
Version: &newVersion,
|
||||||
|
Draft: isDraft,
|
||||||
},
|
},
|
||||||
Last: shared.ReleaseVersionEntry{
|
Last: shared.ReleaseVersionEntry{
|
||||||
Commit: lastVersionHash,
|
Commit: lastVersionHash,
|
||||||
|
|||||||
Reference in New Issue
Block a user