2019-11-17 16:17:24 +00:00
|
|
|
package sv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Masterminds/semver"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ReleaseNoteProcessor release note processor interface.
|
|
|
|
type ReleaseNoteProcessor interface {
|
2020-02-02 00:00:53 +00:00
|
|
|
Create(version semver.Version, date time.Time, commits []GitCommitLog) ReleaseNote
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReleaseNoteProcessorImpl release note based on commit log.
|
|
|
|
type ReleaseNoteProcessorImpl struct {
|
2020-02-02 01:40:31 +00:00
|
|
|
tags map[string]string
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewReleaseNoteProcessor ReleaseNoteProcessor constructor.
|
|
|
|
func NewReleaseNoteProcessor(tags map[string]string) *ReleaseNoteProcessorImpl {
|
2020-02-02 01:40:31 +00:00
|
|
|
return &ReleaseNoteProcessorImpl{tags: tags}
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 00:00:53 +00:00
|
|
|
// Create create a release note based on commits.
|
|
|
|
func (p ReleaseNoteProcessorImpl) Create(version semver.Version, date time.Time, commits []GitCommitLog) ReleaseNote {
|
2019-11-17 16:17:24 +00:00
|
|
|
sections := make(map[string]ReleaseNoteSection)
|
|
|
|
var breakingChanges []string
|
|
|
|
for _, commit := range commits {
|
|
|
|
if name, exists := p.tags[commit.Type]; exists {
|
|
|
|
section, sexists := sections[commit.Type]
|
|
|
|
if !sexists {
|
|
|
|
section = ReleaseNoteSection{Name: name}
|
|
|
|
}
|
|
|
|
section.Items = append(section.Items, commit)
|
|
|
|
sections[commit.Type] = section
|
|
|
|
}
|
2020-02-02 00:15:12 +00:00
|
|
|
if value, exists := commit.Metadata[BreakingChangesKey]; exists {
|
2019-11-17 16:17:24 +00:00
|
|
|
breakingChanges = append(breakingChanges, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-02 00:00:53 +00:00
|
|
|
return ReleaseNote{Version: version, Date: date.Truncate(time.Minute), Sections: sections, BreakingChanges: breakingChanges}
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReleaseNote release note.
|
|
|
|
type ReleaseNote struct {
|
2020-02-02 00:00:53 +00:00
|
|
|
Version semver.Version
|
2019-11-17 16:17:24 +00:00
|
|
|
Date time.Time
|
|
|
|
Sections map[string]ReleaseNoteSection
|
|
|
|
BreakingChanges []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReleaseNoteSection release note section.
|
|
|
|
type ReleaseNoteSection struct {
|
|
|
|
Name string
|
|
|
|
Items []GitCommitLog
|
|
|
|
}
|