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

Merge branch 'master' into #87

This commit is contained in:
Beatriz Vieira 2023-01-22 21:00:14 -03:00 committed by GitHub
commit bdd631ab76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 13 deletions

View File

@ -69,6 +69,8 @@ func readConfig(filepath string) (Config, error) {
func defaultConfig() Config { func defaultConfig() Config {
skipDetached := false skipDetached := false
pattern := "%d.%d.%d"
filter := ""
return Config{ return Config{
Version: "1.1", Version: "1.1",
Versioning: sv.VersioningConfig{ Versioning: sv.VersioningConfig{
@ -78,8 +80,8 @@ func defaultConfig() Config {
IgnoreUnknown: false, IgnoreUnknown: false,
}, },
Tag: sv.TagConfig{ Tag: sv.TagConfig{
Pattern: "%d.%d.%d", Pattern: &pattern,
Filter: "", Filter: &filter,
}, },
ReleaseNotes: sv.ReleaseNotesConfig{ ReleaseNotes: sv.ReleaseNotesConfig{
Sections: []sv.ReleaseNotesSectionConfig{ Sections: []sv.ReleaseNotesSectionConfig{

View File

@ -10,6 +10,8 @@ import (
func Test_merge(t *testing.T) { func Test_merge(t *testing.T) {
boolFalse := false boolFalse := false
boolTrue := true boolTrue := true
emptyStr := ""
nonEmptyStr := "something"
tests := []struct { tests := []struct {
name string name string
@ -34,6 +36,8 @@ func Test_merge(t *testing.T) {
{"merge empty maps", Config{CommitMessage: sv.CommitMessageConfig{Footer: map[string]sv.CommitMessageFooterConfig{"issue": {Key: "jira"}}}}, Config{CommitMessage: sv.CommitMessageConfig{Footer: map[string]sv.CommitMessageFooterConfig{}}}, Config{CommitMessage: sv.CommitMessageConfig{Footer: map[string]sv.CommitMessageFooterConfig{"issue": {Key: "jira"}}}}, false}, {"merge empty maps", Config{CommitMessage: sv.CommitMessageConfig{Footer: map[string]sv.CommitMessageFooterConfig{"issue": {Key: "jira"}}}}, Config{CommitMessage: sv.CommitMessageConfig{Footer: map[string]sv.CommitMessageFooterConfig{}}}, Config{CommitMessage: sv.CommitMessageConfig{Footer: map[string]sv.CommitMessageFooterConfig{"issue": {Key: "jira"}}}}, false},
{"overwrite release notes header", Config{ReleaseNotes: sv.ReleaseNotesConfig{Headers: map[string]string{"a": "aa"}}}, Config{ReleaseNotes: sv.ReleaseNotesConfig{Headers: map[string]string{"b": "bb"}}}, Config{ReleaseNotes: sv.ReleaseNotesConfig{Headers: map[string]string{"b": "bb"}}}, false}, {"overwrite release notes header", Config{ReleaseNotes: sv.ReleaseNotesConfig{Headers: map[string]string{"a": "aa"}}}, Config{ReleaseNotes: sv.ReleaseNotesConfig{Headers: map[string]string{"b": "bb"}}}, Config{ReleaseNotes: sv.ReleaseNotesConfig{Headers: map[string]string{"b": "bb"}}}, false},
{"overwrite tag config", Config{Version: "a", Tag: sv.TagConfig{Pattern: &nonEmptyStr, Filter: &nonEmptyStr}}, Config{Version: "", Tag: sv.TagConfig{Pattern: &emptyStr, Filter: &emptyStr}}, Config{Version: "a", Tag: sv.TagConfig{Pattern: &emptyStr, Filter: &emptyStr}}, false},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

View File

@ -209,7 +209,7 @@ func getTags(git sv.Git, tag string) (string, sv.GitTag, error) {
index := find(tag, tags) index := find(tag, tags)
if index < 0 { if index < 0 {
return "", sv.GitTag{}, fmt.Errorf("tag: %s not found", tag) return "", sv.GitTag{}, fmt.Errorf("tag: %s not found, check tag filter", tag)
} }
previousTag := "" previousTag := ""

View File

@ -4,11 +4,11 @@ package sv
// CommitMessageConfig config a commit message. // CommitMessageConfig config a commit message.
type CommitMessageConfig struct { type CommitMessageConfig struct {
Types []string `yaml:"types,flow"` Types []string `yaml:"types,flow"`
HeaderSelector string `yaml:"header-selector"` HeaderSelector string `yaml:"header-selector"`
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"`
} }
// IssueFooterConfig config for issue. // IssueFooterConfig config for issue.
@ -62,8 +62,8 @@ type VersioningConfig struct {
// TagConfig tag preferences. // TagConfig tag preferences.
type TagConfig struct { type TagConfig struct {
Pattern string `yaml:"pattern"` Pattern *string `yaml:"pattern"`
Filter string `yaml:"filter"` Filter *string `yaml:"filter"`
} }
// ==== Release Notes ==== // ==== Release Notes ====

View File

@ -83,7 +83,7 @@ func NewGit(messageProcessor MessageProcessor, cfg TagConfig) *GitImpl {
// LastTag get last tag, if no tag found, return empty. // LastTag get last tag, if no tag found, return empty.
func (g GitImpl) LastTag() string { func (g GitImpl) LastTag() string {
cmd := exec.Command("git", "for-each-ref", "refs/tags/"+g.tagCfg.Filter, "--sort", "-creatordate", "--format", "%(refname:short)", "--count", "1") cmd := exec.Command("git", "for-each-ref", "refs/tags/"+*g.tagCfg.Filter, "--sort", "-creatordate", "--format", "%(refname:short)", "--count", "1")
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return "" return ""
@ -131,7 +131,7 @@ func (g GitImpl) Commit(header, body, footer string) error {
// Tag create a git tag. // Tag create a git tag.
func (g GitImpl) Tag(version semver.Version) (string, error) { func (g GitImpl) Tag(version semver.Version) (string, error) {
tag := fmt.Sprintf(g.tagCfg.Pattern, version.Major(), version.Minor(), version.Patch()) tag := fmt.Sprintf(*g.tagCfg.Pattern, version.Major(), version.Minor(), version.Patch())
tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch()) tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch())
tagCommand := exec.Command("git", "tag", "-a", tag, "-m", tagMsg) tagCommand := exec.Command("git", "tag", "-a", tag, "-m", tagMsg)
@ -148,7 +148,7 @@ func (g GitImpl) Tag(version semver.Version) (string, error) {
// Tags list repository tags. // Tags list repository tags.
func (g GitImpl) Tags() ([]GitTag, error) { func (g GitImpl) Tags() ([]GitTag, error) {
cmd := exec.Command("git", "for-each-ref", "--sort", "creatordate", "--format", "%(creatordate:iso8601)#%(refname:short)", "refs/tags/"+g.tagCfg.Filter) cmd := exec.Command("git", "for-each-ref", "--sort", "creatordate", "--format", "%(creatordate:iso8601)#%(refname:short)", "refs/tags/"+*g.tagCfg.Filter)
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return nil, combinedOutputErr(err, out) return nil, combinedOutputErr(err, out)