mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-10 02:10:38 +00:00
refactor: add versioning, tag and release notes config
This commit is contained in:
parent
f6debee45e
commit
9b63aacd8d
@ -32,12 +32,20 @@ func main() {
|
||||
PrefixRegex: cfg.BranchIssuePrefixRegex,
|
||||
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)
|
||||
git := sv.NewGit(messageProcessor, cfg.TagPattern)
|
||||
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.IncludeUnknownTypeAsPatch, cfg.MajorVersionTypes, cfg.MinorVersionTypes, cfg.PatchVersionTypes)
|
||||
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotesTags)
|
||||
git := sv.NewGit(messageProcessor, tagConfig)
|
||||
semverProcessor := sv.NewSemVerCommitsProcessor(versioningConfig)
|
||||
releasenotesProcessor := sv.NewReleaseNoteProcessor(releaseNotesConfig)
|
||||
outputFormatter := sv.NewOutputFormatter()
|
||||
|
||||
app := cli.NewApp()
|
||||
|
28
sv/config.go
28
sv/config.go
@ -1,5 +1,7 @@
|
||||
package sv
|
||||
|
||||
// ==== Message ====
|
||||
|
||||
// CommitMessageConfig config a commit message.
|
||||
type CommitMessageConfig struct {
|
||||
Types []string
|
||||
@ -42,6 +44,8 @@ type CommitMessageIssueConfig struct {
|
||||
Regex string
|
||||
}
|
||||
|
||||
// ==== Branches ====
|
||||
|
||||
// BranchesConfig branches preferences.
|
||||
type BranchesConfig struct {
|
||||
PrefixRegex string
|
||||
@ -49,3 +53,27 @@ type BranchesConfig struct {
|
||||
ExpectIssue bool
|
||||
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
|
||||
}
|
||||
|
@ -65,14 +65,14 @@ func NewLogRange(t LogRangeType, start, end string) LogRange {
|
||||
// GitImpl git command implementation
|
||||
type GitImpl struct {
|
||||
messageProcessor MessageProcessor
|
||||
tagPattern string
|
||||
tagCfg TagConfig
|
||||
}
|
||||
|
||||
// NewGit constructor
|
||||
func NewGit(messageProcessor MessageProcessor, tagPattern string) *GitImpl {
|
||||
func NewGit(messageProcessor MessageProcessor, cfg TagConfig) *GitImpl {
|
||||
return &GitImpl{
|
||||
messageProcessor: messageProcessor,
|
||||
tagPattern: tagPattern,
|
||||
tagCfg: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,7 +122,7 @@ func (g GitImpl) Commit(header, body, footer string) error {
|
||||
|
||||
// Tag create a git tag
|
||||
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())
|
||||
|
||||
tagCommand := exec.Command("git", "tag", "-a", tag, "-m", tagMsg)
|
||||
|
@ -13,12 +13,12 @@ type ReleaseNoteProcessor interface {
|
||||
|
||||
// ReleaseNoteProcessorImpl release note based on commit log.
|
||||
type ReleaseNoteProcessorImpl struct {
|
||||
tags map[string]string
|
||||
cfg ReleaseNotesConfig
|
||||
}
|
||||
|
||||
// NewReleaseNoteProcessor ReleaseNoteProcessor constructor.
|
||||
func NewReleaseNoteProcessor(tags map[string]string) *ReleaseNoteProcessorImpl {
|
||||
return &ReleaseNoteProcessorImpl{tags: tags}
|
||||
func NewReleaseNoteProcessor(cfg ReleaseNotesConfig) *ReleaseNoteProcessorImpl {
|
||||
return &ReleaseNoteProcessorImpl{cfg: cfg}
|
||||
}
|
||||
|
||||
// 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)
|
||||
var breakingChanges []string
|
||||
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]
|
||||
if !sexists {
|
||||
section = ReleaseNoteSection{Name: name}
|
||||
|
@ -42,7 +42,7 @@ func TestReleaseNoteProcessorImpl_Create(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
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) {
|
||||
t.Errorf("ReleaseNoteProcessorImpl.Create() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
10
sv/semver.go
10
sv/semver.go
@ -38,12 +38,12 @@ type SemVerCommitsProcessorImpl struct {
|
||||
}
|
||||
|
||||
// NewSemVerCommitsProcessor SemanticVersionCommitsProcessorImpl constructor
|
||||
func NewSemVerCommitsProcessor(unknownAsPatch bool, majorTypes, minorTypes, patchTypes []string) *SemVerCommitsProcessorImpl {
|
||||
func NewSemVerCommitsProcessor(cfg VersioningConfig) *SemVerCommitsProcessorImpl {
|
||||
return &SemVerCommitsProcessorImpl{
|
||||
IncludeUnknownTypeAsPatch: unknownAsPatch,
|
||||
MajorVersionTypes: toMap(majorTypes),
|
||||
MinorVersionTypes: toMap(minorTypes),
|
||||
PatchVersionTypes: toMap(patchTypes),
|
||||
IncludeUnknownTypeAsPatch: cfg.UnknownTypeAsPatch,
|
||||
MajorVersionTypes: toMap(cfg.UpdateMajor),
|
||||
MinorVersionTypes: toMap(cfg.UpdateMinor),
|
||||
PatchVersionTypes: toMap(cfg.UpdatePatch),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ func TestSemVerCommitsProcessorImpl_NextVersion(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
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) {
|
||||
t.Errorf("SemVerCommitsProcessorImpl.NextVersion() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user