mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-25 07:30:38 +00:00
Merge pull request #26 from bvieira/#24
Feature: support more commit types on release notes sections
This commit is contained in:
commit
2d22b9d9f2
41
README.md
41
README.md
@ -68,18 +68,8 @@ version: "1.0" #config version
|
|||||||
|
|
||||||
versioning: # versioning bump
|
versioning: # versioning bump
|
||||||
update-major: [] # Commit types used to bump major.
|
update-major: [] # Commit types used to bump major.
|
||||||
update-minor: # Commit types used to bump minor.
|
update-minor: [feat] # Commit types used to bump minor.
|
||||||
- feat
|
update-patch: [build, ci, chore, fix, perf, refactor, test] # Commit types used to bump patch.
|
||||||
update-patch: # Commit types used to bump patch.
|
|
||||||
- build
|
|
||||||
- ci
|
|
||||||
- chore
|
|
||||||
- docs
|
|
||||||
- fix
|
|
||||||
- perf
|
|
||||||
- refactor
|
|
||||||
- style
|
|
||||||
- test
|
|
||||||
# When type is not present on update rules and is unknown (not mapped on commit message types);
|
# When type is not present on update rules and is unknown (not mapped on commit message types);
|
||||||
# if ignore-unknown=false bump patch, if ignore-unknown=true do not bump version
|
# if ignore-unknown=false bump patch, if ignore-unknown=true do not bump version
|
||||||
ignore-unknown: false
|
ignore-unknown: false
|
||||||
@ -88,7 +78,10 @@ tag:
|
|||||||
pattern: '%d.%d.%d' # Pattern used to create git tag.
|
pattern: '%d.%d.%d' # Pattern used to create git tag.
|
||||||
|
|
||||||
release-notes:
|
release-notes:
|
||||||
headers: # Headers names for release notes markdown. To disable a section just remove the header line.
|
# Headers names for release notes markdown. To disable a section just remove the header line.
|
||||||
|
# It's possible to add other commit types, the release note will be created respecting the following order:
|
||||||
|
# feat, fix, refactor, perf, test, build, ci, chore, docs, style, breaking-change
|
||||||
|
headers:
|
||||||
breaking-change: Breaking Changes
|
breaking-change: Breaking Changes
|
||||||
feat: Features
|
feat: Features
|
||||||
fix: Bug Fixes
|
fix: Bug Fixes
|
||||||
@ -97,25 +90,11 @@ branches: # Git branches config.
|
|||||||
prefix: ([a-z]+\/)? # Prefix used on branch name, it should be a regex group.
|
prefix: ([a-z]+\/)? # Prefix used on branch name, it should be a regex group.
|
||||||
suffix: (-.*)? # Suffix used on branch name, it should be a regex group.
|
suffix: (-.*)? # Suffix used on branch name, it should be a regex group.
|
||||||
disable-issue: false # Set true if there is no need to recover issue id from branch name.
|
disable-issue: false # Set true if there is no need to recover issue id from branch name.
|
||||||
skip: # List of branch names ignored on commit message validation.
|
skip: [master, main, developer] # List of branch names ignored on commit message validation.
|
||||||
- master
|
|
||||||
- main
|
|
||||||
- developer
|
|
||||||
skip-detached: false # Set true if a detached branch should be ignored on commit message validation.
|
skip-detached: false # Set true if a detached branch should be ignored on commit message validation.
|
||||||
|
|
||||||
commit-message:
|
commit-message:
|
||||||
types: # Supported commit types.
|
types: [build, ci, chore, docs, feat, fix, perf, refactor, revert, style, test] # Supported commit types.
|
||||||
- build
|
|
||||||
- ci
|
|
||||||
- chore
|
|
||||||
- docs
|
|
||||||
- feat
|
|
||||||
- fix
|
|
||||||
- perf
|
|
||||||
- refactor
|
|
||||||
- revert
|
|
||||||
- style
|
|
||||||
- test
|
|
||||||
scope:
|
scope:
|
||||||
# Define supported scopes, if blank, scope will not be validated, if not, only scope listed will be valid.
|
# Define supported scopes, if blank, scope will not be validated, if not, only scope listed will be valid.
|
||||||
# Don't forget to add "" on your list if you need to define scopes and keep it optional.
|
# Don't forget to add "" on your list if you need to define scopes and keep it optional.
|
||||||
@ -123,9 +102,7 @@ commit-message:
|
|||||||
footer:
|
footer:
|
||||||
issue: # Use "issue: {}" if you wish to disable issue footer.
|
issue: # Use "issue: {}" if you wish to disable issue footer.
|
||||||
key: jira # Name used to define an issue on footer metadata.
|
key: jira # Name used to define an issue on footer metadata.
|
||||||
key-synonyms: # Supported variations for footer metadata.
|
key-synonyms: [Jira, JIRA] # Supported variations for footer metadata.
|
||||||
- Jira
|
|
||||||
- JIRA
|
|
||||||
use-hash: false # If false, use :<space> separator. If true, use <space># separator.
|
use-hash: false # If false, use :<space> separator. If true, use <space># separator.
|
||||||
add-value-prefix: '' # Add a prefix to issue value.
|
add-value-prefix: '' # Add a prefix to issue value.
|
||||||
issue:
|
issue:
|
||||||
|
12
sv/config.go
12
sv/config.go
@ -4,7 +4,7 @@ package sv
|
|||||||
|
|
||||||
// CommitMessageConfig config a commit message.
|
// CommitMessageConfig config a commit message.
|
||||||
type CommitMessageConfig struct {
|
type CommitMessageConfig struct {
|
||||||
Types []string `yaml:"types"`
|
Types []string `yaml:"types,flow"`
|
||||||
Scope CommitMessageScopeConfig `yaml:"scope"`
|
Scope CommitMessageScopeConfig `yaml:"scope"`
|
||||||
Footer map[string]CommitMessageFooterConfig `yaml:"footer"`
|
Footer map[string]CommitMessageFooterConfig `yaml:"footer"`
|
||||||
Issue CommitMessageIssueConfig `yaml:"issue"`
|
Issue CommitMessageIssueConfig `yaml:"issue"`
|
||||||
@ -26,7 +26,7 @@ type CommitMessageScopeConfig struct {
|
|||||||
// CommitMessageFooterConfig config footer metadata.
|
// CommitMessageFooterConfig config footer metadata.
|
||||||
type CommitMessageFooterConfig struct {
|
type CommitMessageFooterConfig struct {
|
||||||
Key string `yaml:"key"`
|
Key string `yaml:"key"`
|
||||||
KeySynonyms []string `yaml:"key-synonyms"`
|
KeySynonyms []string `yaml:"key-synonyms,flow"`
|
||||||
UseHash bool `yaml:"use-hash"`
|
UseHash bool `yaml:"use-hash"`
|
||||||
AddValuePrefix string `yaml:"add-value-prefix"`
|
AddValuePrefix string `yaml:"add-value-prefix"`
|
||||||
}
|
}
|
||||||
@ -43,7 +43,7 @@ type BranchesConfig struct {
|
|||||||
PrefixRegex string `yaml:"prefix"`
|
PrefixRegex string `yaml:"prefix"`
|
||||||
SuffixRegex string `yaml:"suffix"`
|
SuffixRegex string `yaml:"suffix"`
|
||||||
DisableIssue bool `yaml:"disable-issue"`
|
DisableIssue bool `yaml:"disable-issue"`
|
||||||
Skip []string `yaml:"skip"`
|
Skip []string `yaml:"skip,flow"`
|
||||||
SkipDetached *bool `yaml:"skip-detached"`
|
SkipDetached *bool `yaml:"skip-detached"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,9 +51,9 @@ type BranchesConfig struct {
|
|||||||
|
|
||||||
// VersioningConfig versioning preferences.
|
// VersioningConfig versioning preferences.
|
||||||
type VersioningConfig struct {
|
type VersioningConfig struct {
|
||||||
UpdateMajor []string `yaml:"update-major"`
|
UpdateMajor []string `yaml:"update-major,flow"`
|
||||||
UpdateMinor []string `yaml:"update-minor"`
|
UpdateMinor []string `yaml:"update-minor,flow"`
|
||||||
UpdatePatch []string `yaml:"update-patch"`
|
UpdatePatch []string `yaml:"update-patch,flow"`
|
||||||
IgnoreUnknown bool `yaml:"ignore-unknown"`
|
IgnoreUnknown bool `yaml:"ignore-unknown"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ type releaseNoteTemplateVariables struct {
|
|||||||
Version string
|
Version string
|
||||||
Date string
|
Date string
|
||||||
Sections map[string]ReleaseNoteSection
|
Sections map[string]ReleaseNoteSection
|
||||||
|
Order []string
|
||||||
BreakingChanges BreakingChangeSection
|
BreakingChanges BreakingChangeSection
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,13 +24,13 @@ const (
|
|||||||
|
|
||||||
rnSectionItem = "- {{if .Message.Scope}}**{{.Message.Scope}}:** {{end}}{{.Message.Description}} ({{.Hash}}){{if .Message.Metadata.issue}} ({{.Message.Metadata.issue}}){{end}}"
|
rnSectionItem = "- {{if .Message.Scope}}**{{.Message.Scope}}:** {{end}}{{.Message.Description}} ({{.Hash}}){{if .Message.Metadata.issue}} ({{.Message.Metadata.issue}}){{end}}"
|
||||||
|
|
||||||
rnSection = `{{- if .}}
|
rnSection = `{{- if .}}{{- if ne .Name ""}}
|
||||||
|
|
||||||
### {{.Name}}
|
### {{.Name}}
|
||||||
{{range $k,$v := .Items}}
|
{{range $k,$v := .Items}}
|
||||||
{{template "rnSectionItem" $v}}
|
{{template "rnSectionItem" $v}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{- end}}`
|
{{- end}}{{- end}}`
|
||||||
|
|
||||||
rnSectionBreakingChanges = `{{- if ne .Name ""}}
|
rnSectionBreakingChanges = `{{- if ne .Name ""}}
|
||||||
|
|
||||||
@ -40,8 +41,10 @@ const (
|
|||||||
{{- end}}`
|
{{- end}}`
|
||||||
|
|
||||||
rnTemplate = `## {{if .Version}}v{{.Version}}{{end}}{{if and .Date .Version}} ({{end}}{{.Date}}{{if and .Version .Date}}){{end}}
|
rnTemplate = `## {{if .Version}}v{{.Version}}{{end}}{{if and .Date .Version}} ({{end}}{{.Date}}{{if and .Version .Date}}){{end}}
|
||||||
{{- template "rnSection" .Sections.feat}}
|
{{- $sections := .Sections }}
|
||||||
{{- template "rnSection" .Sections.fix}}
|
{{- range $key := .Order }}
|
||||||
|
{{- template "rnSection" (index $sections $key) }}
|
||||||
|
{{- end}}
|
||||||
{{- template "rnSectionBreakingChanges" .BreakingChanges}}
|
{{- template "rnSectionBreakingChanges" .BreakingChanges}}
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
@ -101,6 +104,7 @@ func releaseNoteVariables(releasenote ReleaseNote) releaseNoteTemplateVariables
|
|||||||
Version: version,
|
Version: version,
|
||||||
Date: date,
|
Date: date,
|
||||||
Sections: releasenote.Sections,
|
Sections: releasenote.Sections,
|
||||||
|
Order: []string{"feat", "fix", "refactor", "perf", "test", "build", "ci", "chore", "docs", "style"},
|
||||||
BreakingChanges: releasenote.BreakingChanges,
|
BreakingChanges: releasenote.BreakingChanges,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,24 @@ var emptyDateChangelog = `## v1.0.0
|
|||||||
`
|
`
|
||||||
var emptyVersionChangelog = `## 2020-05-01
|
var emptyVersionChangelog = `## 2020-05-01
|
||||||
`
|
`
|
||||||
|
var fullChangeLog = `## v1.0.0 (2020-05-01)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- subject text ()
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- subject text ()
|
||||||
|
|
||||||
|
### Build
|
||||||
|
|
||||||
|
- subject text ()
|
||||||
|
|
||||||
|
### Breaking Changes
|
||||||
|
|
||||||
|
- break change message
|
||||||
|
`
|
||||||
|
|
||||||
func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
|
func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
|
||||||
date, _ := time.Parse("2006-01-02", "2020-05-01")
|
date, _ := time.Parse("2006-01-02", "2020-05-01")
|
||||||
@ -25,6 +43,7 @@ func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
|
|||||||
{"with date", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog},
|
{"with date", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog},
|
||||||
{"without date", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog},
|
{"without date", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog},
|
||||||
{"without version", emptyReleaseNote("", date.Truncate(time.Minute)), emptyVersionChangelog},
|
{"without version", emptyReleaseNote("", date.Truncate(time.Minute)), emptyVersionChangelog},
|
||||||
|
{"full changelog", fullReleaseNote("1.0.0", date.Truncate(time.Minute)), fullChangeLog},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@ -45,3 +64,17 @@ func emptyReleaseNote(version string, date time.Time) ReleaseNote {
|
|||||||
Date: date,
|
Date: date,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fullReleaseNote(version string, date time.Time) ReleaseNote {
|
||||||
|
var v *semver.Version
|
||||||
|
if version != "" {
|
||||||
|
v = semver.MustParse(version)
|
||||||
|
}
|
||||||
|
|
||||||
|
sections := map[string]ReleaseNoteSection{
|
||||||
|
"build": newReleaseNoteSection("Build", []GitCommitLog{commitlog("build", map[string]string{})}),
|
||||||
|
"feat": newReleaseNoteSection("Features", []GitCommitLog{commitlog("feat", map[string]string{})}),
|
||||||
|
"fix": newReleaseNoteSection("Bug Fixes", []GitCommitLog{commitlog("fix", map[string]string{})}),
|
||||||
|
}
|
||||||
|
return releaseNote(v, date, sections, []string{"break change message"})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user