mirror of
https://github.com/romdo/go-conver.git
synced 2026-02-19 08:16:40 +00:00
fix(changelog): improve changelog template
This commit is contained in:
50
main.go
50
main.go
@@ -20,24 +20,11 @@ import (
|
|||||||
|
|
||||||
const changelogTemplate = `
|
const changelogTemplate = `
|
||||||
## {{ .Version }}
|
## {{ .Version }}
|
||||||
|
{{ range $type, $commits := .CommitsGrouped }}
|
||||||
{{- range $commit := .Commits }}
|
### {{ $type }}
|
||||||
|
{{ range $commit := $commits }}
|
||||||
### {{ $commit.Git.Hash }}
|
* {{ if $commit.Conv.Scope }}__{{ $commit.Conv.Scope }}:__ {{ else }}{{ end }}{{ $commit.Conv.Description }}
|
||||||
|
{{- end }}
|
||||||
{{ $commit.Git.Message }}
|
|
||||||
* Type: {{ $commit.Conv.Type }}
|
|
||||||
* Scope: {{ $commit.Conv.Scope }}
|
|
||||||
* Description: {{ $commit.Conv.Description }}
|
|
||||||
* Header: {{ $commit.Conv.Header }}
|
|
||||||
* MergeHeader: {{ $commit.Conv.MergeHeader }}
|
|
||||||
* Body: {{ $commit.Conv.Body }}
|
|
||||||
* Footers: {{ $commit.Conv.Footers }}
|
|
||||||
* Mentions: {{ $commit.Conv.Mentions }}
|
|
||||||
* References: {{ $commit.Conv.References }}
|
|
||||||
* Notes: {{ $commit.Conv.Notes }}
|
|
||||||
* Reverts: {{ $commit.Conv.Reverts }}
|
|
||||||
* IsBreaking: {{ $commit.Conv.IsBreaking }}
|
|
||||||
{{ end }}
|
{{ end }}
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -64,8 +51,9 @@ type (
|
|||||||
ChangelogPath string `flag:"changelog-path" desc:"Changelog file path"`
|
ChangelogPath string `flag:"changelog-path" desc:"Changelog file path"`
|
||||||
}
|
}
|
||||||
changelogEntry struct {
|
changelogEntry struct {
|
||||||
Version string
|
Version string
|
||||||
Commits []*changelogCommit
|
Commits []*changelogCommit
|
||||||
|
CommitsGrouped map[string][]*changelogCommit
|
||||||
}
|
}
|
||||||
changelogCommit struct {
|
changelogCommit struct {
|
||||||
Git *object.Commit
|
Git *object.Commit
|
||||||
@@ -283,6 +271,7 @@ func changelogUpdate(c *config) error {
|
|||||||
|
|
||||||
// find commits since the latest tag
|
// find commits since the latest tag
|
||||||
commitsSinceTag := []*changelogCommit{}
|
commitsSinceTag := []*changelogCommit{}
|
||||||
|
commitsSinceTagGrouped := map[string][]*changelogCommit{}
|
||||||
commitIter, err := repo.Log(&git.LogOptions{})
|
commitIter, err := repo.Log(&git.LogOptions{})
|
||||||
err = commitIter.ForEach(func(commit *object.Commit) error {
|
err = commitIter.ForEach(func(commit *object.Commit) error {
|
||||||
// once we reach the commit of the latest tag, we're done
|
// once we reach the commit of the latest tag, we're done
|
||||||
@@ -293,10 +282,22 @@ func changelogUpdate(c *config) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
commitsSinceTag = append(commitsSinceTag, &changelogCommit{
|
changelogEntry := &changelogCommit{
|
||||||
Git: commit,
|
Git: commit,
|
||||||
Conv: convCommit,
|
Conv: convCommit,
|
||||||
})
|
}
|
||||||
|
commitType := convCommit.Type
|
||||||
|
if convCommit.IsBreaking {
|
||||||
|
commitType = "breaking"
|
||||||
|
}
|
||||||
|
commitsSinceTag = append(commitsSinceTag, changelogEntry)
|
||||||
|
if _, ok := commitsSinceTagGrouped[commitType]; !ok {
|
||||||
|
commitsSinceTagGrouped[commitType] = []*changelogCommit{}
|
||||||
|
}
|
||||||
|
commitsSinceTagGrouped[commitType] = append(
|
||||||
|
commitsSinceTagGrouped[commitType],
|
||||||
|
changelogEntry,
|
||||||
|
)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil && err != errDone {
|
if err != nil && err != errDone {
|
||||||
@@ -317,8 +318,9 @@ func changelogUpdate(c *config) error {
|
|||||||
// render template
|
// render template
|
||||||
var newBody bytes.Buffer
|
var newBody bytes.Buffer
|
||||||
if err := tmpl.Execute(&newBody, &changelogEntry{
|
if err := tmpl.Execute(&newBody, &changelogEntry{
|
||||||
Version: newVersion,
|
Version: newVersion,
|
||||||
Commits: commitsSinceTag,
|
Commits: commitsSinceTag,
|
||||||
|
CommitsGrouped: commitsSinceTagGrouped,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user