-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
79 lines (67 loc) · 1.77 KB
/
main.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
75
76
77
78
79
// A command-line utility to run a search query and display results.
package main
import (
"flag"
"fmt"
"log"
"net/http"
"github.com/google/go-github/v28/github"
"github.com/parkr/github-utils/gh"
"github.com/parkr/github-utils/search"
"github.com/parkr/github-utils/webview"
)
func haltIfError(err error) {
if err != nil {
log.Fatalln("error:", err)
}
}
func truncate(text string, max int) string {
if len(text) <= max {
return text
}
return text[0:max-3] + "..."
}
func printIssues(title string, issues []github.Issue) {
fmt.Printf("%d %s:\n", len(issues), title)
for _, issue := range issues {
fmt.Printf("%s | %-50s | %s\n",
issue.CreatedAt.Format("2006-01-02"),
truncate(*issue.Title, 50),
*issue.HTMLURL,
)
}
}
func unearthForUser(client *gh.Client, user string) {
issues, err := search.FindAllAssignedIssues(client, user)
haltIfError(err)
printIssues(fmt.Sprintf("issues assigned to %s", user), issues)
issues, err = search.FindAllUnansweredMentions(client, user)
haltIfError(err)
printIssues(fmt.Sprintf("unanswered issues for %s", user), issues)
}
func main() {
var httpBind string
flag.StringVar(&httpBind, "http", "", "The network binding to attach a server to. Only boots server if specified.")
flag.Parse()
client, err := gh.NewDefaultClient()
if err != nil {
log.Fatalf("fatal: could not initialize client: %v", err)
}
users := []string{"parkr"}
if flag.NArg() > 0 {
users = flag.Args()
}
if httpBind != "" {
handler := webview.Handler{Users: users, Client: client}
http.Handle("/", handler)
log.Println("Starting server on", httpBind)
if err := http.ListenAndServe(httpBind, nil); err != nil {
log.Fatalln(err)
}
} else {
// Print to stdout.
for _, user := range users {
unearthForUser(client, user)
}
}
}