2019-11-17 16:17:24 +00:00
|
|
|
package sv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2021-02-13 18:40:09 +00:00
|
|
|
"github.com/Masterminds/semver/v3"
|
2019-11-17 16:17:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ReleaseNoteProcessor release note processor interface.
|
|
|
|
type ReleaseNoteProcessor interface {
|
2021-01-25 20:16:56 +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.
|
2021-01-25 20:16:56 +00:00
|
|
|
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 {
|
2021-02-14 02:35:31 +00:00
|
|
|
if name, exists := p.tags[commit.Message.Type]; exists {
|
|
|
|
section, sexists := sections[commit.Message.Type]
|
2019-11-17 16:17:24 +00:00
|
|
|
if !sexists {
|
|
|
|
section = ReleaseNoteSection{Name: name}
|
|
|
|
}
|
|
|
|
section.Items = append(section.Items, commit)
|
2021-02-14 02:35:31 +00:00
|
|
|
sections[commit.Message.Type] = section
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
2021-02-14 02:35:31 +00:00
|
|
|
if commit.Message.BreakingMessage() != "" {
|
|
|
|
// TODO: if no message found, should use description instead?
|
|
|
|
breakingChanges = append(breakingChanges, commit.Message.BreakingMessage())
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2021-01-25 20:16:56 +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
|
|
|
|
}
|