Esempio 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)
	}
}
Esempio 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)
	}
}
Esempio n. 3
0
func issues() {
	result, err := githublib.SearchIssues(os.Args[1:])
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%d issues: \n", result.TotalCount)
	for _, item := range result.Items {
		fmt.Printf("#%-5d %9.9s %55s\n",
			item.Number, item.User.Login, item.Title)
	}
}