forked from sj14/review-bot
/
template.go
44 lines (35 loc) 路 1.13 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
package github
import (
"bytes"
"log"
"text/template"
"github.com/google/go-github/v25/github"
)
// DefaultTemplate contains a project header and reminder messages.
func DefaultTemplate() *template.Template {
const defaultTemplate = `
# [{{.Repository.Name}}]({{.Repository.HTMLURL}})
**How-To**: *Got reminded? Just normally review the given pull request.*
---
{{range .Reminders}}
**[{{.PR.Title}}]({{.PR.HTMLURL}})**
{{if .Discussions}} {{.Discussions}} 馃挰 {{end}} {{range $emoji, $count := .Emojis}} {{$count}} :{{$emoji}}: {{end}} {{range .Missing}}{{.}} {{else}}You got all reviews, {{.Owner}}.{{end}}
{{end}}
`
return template.Must(template.New("default").Parse(defaultTemplate))
}
// Exec the reminder message for the given merge request.
func ExecTemplate(template *template.Template, repository *github.Repository, reminders []reminder) string {
data := struct {
Repository *github.Repository
Reminders []reminder
}{
repository,
reminders,
}
buffer := bytes.NewBuffer([]byte{})
if err := template.Execute(buffer, data); err != nil {
log.Fatalf("failed executing template: %v", err)
}
return buffer.String()
}