diff --git a/cmd/git-sv/main.go b/cmd/git-sv/main.go index a41c78c..d39f5c5 100644 --- a/cmd/git-sv/main.go +++ b/cmd/git-sv/main.go @@ -49,7 +49,7 @@ func main() { messageProcessor := sv.NewMessageProcessor(cfg.CommitMessage, cfg.Branches) git := sv.NewGit(messageProcessor, cfg.Tag) - semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning) + semverProcessor := sv.NewSemVerCommitsProcessor(cfg.Versioning, cfg.CommitMessage) releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotes) outputFormatter := sv.NewOutputFormatter() diff --git a/sv/semver.go b/sv/semver.go index a58365d..c3648e1 100644 --- a/sv/semver.go +++ b/sv/semver.go @@ -34,16 +34,18 @@ type SemVerCommitsProcessorImpl struct { MajorVersionTypes map[string]struct{} MinorVersionTypes map[string]struct{} PatchVersionTypes map[string]struct{} + KnownTypes []string IncludeUnknownTypeAsPatch bool } // NewSemVerCommitsProcessor SemanticVersionCommitsProcessorImpl constructor -func NewSemVerCommitsProcessor(cfg VersioningConfig) *SemVerCommitsProcessorImpl { +func NewSemVerCommitsProcessor(vcfg VersioningConfig, mcfg CommitMessageConfig) *SemVerCommitsProcessorImpl { return &SemVerCommitsProcessorImpl{ - IncludeUnknownTypeAsPatch: !cfg.IgnoreUnknown, - MajorVersionTypes: toMap(cfg.UpdateMajor), - MinorVersionTypes: toMap(cfg.UpdateMinor), - PatchVersionTypes: toMap(cfg.UpdatePatch), + IncludeUnknownTypeAsPatch: !vcfg.IgnoreUnknown, + MajorVersionTypes: toMap(vcfg.UpdateMajor), + MinorVersionTypes: toMap(vcfg.UpdateMinor), + 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 { return patch } - if p.IncludeUnknownTypeAsPatch { + if !contains(commit.Message.Type, p.KnownTypes) && p.IncludeUnknownTypeAsPatch { return patch } return none diff --git a/sv/semver_test.go b/sv/semver_test.go index 3117e16..c1a2678 100644 --- a/sv/semver_test.go +++ b/sv/semver_test.go @@ -17,6 +17,7 @@ func TestSemVerCommitsProcessorImpl_NextVersion(t *testing.T) { }{ {"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 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")}, {"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")}, @@ -25,7 +26,7 @@ func TestSemVerCommitsProcessorImpl_NextVersion(t *testing.T) { } for _, tt := range tests { 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) { t.Errorf("SemVerCommitsProcessorImpl.NextVersion() = %v, want %v", got, tt.want) }