Merge pull request #20 from git-chglog/feat/kac-template-title-id

Add tag name header id for keep-a-changelog template
This commit is contained in:
tsuyoshi wada 2018-05-04 17:32:52 +09:00 committed by GitHub
commit c36bc89869
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 5 deletions

View file

@ -400,6 +400,7 @@ The basic templates are as follows.
```markdown
{{ if .Versions -}}
<a name="unreleased"></a>
## [Unreleased]
{{ if .Unreleased.CommitGroups -}}
@ -413,6 +414,7 @@ The basic templates are as follows.
{{ end -}}
{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
{{ range .CommitGroups -}}
### {{ .Title }}

View file

@ -49,10 +49,10 @@ func (*customTemplateBuilderImpl) versionHeader(style, template string) string {
// parts
switch style {
case styleGitHub, styleGitLab:
tpl = "<a name=\"{{ .Tag.Name }}\"></a>\n"
tpl = templateTagNameAnchor
tagName = "{{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }}"
case styleBitbucket:
tpl = "<a name=\"{{ .Tag.Name }}\"></a>\n"
tpl = templateTagNameAnchor
tagName = "{{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Name }}..{{ .Tag.Previous.Name }}){{ else }}{{ .Tag.Name }}{{ end }}"
}

View file

@ -46,36 +46,40 @@ func (t *kacTemplateBuilderImpl) Build(ans *Answer) (string, error) {
func (t *kacTemplateBuilderImpl) unreleased(style, format string) string {
var (
id = ""
title = "Unreleased"
commits = t.commits(".Unreleased.CommitGroups", format)
)
switch style {
case styleGitHub, styleGitLab, styleBitbucket:
id = "<a name=\"unreleased\"></a>\n"
title = fmt.Sprintf("[%s]", title)
}
return fmt.Sprintf(`{{ if .Versions -}}
## %s
%s## %s
{{ if .Unreleased.CommitGroups -}}
%s{{ end -}}
{{ end -}}
`, title, commits)
`, id, title, commits)
}
func (t *kacTemplateBuilderImpl) versionHeader(style string) string {
var (
id = ""
tagName = "{{ .Tag.Name }}"
date = "{{ datetime \"2006-01-02\" .Tag.Date }}"
)
switch style {
case styleGitHub, styleGitLab, styleBitbucket:
id = templateTagNameAnchor
tagName = "{{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }}"
}
return fmt.Sprintf("## %s - %s\n", tagName, date)
return fmt.Sprintf("%s## %s - %s\n", id, tagName, date)
}
func (t *kacTemplateBuilderImpl) commits(commitGroups, format string) string {

View file

@ -20,6 +20,7 @@ func TestKACTemplateBuilderDefault(t *testing.T) {
assert.Nil(err)
assert.Equal(`{{ if .Versions -}}
<a name="unreleased"></a>
## [Unreleased]
{{ if .Unreleased.CommitGroups -}}
@ -33,6 +34,7 @@ func TestKACTemplateBuilderDefault(t *testing.T) {
{{ end -}}
{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
{{ range .CommitGroups -}}
### {{ .Title }}

View file

@ -1,5 +1,7 @@
package main
const templateTagNameAnchor = "<a name=\"{{ .Tag.Name }}\"></a>\n"
// TemplateBuilder ...
type TemplateBuilder interface {
Builder