-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
template.go
66 lines (52 loc) · 1.66 KB
/
template.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
package tagpr
import (
"bytes"
"log"
"text/template"
)
const defaultTmplStr = `Release for {{.NextVersion}}
This pull request is for the next release as {{.NextVersion}} created by [tagpr](https://github.com/Songmu/tagpr). Merging it will tag {{.NextVersion}} to the merge commit and create a GitHub release.
You can modify this branch "{{.Branch}}" directly before merging if you want to change the next version number or other files for the release.
<details>
<summary>How to change the next version as you like</summary>
There are two ways to do it.
- Version file
- Edit and commit the version file specified in the .tagpr configuration file to describe the next version
- If you want to use another version file, edit the configuration file.
- Labels convention
- Add labels to this pull request like "tagpr:minor" or "tagpr:major"
- If no conventional labels are added, the patch version is incremented as is.
</details>
---
{{.Changelog}}`
var defaultTmpl *template.Template
func init() {
var err error
defaultTmpl, err = template.New("pull request template").Parse(defaultTmplStr)
if err != nil {
log.Fatal(err)
}
}
type tmplArg struct {
NextVersion, Branch, Changelog string
}
func newPRTmpl(tmpl *template.Template) *prTmpl {
if tmpl == nil {
tmpl = defaultTmpl
}
return &prTmpl{tmpl: tmpl}
}
type prTmpl struct {
tmpl *template.Template
}
func (pt *prTmpl) Render(arg *tmplArg) (string, error) {
var b bytes.Buffer
err := pt.tmpl.Execute(&b, arg)
if err != nil {
log.Printf("failed to render configured template: %s\n", err)
b.Reset()
// fallback to default template
err = defaultTmpl.Execute(&b, arg)
}
return b.String(), err
}