-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtemplates.go
74 lines (65 loc) · 2.09 KB
/
templates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package chglog
import (
"text/template"
"github.com/Masterminds/sprig/v3"
)
const (
rpmTpl = `
{{- range .Entries }}{{$version := semver .Semver}}
* {{ date_in_zone "Mon Jan 2 2006" .Date "UTC" }} {{ .Packager }} - {{ $version.Major }}.{{ $version.Minor }}.{{ $version.Patch }}{{if $version.Prerelease}}-{{ $version.Prerelease }}{{end}}
{{- range .Changes }}{{$note := splitList "\n" .Note}}
- {{ first $note }}{{ range $i,$n := (rest $note) }}{{if ne $n "\n"}} {{$n}}{{end}}
{{end}}
{{- end }}
{{ end }}
`
debTpl = `{{- $name := .Name}}
{{- range .Entries }}
{{ $name }} ({{ .Semver }}){{if .Deb}} {{default "" (.Deb.Distributions | join " ")}}; urgency={{default "low" .Deb.Urgency}}{{end}}
{{- range .Changes }}{{$note := splitList "\n" .Note}}
* {{ first $note }}
{{- range $i,$n := (rest $note) }}
{{- if ne (trim $n) ""}}
- {{$n}}{{end}}
{{- end}}{{end}}
-- {{ .Packager }} {{ date_in_zone "Mon, 02 Jan 2006 15:04:05 -0700" .Date "UTC" }}
{{ end }}
`
releaseTpl = `
Changelog
=========
{{- with (first .Entries)}}
{{range .Changes }}{{$note := splitList "\n" .Note}}
{{substr 0 8 .Commit}} {{ first $note }}{{end}}
{{ end}}
`
repoTpl = `
{{- range .Entries }}
{{ .Semver }}
=============
{{ date_in_zone "2006-01-02" .Date "UTC" }}
{{range .Changes }}{{$note := splitList "\n" .Note}}
* {{ first $note }} ({{substr 0 8 .Commit}}){{end}}
{{ end}}
`
)
// LoadTemplateData load a template from string with all of the sprig.TxtFuncMap loaded.
func LoadTemplateData(data string) (*template.Template, error) {
return template.New("base").Funcs(sprig.TxtFuncMap()).Parse(data)
}
// DebTemplate load default debian template.
func DebTemplate() (*template.Template, error) {
return LoadTemplateData(debTpl)
}
// RPMTemplate load default RPM template.
func RPMTemplate() (*template.Template, error) {
return LoadTemplateData(rpmTpl)
}
// ReleaseTemplate load default release template.
func ReleaseTemplate() (*template.Template, error) {
return LoadTemplateData(releaseTpl)
}
// RepoTemplate load default repo template.
func RepoTemplate() (*template.Template, error) {
return LoadTemplateData(repoTpl)
}