releaser: Include stats from hugoDocs

Fixes #3727
This commit is contained in:
Bjørn Erik Pedersen 2017-08-06 10:42:07 +02:00
parent f768c27f0d
commit 11e5d456e8
5 changed files with 54 additions and 24 deletions

View file

@ -38,6 +38,7 @@ type changeLog struct {
Fixes map[string]gitInfos Fixes map[string]gitInfos
Notes gitInfos Notes gitInfos
All gitInfos All gitInfos
Docs gitInfos
// Overall stats // Overall stats
Repo *gitHubRepo Repo *gitHubRepo
@ -45,11 +46,12 @@ type changeLog struct {
ThemeCount int ThemeCount int
} }
func newChangeLog(infos gitInfos) *changeLog { func newChangeLog(infos, docInfos gitInfos) *changeLog {
return &changeLog{ return &changeLog{
Enhancements: make(map[string]gitInfos), Enhancements: make(map[string]gitInfos),
Fixes: make(map[string]gitInfos), Fixes: make(map[string]gitInfos),
All: infos, All: infos,
Docs: docInfos,
} }
} }
@ -78,8 +80,8 @@ func (l *changeLog) addGitInfo(isFix bool, info gitInfo, category string) {
segment[category] = infos segment[category] = infos
} }
func gitInfosToChangeLog(infos gitInfos) *changeLog { func gitInfosToChangeLog(infos, docInfos gitInfos) *changeLog {
log := newChangeLog(infos) log := newChangeLog(infos, docInfos)
for _, info := range infos { for _, info := range infos {
los := strings.ToLower(info.Subject) los := strings.ToLower(info.Subject)
isFix := strings.Contains(los, "fix") isFix := strings.Contains(los, "fix")
@ -154,8 +156,8 @@ func git(args ...string) (string, error) {
return string(out), nil return string(out), nil
} }
func getGitInfos(tag string, remote bool) (gitInfos, error) { func getGitInfos(tag, repoPath string, remote bool) (gitInfos, error) {
return getGitInfosBefore("HEAD", tag, remote) return getGitInfosBefore("HEAD", tag, repoPath, remote)
} }
type countribCount struct { type countribCount struct {
@ -211,11 +213,11 @@ func (g gitInfos) ContribCountPerAuthor() contribCounts {
return c return c
} }
func getGitInfosBefore(ref, tag string, remote bool) (gitInfos, error) { func getGitInfosBefore(ref, tag, repoPath string, remote bool) (gitInfos, error) {
var g gitInfos var g gitInfos
log, err := gitLogBefore(ref, tag) log, err := gitLogBefore(ref, tag, repoPath)
if err != nil { if err != nil {
return g, err return g, err
} }
@ -246,7 +248,7 @@ func getGitInfosBefore(ref, tag string, remote bool) (gitInfos, error) {
// Ignore autogenerated commits etc. in change log. This is a regexp. // Ignore autogenerated commits etc. in change log. This is a regexp.
const ignoredCommits = "releaser?:|snapcraft:|Merge commit|Squashed|Revert" const ignoredCommits = "releaser?:|snapcraft:|Merge commit|Squashed|Revert"
func gitLogBefore(ref, tag string) (string, error) { func gitLogBefore(ref, tag, repoPath string) (string, error) {
var prevTag string var prevTag string
var err error var err error
if tag != "" { if tag != "" {
@ -257,7 +259,18 @@ func gitLogBefore(ref, tag string) (string, error) {
return "", err 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)
defaultArgs := []string{"log", "-E", fmt.Sprintf("--grep=%s", ignoredCommits), "--invert-grep", "--pretty=format:%x1e%h%x1f%aE%x1f%s%x1f%b", "--abbrev-commit", prevTag + ".." + ref}
var args []string
if repoPath != "" {
args = append([]string{"-C", repoPath}, defaultArgs...)
} else {
args = defaultArgs
}
log, err := git(args...)
if err != nil { if err != nil {
return ",", err return ",", err
} }
@ -270,7 +283,7 @@ func gitVersionTagBefore(ref string) (string, error) {
} }
func gitLog() (string, error) { func gitLog() (string, error) {
return gitLogBefore("HEAD", "") return gitLogBefore("HEAD", "", "")
} }
func gitShort(args ...string) (output string, err error) { func gitShort(args ...string) (output string, err error) {

View file

@ -22,7 +22,7 @@ import (
func TestGitInfos(t *testing.T) { func TestGitInfos(t *testing.T) {
skipIfCI(t) skipIfCI(t)
infos, err := getGitInfos("v0.20", false) infos, err := getGitInfos("v0.20", "", false)
require.NoError(t, err) require.NoError(t, err)
require.True(t, len(infos) > 0) require.True(t, len(infos) > 0)

View file

@ -34,7 +34,7 @@ const (
releaseNotesMarkdownTemplate = ` releaseNotesMarkdownTemplate = `
{{- $patchRelease := isPatch . -}} {{- $patchRelease := isPatch . -}}
{{- $contribsPerAuthor := .All.ContribCountPerAuthor -}} {{- $contribsPerAuthor := .All.ContribCountPerAuthor -}}
{{- $docsContribsPerAuthor := .Docs.ContribCountPerAuthor -}}
{{- if $patchRelease }} {{- if $patchRelease }}
{{ if eq (len .All) 1 }} {{ if eq (len .All) 1 }}
This is a bug-fix release with one important fix. This is a bug-fix release with one important fix.
@ -53,6 +53,16 @@ This release represents **{{ len .All }} contributions by {{ len $contribsPerAut
{{- $u1.AuthorLink }} leads the Hugo development with a significant amount of contributions, but also a big shoutout to {{ $u2.AuthorLink }}, {{ $u3.AuthorLink }}, and {{ $u4.AuthorLink }} for their ongoing contributions. {{- $u1.AuthorLink }} leads the Hugo development with a significant amount of contributions, but also a big shoutout to {{ $u2.AuthorLink }}, {{ $u3.AuthorLink }}, and {{ $u4.AuthorLink }} for their ongoing contributions.
And as always a big thanks to [@digitalcraftsman](https://github.com/digitalcraftsman) for his relentless work on keeping the documentation and the themes site in pristine condition. And as always a big thanks to [@digitalcraftsman](https://github.com/digitalcraftsman) for his relentless work on keeping the documentation and the themes site in pristine condition.
{{ end }} {{ end }}
{{- if not $patchRelease }}
Many have also been busy writing and fixing the documentation in [hugoDocs](https://github.com/gohugoio/hugoDocs),
which has received **{{ len .Docs }} contributions by {{ len $docsContribsPerAuthor }} contributors**.
{{- if gt (len $docsContribsPerAuthor) 3 -}}
{{- $u1 := index $docsContribsPerAuthor 0 -}}
{{- $u2 := index $docsContribsPerAuthor 1 -}}
{{- $u3 := index $docsContribsPerAuthor 2 -}}
{{- $u4 := index $docsContribsPerAuthor 3 }} A special thanks to {{ $u1.AuthorLink }}, {{ $u2.AuthorLink }}, {{ $u3.AuthorLink }}, and {{ $u4.AuthorLink }} for their work on the documentation site.
{{ end }}
{{ end }}
Hugo now has: Hugo now has:
{{ with .Repo -}} {{ with .Repo -}}
@ -61,7 +71,7 @@ Hugo now has:
{{- end -}} {{- end -}}
{{ with .ThemeCount }} {{ with .ThemeCount }}
* {{ . }}+ [themes](http://themes.gohugo.io/) * {{ . }}+ [themes](http://themes.gohugo.io/)
{{- end }} {{ end }}
{{ with .Notes }} {{ with .Notes }}
## Notes ## Notes
{{ template "change-section" . }} {{ template "change-section" . }}
@ -128,8 +138,8 @@ var templateFuncs = template.FuncMap{
}, },
} }
func writeReleaseNotes(version string, infos gitInfos, to io.Writer) error { func writeReleaseNotes(version string, infosMain, infosDocs gitInfos, to io.Writer) error {
changes := gitInfosToChangeLog(infos) changes := gitInfosToChangeLog(infosMain, infosDocs)
changes.Version = version changes.Version = version
repo, err := fetchRepo() repo, err := fetchRepo()
if err == nil { if err == nil {
@ -165,7 +175,7 @@ func fetchThemeCount() (int, error) {
return bytes.Count(b, []byte("submodule")), nil return bytes.Count(b, []byte("submodule")), nil
} }
func writeReleaseNotesToTmpFile(version string, infos gitInfos) (string, error) { func writeReleaseNotesToTmpFile(version string, infosMain, infosDocs gitInfos) (string, error) {
f, err := ioutil.TempFile("", "hugorelease") f, err := ioutil.TempFile("", "hugorelease")
if err != nil { if err != nil {
return "", err return "", err
@ -173,7 +183,7 @@ func writeReleaseNotesToTmpFile(version string, infos gitInfos) (string, error)
defer f.Close() defer f.Close()
if err := writeReleaseNotes(version, infos, f); err != nil { if err := writeReleaseNotes(version, infosMain, infosDocs, f); err != nil {
return "", err return "", err
} }
@ -188,7 +198,7 @@ func getReleaseNotesDocsTempFilename(version string) string {
return filepath.Join(getReleaseNotesDocsTempDirAndName(version)) return filepath.Join(getReleaseNotesDocsTempDirAndName(version))
} }
func (r *ReleaseHandler) writeReleaseNotesToTemp(version string, infos gitInfos) (string, error) { func (r *ReleaseHandler) writeReleaseNotesToTemp(version string, infosMain, infosDocs gitInfos) (string, error) {
docsTempPath, name := getReleaseNotesDocsTempDirAndName(version) docsTempPath, name := getReleaseNotesDocsTempDirAndName(version)
@ -214,7 +224,7 @@ func (r *ReleaseHandler) writeReleaseNotesToTemp(version string, infos gitInfos)
w = os.Stdout w = os.Stdout
} }
if err := writeReleaseNotes(version, infos, w); err != nil { if err := writeReleaseNotes(version, infosMain, infosDocs, w); err != nil {
return "", err return "", err
} }

View file

@ -34,10 +34,10 @@ func _TestReleaseNotesWriter(t *testing.T) {
var b bytes.Buffer var b bytes.Buffer
// TODO(bep) consider to query GitHub directly for the gitlog with author info, probably faster. // TODO(bep) consider to query GitHub directly for the gitlog with author info, probably faster.
infos, err := getGitInfosBefore("HEAD", "v0.20", false) infos, err := getGitInfosBefore("HEAD", "v0.20", "", false)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, writeReleaseNotes("0.21", infos, &b)) require.NoError(t, writeReleaseNotes("0.21", infos, infos, &b))
fmt.Println(b.String()) fmt.Println(b.String())

View file

@ -130,17 +130,24 @@ func (r *ReleaseHandler) Run() error {
} }
} }
var gitCommits gitInfos var (
gitCommits gitInfos
gitCommitsDocs gitInfos
)
if r.shouldPrepareReleasenotes() || r.shouldRelease() { if r.shouldPrepareReleasenotes() || r.shouldRelease() {
gitCommits, err = getGitInfos(changeLogFromTag, !r.try) gitCommits, err = getGitInfos(changeLogFromTag, "", !r.try)
if err != nil {
return err
}
gitCommitsDocs, err = getGitInfos(changeLogFromTag, "../hugoDocs", !r.try)
if err != nil { if err != nil {
return err return err
} }
} }
if r.shouldPrepareReleasenotes() { if r.shouldPrepareReleasenotes() {
releaseNotesFile, err := r.writeReleaseNotesToTemp(version, gitCommits) releaseNotesFile, err := r.writeReleaseNotesToTemp(version, gitCommits, gitCommitsDocs)
if err != nil { if err != nil {
return err return err
} }