Ejemplo n.º 1
0
func issuesReport() {
	const templ = `{{.TotalCount}} issues:
{{range .Items}}----------------------------------------
Number: {{.Number}}
User:   {{.User.Login}}
Title:  {{.Title | printf "%.64s"}}
Age:    {{.CreateAt | daysAgo}} days
{{end}}`
	daysAgo := func(t time.Time) int {
		return int(time.Since(t).Hours() / 24)
	}
	report, err := template.New("report").
		Funcs(template.FuncMap{"daysAgo": daysAgo}).
		Parse(templ)
	if err != nil {
		glog.Fatal(err)
	}
	result, err := githublib.SearchIssues(os.Args[1:])
	glog.Infoln(handy.MarshalJSONOrDie(result))
	if err != nil {
		glog.Fatal(err)
	}
	if err := report.Execute(os.Stderr, result); err != nil {
		glog.Fatal(err)
	}
}
Ejemplo n.º 2
0
func issuesReportHTML() {
	// go run main.go repo:golang/go commenter:gopherbot json encoder >issues.html
	var issueList = template.Must(template.New("issuelist").Parse(`
<h1>{{.TotalCount}} issues</h1>
<table>
<tr style='text-align: left'>
  <th>#</th>
  <th>State</th>
  <th>User</th>
  <th>Title</th>
</tr>
{{range .Items}}
<tr>
  <td><a href='{{.HTMLURL}}'>{{.Number}}</a></td>
  <td>{{.State}}</td>
  <td><a href='{{.User.HTMLURL}}'>{{.User.Login}}</a></td>
  <td><a href='{{.HTMLURL}}'>{{.Title}}</a></td>
</tr>
{{end}}
</table>
`))
	result, err := githublib.SearchIssues(os.Args[1:])
	glog.Infoln(handy.MarshalJSONOrDie(result))
	if err != nil {
		glog.Fatal(err)
	}
	if err := issueList.Execute(os.Stdout, result); err != nil {
		glog.Fatal(err)
	}
}