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-12-29 21:02:50 +00:00
|
|
|
Create(version *semver.Version, tag string, date time.Time, commits []GitCommitLog) ReleaseNote
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReleaseNoteProcessorImpl release note based on commit log.
|
|
|
|
type ReleaseNoteProcessorImpl struct {
|
2021-02-14 05:32:23 +00:00
|
|
|
cfg ReleaseNotesConfig
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewReleaseNoteProcessor ReleaseNoteProcessor constructor.
|
2021-02-14 05:32:23 +00:00
|
|
|
func NewReleaseNoteProcessor(cfg ReleaseNotesConfig) *ReleaseNoteProcessorImpl {
|
|
|
|
return &ReleaseNoteProcessorImpl{cfg: cfg}
|
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-12-29 21:02:50 +00:00
|
|
|
func (p ReleaseNoteProcessorImpl) Create(version *semver.Version, tag string, date time.Time, commits []GitCommitLog) ReleaseNote {
|
2019-11-17 16:17:24 +00:00
|
|
|
sections := make(map[string]ReleaseNoteSection)
|
2022-02-07 01:06:46 +00:00
|
|
|
authors := make(map[string]struct{})
|
2019-11-17 16:17:24 +00:00
|
|
|
var breakingChanges []string
|
|
|
|
for _, commit := range commits {
|
2022-02-07 01:06:46 +00:00
|
|
|
authors[commit.AuthorName] = struct{}{}
|
2021-02-14 05:32:23 +00:00
|
|
|
if name, exists := p.cfg.Headers[commit.Message.Type]; exists {
|
2021-02-14 02:35:31 +00:00
|
|
|
section, sexists := sections[commit.Message.Type]
|
2019-11-17 16:17:24 +00:00
|
|
|
if !sexists {
|
2022-02-07 01:06:46 +00:00
|
|
|
section = ReleaseNoteSection{Name: name, Types: []string{commit.Message.Type}} //TODO: change to support more than one type per section
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-15 04:47:20 +00:00
|
|
|
var breakingChangeSection BreakingChangeSection
|
|
|
|
if name, exists := p.cfg.Headers[breakingChangeMetadataKey]; exists && len(breakingChanges) > 0 {
|
|
|
|
breakingChangeSection = BreakingChangeSection{Name: name, Messages: breakingChanges}
|
|
|
|
}
|
2022-02-07 01:06:46 +00:00
|
|
|
return ReleaseNote{Version: version, Tag: tag, Date: date.Truncate(time.Minute), Sections: sections, BreakingChanges: breakingChangeSection, AuthorsNames: authors}
|
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
|
2021-12-29 21:02:50 +00:00
|
|
|
Tag string
|
2019-11-17 16:17:24 +00:00
|
|
|
Date time.Time
|
|
|
|
Sections map[string]ReleaseNoteSection
|
2021-02-15 04:47:20 +00:00
|
|
|
BreakingChanges BreakingChangeSection
|
2022-02-07 01:06:46 +00:00
|
|
|
AuthorsNames map[string]struct{}
|
2021-02-15 04:47:20 +00:00
|
|
|
}
|
|
|
|
|
2021-07-31 19:03:58 +00:00
|
|
|
// BreakingChangeSection breaking change section.
|
2021-02-15 04:47:20 +00:00
|
|
|
type BreakingChangeSection struct {
|
|
|
|
Name string
|
|
|
|
Messages []string
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ReleaseNoteSection release note section.
|
|
|
|
type ReleaseNoteSection struct {
|
|
|
|
Name string
|
2022-02-07 01:06:46 +00:00
|
|
|
Types []string
|
2019-11-17 16:17:24 +00:00
|
|
|
Items []GitCommitLog
|
|
|
|
}
|