mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-24 11:10:39 +00:00
refactor: add version to releasenote struct
This commit is contained in:
parent
32231552a5
commit
2cd32e3ed3
@ -93,8 +93,8 @@ func releaseNotesHandler(git sv.Git, semverProcessor sv.SemVerCommitsProcessor,
|
||||
return err
|
||||
}
|
||||
|
||||
releasenote := rnProcessor.Get(date, commits)
|
||||
fmt.Println(rnProcessor.Format(releasenote, rnVersion))
|
||||
releasenote := rnProcessor.Create(rnVersion, date, commits)
|
||||
fmt.Println(rnProcessor.Format(releasenote))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,9 @@ func commitlog(t string, metadata map[string]string) GitCommitLog {
|
||||
}
|
||||
}
|
||||
|
||||
func releaseNote(date time.Time, sections map[string]ReleaseNoteSection, breakingChanges []string) ReleaseNote {
|
||||
func releaseNote(version semver.Version, date time.Time, sections map[string]ReleaseNoteSection, breakingChanges []string) ReleaseNote {
|
||||
return ReleaseNote{
|
||||
Version: version,
|
||||
Date: date.Truncate(time.Minute),
|
||||
Sections: sections,
|
||||
BreakingChanges: breakingChanges,
|
||||
|
@ -33,8 +33,8 @@ const markdownTemplate = `## v{{.Version}} ({{.Date}})
|
||||
|
||||
// ReleaseNoteProcessor release note processor interface.
|
||||
type ReleaseNoteProcessor interface {
|
||||
Get(date time.Time, commits []GitCommitLog) ReleaseNote
|
||||
Format(releasenote ReleaseNote, version semver.Version) string
|
||||
Create(version semver.Version, date time.Time, commits []GitCommitLog) ReleaseNote
|
||||
Format(releasenote ReleaseNote) string
|
||||
}
|
||||
|
||||
// ReleaseNoteProcessorImpl release note based on commit log.
|
||||
@ -49,8 +49,8 @@ func NewReleaseNoteProcessor(tags map[string]string) *ReleaseNoteProcessorImpl {
|
||||
return &ReleaseNoteProcessorImpl{tags: tags, template: template}
|
||||
}
|
||||
|
||||
// Get generate a release note based on commits.
|
||||
func (p ReleaseNoteProcessorImpl) Get(date time.Time, commits []GitCommitLog) ReleaseNote {
|
||||
// Create create a release note based on commits.
|
||||
func (p ReleaseNoteProcessorImpl) Create(version semver.Version, date time.Time, commits []GitCommitLog) ReleaseNote {
|
||||
sections := make(map[string]ReleaseNoteSection)
|
||||
var breakingChanges []string
|
||||
for _, commit := range commits {
|
||||
@ -67,13 +67,13 @@ func (p ReleaseNoteProcessorImpl) Get(date time.Time, commits []GitCommitLog) Re
|
||||
}
|
||||
}
|
||||
|
||||
return ReleaseNote{Date: date.Truncate(time.Minute), Sections: sections, BreakingChanges: breakingChanges}
|
||||
return ReleaseNote{Version: version, Date: date.Truncate(time.Minute), Sections: sections, BreakingChanges: breakingChanges}
|
||||
}
|
||||
|
||||
// Format format a release note.
|
||||
func (p ReleaseNoteProcessorImpl) Format(releasenote ReleaseNote, version semver.Version) string {
|
||||
func (p ReleaseNoteProcessorImpl) Format(releasenote ReleaseNote) string {
|
||||
templateVars := releaseNoteTemplate{
|
||||
Version: fmt.Sprintf("%d.%d.%d", version.Major(), version.Minor(), version.Patch()),
|
||||
Version: fmt.Sprintf("%d.%d.%d", releasenote.Version.Major(), releasenote.Version.Minor(), releasenote.Version.Patch()),
|
||||
Date: releasenote.Date.Format("2006-01-02"),
|
||||
Sections: releasenote.Sections,
|
||||
BreakingChanges: releasenote.BreakingChanges,
|
||||
@ -86,6 +86,7 @@ func (p ReleaseNoteProcessorImpl) Format(releasenote ReleaseNote, version semver
|
||||
|
||||
// ReleaseNote release note.
|
||||
type ReleaseNote struct {
|
||||
Version semver.Version
|
||||
Date time.Time
|
||||
Sections map[string]ReleaseNoteSection
|
||||
BreakingChanges []string
|
||||
|
@ -4,41 +4,47 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/semver"
|
||||
)
|
||||
|
||||
func TestReleaseNoteProcessorImpl_Get(t *testing.T) {
|
||||
func TestReleaseNoteProcessorImpl_Create(t *testing.T) {
|
||||
date := time.Now()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
version semver.Version
|
||||
date time.Time
|
||||
commits []GitCommitLog
|
||||
want ReleaseNote
|
||||
}{
|
||||
{
|
||||
name: "mapped tag",
|
||||
version: *semver.MustParse("1.0.0"),
|
||||
date: date,
|
||||
commits: []GitCommitLog{commitlog("t1", map[string]string{})},
|
||||
want: releaseNote(date, map[string]ReleaseNoteSection{"t1": rnSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
|
||||
want: releaseNote(*semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": rnSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
|
||||
},
|
||||
{
|
||||
name: "unmapped tag",
|
||||
version: *semver.MustParse("1.0.0"),
|
||||
date: date,
|
||||
commits: []GitCommitLog{commitlog("t1", map[string]string{}), commitlog("unmapped", map[string]string{})},
|
||||
want: releaseNote(date, map[string]ReleaseNoteSection{"t1": rnSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
|
||||
want: releaseNote(*semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": rnSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
|
||||
},
|
||||
{
|
||||
name: "breaking changes tag",
|
||||
version: *semver.MustParse("1.0.0"),
|
||||
date: date,
|
||||
commits: []GitCommitLog{commitlog("t1", map[string]string{}), commitlog("unmapped", map[string]string{"breakingchange": "breaks"})},
|
||||
want: releaseNote(date, map[string]ReleaseNoteSection{"t1": rnSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, []string{"breaks"}),
|
||||
want: releaseNote(*semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": rnSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, []string{"breaks"}),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
p := NewReleaseNoteProcessor(map[string]string{"t1": "Tag 1", "t2": "Tag 2"})
|
||||
if got := p.Get(tt.date, tt.commits); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("ReleaseNoteProcessorImpl.Get() = %v, want %v", 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user