releaser: Fix tag detection for changelog when doing a main release

Also improve the changelog slightly.

Fixes #3482
This commit is contained in:
Bjørn Erik Pedersen
2017-05-20 10:58:08 +03:00
committed by GitHub
parent a59525b05b
commit 4d1989d59c
5 changed files with 102 additions and 32 deletions

View File

@@ -25,6 +25,7 @@ import (
var issueRe = regexp.MustCompile(`(?i)[Updates?|Closes?|Fix.*|See] #(\d+)`)
const (
notesChanges = "notesChanges"
templateChanges = "templateChanges"
coreChanges = "coreChanges"
outChanges = "outChanges"
@@ -36,6 +37,7 @@ type changeLog struct {
Version string
Enhancements map[string]gitInfos
Fixes map[string]gitInfos
Notes gitInfos
All gitInfos
// Overall stats
@@ -44,22 +46,25 @@ type changeLog struct {
ThemeCount int
}
func newChangeLog(infos gitInfos) changeLog {
return changeLog{
func newChangeLog(infos gitInfos) *changeLog {
return &changeLog{
Enhancements: make(map[string]gitInfos),
Fixes: make(map[string]gitInfos),
All: infos,
}
}
func (l changeLog) addGitInfo(isFix bool, info gitInfo, category string) {
func (l *changeLog) addGitInfo(isFix bool, info gitInfo, category string) {
var (
infos gitInfos
found bool
segment map[string]gitInfos
)
if isFix {
if category == notesChanges {
l.Notes = append(l.Notes, info)
return
} else if isFix {
segment = l.Fixes
} else {
segment = l.Enhancements
@@ -74,7 +79,7 @@ func (l changeLog) addGitInfo(isFix bool, info gitInfo, category string) {
segment[category] = infos
}
func gitInfosToChangeLog(infos gitInfos) changeLog {
func gitInfosToChangeLog(infos gitInfos) *changeLog {
log := newChangeLog(infos)
for _, info := range infos {
los := strings.ToLower(info.Subject)
@@ -82,7 +87,9 @@ func gitInfosToChangeLog(infos gitInfos) changeLog {
var category = otherChanges
// TODO(bep) improve
if regexp.MustCompile("(?i)tpl:|tplimpl:|layout").MatchString(los) {
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)docs?:|documentation:").MatchString(los) {
category = docsChanges
@@ -150,8 +157,8 @@ func git(args ...string) (string, error) {
return string(out), nil
}
func getGitInfos(remote bool) (gitInfos, error) {
return getGitInfosBefore("HEAD", remote)
func getGitInfos(tag string, remote bool) (gitInfos, error) {
return getGitInfosBefore("HEAD", tag, remote)
}
type countribCount struct {
@@ -207,11 +214,11 @@ func (g gitInfos) ContribCountPerAuthor() contribCounts {
return c
}
func getGitInfosBefore(ref string, remote bool) (gitInfos, error) {
func getGitInfosBefore(ref, tag string, remote bool) (gitInfos, error) {
var g gitInfos
log, err := gitLogBefore(ref)
log, err := gitLogBefore(ref, tag)
if err != nil {
return g, err
}
@@ -242,10 +249,16 @@ func getGitInfosBefore(ref string, remote bool) (gitInfos, error) {
// Ignore autogenerated commits etc. in change log. This is a regexp.
const ignoredCommits = "release:|vendor:|snapcraft:"
func gitLogBefore(ref string) (string, error) {
prevTag, err := gitShort("describe", "--tags", "--abbrev=0", "--always", ref+"^")
if err != nil {
return "", err
func gitLogBefore(ref, tag string) (string, error) {
var prevTag string
var err error
if tag != "" {
prevTag = tag
} else {
prevTag, err = gitVersionTagBefore(ref)
if err != nil {
return "", err
}
}
log, err := git("log", "-E", fmt.Sprintf("--grep=%s", ignoredCommits), "--invert-grep", "--pretty=format:%x1e%h%x1f%aE%x1f%s%x1f%b", "--abbrev-commit", prevTag+".."+ref)
if err != nil {
@@ -255,11 +268,29 @@ func gitLogBefore(ref string) (string, error) {
return log, err
}
func gitVersionTagBefore(ref string) (string, error) {
return gitShort("describe", "--tags", "--abbrev=0", "--always", "--match", "v[0-9]*", ref+"^")
}
func gitLog() (string, error) {
return gitLogBefore("HEAD")
return gitLogBefore("HEAD", "")
}
func gitShort(args ...string) (output string, err error) {
output, err = git(args...)
return strings.Replace(strings.Split(output, "\n")[0], "'", "", -1), err
}
func tagExists(tag string) (bool, error) {
out, err := git("tag", "-l", tag)
if err != nil {
return false, err
}
if strings.Contains(out, tag) {
return true, nil
}
return false, nil
}