releaser: Rework and simplify to use GitHub only for release notes

This commit is contained in:
Bjørn Erik Pedersen 2021-12-02 22:08:52 +01:00
parent bf1564bd2c
commit 24a893cf83
4 changed files with 27 additions and 177 deletions

View file

@ -34,12 +34,10 @@ const (
)
type changeLog struct {
Version string
Enhancements map[string]gitInfos
Fixes map[string]gitInfos
Notes gitInfos
All gitInfos
Docs gitInfos
Version string
Notes gitInfos
All gitInfos
Docs gitInfos
// Overall stats
Repo *gitHubRepo
@ -48,66 +46,19 @@ type changeLog struct {
}
func newChangeLog(infos, docInfos gitInfos) *changeLog {
return &changeLog{
Enhancements: make(map[string]gitInfos),
Fixes: make(map[string]gitInfos),
All: infos,
Docs: docInfos,
}
}
func (l *changeLog) addGitInfo(isFix bool, info gitInfo, category string) {
var (
infos gitInfos
found bool
segment map[string]gitInfos
)
if category == notesChanges {
l.Notes = append(l.Notes, info)
return
} else if isFix {
segment = l.Fixes
} else {
segment = l.Enhancements
log := &changeLog{
Docs: docInfos,
}
infos, found = segment[category]
if !found {
infos = gitInfos{}
}
infos = append(infos, info)
segment[category] = infos
}
func gitInfosToChangeLog(infos, docInfos gitInfos) *changeLog {
log := newChangeLog(infos, docInfos)
for _, info := range infos {
los := strings.ToLower(info.Subject)
isFix := strings.Contains(los, "fix")
category := otherChanges
// TODO(bep) improve
if regexp.MustCompile("(?i)deprecate").MatchString(los) {
category = notesChanges
} else if regexp.MustCompile("(?i)tpl|tplimpl:|layout").MatchString(los) {
category = templateChanges
} else if regexp.MustCompile("(?i)hugolib:").MatchString(los) {
category = coreChanges
} else if regexp.MustCompile("(?i)out(put)?:|media:|Output|Media").MatchString(los) {
category = outChanges
}
// Trim package prefix.
colonIdx := strings.Index(info.Subject, ":")
if colonIdx != -1 && colonIdx < (len(info.Subject)/2) {
info.Subject = info.Subject[colonIdx+1:]
if regexp.MustCompile("(?i)deprecate").MatchString(info.Subject) {
log.Notes = append(log.Notes, info)
}
log.All = append(log.All, info)
info.Subject = strings.TrimSpace(info.Subject)
log.addGitInfo(isFix, info, category)
}
return log
@ -255,7 +206,7 @@ func getGitInfosBefore(ref, tag, repo, repoPath string, remote bool) (gitInfos,
}
// Ignore autogenerated commits etc. in change log. This is a regexp.
const ignoredCommits = "releaser?:|snapcraft:|Merge commit|Squashed"
const ignoredCommits = "snapcraft:|Merge commit|Squashed"
func gitLogBefore(ref, tag, repoPath string) (string, error) {
var prevTag string