mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-21 22:10:39 +00:00
feat: ignore known types on bumping version if not mapped on bump config
This commit is contained in:
parent
1fc099481d
commit
5c992b6826
@ -49,7 +49,7 @@ func main() {
|
|||||||
|
|
||||||
messageProcessor := sv.NewMessageProcessor(cfg.CommitMessage, cfg.Branches)
|
messageProcessor := sv.NewMessageProcessor(cfg.CommitMessage, cfg.Branches)
|
||||||
git := sv.NewGit(messageProcessor, cfg.Tag)
|
git := sv.NewGit(messageProcessor, cfg.Tag)
|
||||||
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning)
|
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning, cfg.CommitMessage)
|
||||||
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotes)
|
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotes)
|
||||||
outputFormatter := sv.NewOutputFormatter()
|
outputFormatter := sv.NewOutputFormatter()
|
||||||
|
|
||||||
|
14
sv/semver.go
14
sv/semver.go
@ -34,16 +34,18 @@ type SemVerCommitsProcessorImpl struct {
|
|||||||
MajorVersionTypes map[string]struct{}
|
MajorVersionTypes map[string]struct{}
|
||||||
MinorVersionTypes map[string]struct{}
|
MinorVersionTypes map[string]struct{}
|
||||||
PatchVersionTypes map[string]struct{}
|
PatchVersionTypes map[string]struct{}
|
||||||
|
KnownTypes []string
|
||||||
IncludeUnknownTypeAsPatch bool
|
IncludeUnknownTypeAsPatch bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSemVerCommitsProcessor SemanticVersionCommitsProcessorImpl constructor
|
// NewSemVerCommitsProcessor SemanticVersionCommitsProcessorImpl constructor
|
||||||
func NewSemVerCommitsProcessor(cfg VersioningConfig) *SemVerCommitsProcessorImpl {
|
func NewSemVerCommitsProcessor(vcfg VersioningConfig, mcfg CommitMessageConfig) *SemVerCommitsProcessorImpl {
|
||||||
return &SemVerCommitsProcessorImpl{
|
return &SemVerCommitsProcessorImpl{
|
||||||
IncludeUnknownTypeAsPatch: !cfg.IgnoreUnknown,
|
IncludeUnknownTypeAsPatch: !vcfg.IgnoreUnknown,
|
||||||
MajorVersionTypes: toMap(cfg.UpdateMajor),
|
MajorVersionTypes: toMap(vcfg.UpdateMajor),
|
||||||
MinorVersionTypes: toMap(cfg.UpdateMinor),
|
MinorVersionTypes: toMap(vcfg.UpdateMinor),
|
||||||
PatchVersionTypes: toMap(cfg.UpdatePatch),
|
PatchVersionTypes: toMap(vcfg.UpdatePatch),
|
||||||
|
KnownTypes: mcfg.Types,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +83,7 @@ func (p SemVerCommitsProcessorImpl) versionTypeToUpdate(commit GitCommitLog) ver
|
|||||||
if _, exists := p.PatchVersionTypes[commit.Message.Type]; exists {
|
if _, exists := p.PatchVersionTypes[commit.Message.Type]; exists {
|
||||||
return patch
|
return patch
|
||||||
}
|
}
|
||||||
if p.IncludeUnknownTypeAsPatch {
|
if !contains(commit.Message.Type, p.KnownTypes) && p.IncludeUnknownTypeAsPatch {
|
||||||
return patch
|
return patch
|
||||||
}
|
}
|
||||||
return none
|
return none
|
||||||
|
@ -17,6 +17,7 @@ func TestSemVerCommitsProcessorImpl_NextVersion(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{"no update", true, version("0.0.0"), []GitCommitLog{}, version("0.0.0")},
|
{"no update", true, version("0.0.0"), []GitCommitLog{}, version("0.0.0")},
|
||||||
{"no update on unknown type", true, version("0.0.0"), []GitCommitLog{commitlog("a", map[string]string{})}, version("0.0.0")},
|
{"no update on unknown type", true, version("0.0.0"), []GitCommitLog{commitlog("a", map[string]string{})}, version("0.0.0")},
|
||||||
|
{"no update on unmapped known type", false, version("0.0.0"), []GitCommitLog{commitlog("none", map[string]string{})}, version("0.0.0")},
|
||||||
{"update patch on unknown type", false, version("0.0.0"), []GitCommitLog{commitlog("a", map[string]string{})}, version("0.0.1")},
|
{"update patch on unknown type", false, version("0.0.0"), []GitCommitLog{commitlog("a", map[string]string{})}, version("0.0.1")},
|
||||||
{"patch update", false, version("0.0.0"), []GitCommitLog{commitlog("patch", map[string]string{})}, version("0.0.1")},
|
{"patch update", false, version("0.0.0"), []GitCommitLog{commitlog("patch", map[string]string{})}, version("0.0.1")},
|
||||||
{"minor update", false, version("0.0.0"), []GitCommitLog{commitlog("patch", map[string]string{}), commitlog("minor", map[string]string{})}, version("0.1.0")},
|
{"minor update", false, version("0.0.0"), []GitCommitLog{commitlog("patch", map[string]string{}), commitlog("minor", map[string]string{})}, version("0.1.0")},
|
||||||
@ -25,7 +26,7 @@ func TestSemVerCommitsProcessorImpl_NextVersion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
p := NewSemVerCommitsProcessor(VersioningConfig{UpdateMajor: []string{"major"}, UpdateMinor: []string{"minor"}, UpdatePatch: []string{"patch"}, IgnoreUnknown: tt.ignoreUnknown})
|
p := NewSemVerCommitsProcessor(VersioningConfig{UpdateMajor: []string{"major"}, UpdateMinor: []string{"minor"}, UpdatePatch: []string{"patch"}, IgnoreUnknown: tt.ignoreUnknown}, CommitMessageConfig{Types: []string{"major", "minor", "patch", "none"}})
|
||||||
if got := p.NextVersion(tt.version, tt.commits); !reflect.DeepEqual(got, tt.want) {
|
if got := p.NextVersion(tt.version, tt.commits); !reflect.DeepEqual(got, tt.want) {
|
||||||
t.Errorf("SemVerCommitsProcessorImpl.NextVersion() = %v, want %v", got, tt.want)
|
t.Errorf("SemVerCommitsProcessorImpl.NextVersion() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user