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

refactor: add versioning, tag and release notes config

This commit is contained in:
Beatriz Vieira 2021-02-14 02:32:23 -03:00
parent f6debee45e
commit 9b63aacd8d
7 changed files with 54 additions and 18 deletions

View File

@ -32,12 +32,20 @@ func main() {
PrefixRegex: cfg.BranchIssuePrefixRegex, PrefixRegex: cfg.BranchIssuePrefixRegex,
SuffixRegex: cfg.BranchIssueSuffixRegex, SuffixRegex: cfg.BranchIssueSuffixRegex,
} }
versioningConfig := sv.VersioningConfig{
UpdateMajor: cfg.MajorVersionTypes,
UpdateMinor: cfg.MinorVersionTypes,
UpdatePatch: cfg.PatchVersionTypes,
UnknownTypeAsPatch: cfg.IncludeUnknownTypeAsPatch,
}
tagConfig := sv.TagConfig{Pattern: cfg.TagPattern}
releaseNotesConfig := sv.ReleaseNotesConfig{Headers: cfg.ReleaseNotesTags}
//// ////
messageProcessor := sv.NewMessageProcessor(commitMessageCfg, branchesConfig) messageProcessor := sv.NewMessageProcessor(commitMessageCfg, branchesConfig)
git := sv.NewGit(messageProcessor, cfg.TagPattern) git := sv.NewGit(messageProcessor, tagConfig)
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.IncludeUnknownTypeAsPatch, cfg.MajorVersionTypes, cfg.MinorVersionTypes, cfg.PatchVersionTypes) semverProcessor := sv.NewSemVerCommitsProcessor(versioningConfig)
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotesTags) releasenotesProcessor := sv.NewReleaseNoteProcessor(releaseNotesConfig)
outputFormatter := sv.NewOutputFormatter() outputFormatter := sv.NewOutputFormatter()
app := cli.NewApp() app := cli.NewApp()

View File

@ -1,5 +1,7 @@
package sv package sv
// ==== Message ====
// CommitMessageConfig config a commit message. // CommitMessageConfig config a commit message.
type CommitMessageConfig struct { type CommitMessageConfig struct {
Types []string Types []string
@ -42,6 +44,8 @@ type CommitMessageIssueConfig struct {
Regex string Regex string
} }
// ==== Branches ====
// BranchesConfig branches preferences. // BranchesConfig branches preferences.
type BranchesConfig struct { type BranchesConfig struct {
PrefixRegex string PrefixRegex string
@ -49,3 +53,27 @@ type BranchesConfig struct {
ExpectIssue bool ExpectIssue bool
Skip []string Skip []string
} }
// ==== Versioning ====
// VersioningConfig versioning preferences.
type VersioningConfig struct {
UpdateMajor []string
UpdateMinor []string
UpdatePatch []string
UnknownTypeAsPatch bool
}
// ==== Tag ====
// TagConfig tag preferences.
type TagConfig struct {
Pattern string
}
// ==== Release Notes ====
// ReleaseNotesConfig release notes preferences.
type ReleaseNotesConfig struct {
Headers map[string]string
}

View File

@ -65,14 +65,14 @@ func NewLogRange(t LogRangeType, start, end string) LogRange {
// GitImpl git command implementation // GitImpl git command implementation
type GitImpl struct { type GitImpl struct {
messageProcessor MessageProcessor messageProcessor MessageProcessor
tagPattern string tagCfg TagConfig
} }
// NewGit constructor // NewGit constructor
func NewGit(messageProcessor MessageProcessor, tagPattern string) *GitImpl { func NewGit(messageProcessor MessageProcessor, cfg TagConfig) *GitImpl {
return &GitImpl{ return &GitImpl{
messageProcessor: messageProcessor, messageProcessor: messageProcessor,
tagPattern: tagPattern, tagCfg: cfg,
} }
} }
@ -122,7 +122,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) error { func (g GitImpl) Tag(version semver.Version) error {
tag := fmt.Sprintf(g.tagPattern, 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)

View File

@ -13,12 +13,12 @@ type ReleaseNoteProcessor interface {
// ReleaseNoteProcessorImpl release note based on commit log. // ReleaseNoteProcessorImpl release note based on commit log.
type ReleaseNoteProcessorImpl struct { type ReleaseNoteProcessorImpl struct {
tags map[string]string cfg ReleaseNotesConfig
} }
// NewReleaseNoteProcessor ReleaseNoteProcessor constructor. // NewReleaseNoteProcessor ReleaseNoteProcessor constructor.
func NewReleaseNoteProcessor(tags map[string]string) *ReleaseNoteProcessorImpl { func NewReleaseNoteProcessor(cfg ReleaseNotesConfig) *ReleaseNoteProcessorImpl {
return &ReleaseNoteProcessorImpl{tags: tags} return &ReleaseNoteProcessorImpl{cfg: cfg}
} }
// Create create a release note based on commits. // Create create a release note based on commits.
@ -26,7 +26,7 @@ func (p ReleaseNoteProcessorImpl) Create(version *semver.Version, date time.Time
sections := make(map[string]ReleaseNoteSection) sections := make(map[string]ReleaseNoteSection)
var breakingChanges []string var breakingChanges []string
for _, commit := range commits { for _, commit := range commits {
if name, exists := p.tags[commit.Message.Type]; exists { if name, exists := p.cfg.Headers[commit.Message.Type]; exists {
section, sexists := sections[commit.Message.Type] section, sexists := sections[commit.Message.Type]
if !sexists { if !sexists {
section = ReleaseNoteSection{Name: name} section = ReleaseNoteSection{Name: name}

View File

@ -42,7 +42,7 @@ func TestReleaseNoteProcessorImpl_Create(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 := NewReleaseNoteProcessor(map[string]string{"t1": "Tag 1", "t2": "Tag 2"}) p := NewReleaseNoteProcessor(ReleaseNotesConfig{Headers: map[string]string{"t1": "Tag 1", "t2": "Tag 2"}})
if got := p.Create(tt.version, tt.date, tt.commits); !reflect.DeepEqual(got, tt.want) { if got := p.Create(tt.version, tt.date, tt.commits); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ReleaseNoteProcessorImpl.Create() = %v, want %v", got, tt.want) t.Errorf("ReleaseNoteProcessorImpl.Create() = %v, want %v", got, tt.want)
} }

View File

@ -38,12 +38,12 @@ type SemVerCommitsProcessorImpl struct {
} }
// NewSemVerCommitsProcessor SemanticVersionCommitsProcessorImpl constructor // NewSemVerCommitsProcessor SemanticVersionCommitsProcessorImpl constructor
func NewSemVerCommitsProcessor(unknownAsPatch bool, majorTypes, minorTypes, patchTypes []string) *SemVerCommitsProcessorImpl { func NewSemVerCommitsProcessor(cfg VersioningConfig) *SemVerCommitsProcessorImpl {
return &SemVerCommitsProcessorImpl{ return &SemVerCommitsProcessorImpl{
IncludeUnknownTypeAsPatch: unknownAsPatch, IncludeUnknownTypeAsPatch: cfg.UnknownTypeAsPatch,
MajorVersionTypes: toMap(majorTypes), MajorVersionTypes: toMap(cfg.UpdateMajor),
MinorVersionTypes: toMap(minorTypes), MinorVersionTypes: toMap(cfg.UpdateMinor),
PatchVersionTypes: toMap(patchTypes), PatchVersionTypes: toMap(cfg.UpdatePatch),
} }
} }

View File

@ -25,7 +25,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(tt.unknownAsPatch, []string{"major"}, []string{"minor"}, []string{"patch"}) p := NewSemVerCommitsProcessor(VersioningConfig{UpdateMajor: []string{"major"}, UpdateMinor: []string{"minor"}, UpdatePatch: []string{"patch"}, UnknownTypeAsPatch: tt.unknownAsPatch})
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)
} }