-
Notifications
You must be signed in to change notification settings - Fork 1
/
issues.go
65 lines (56 loc) · 1.26 KB
/
issues.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
package comatome
import (
"context"
"fmt"
"sort"
"strings"
"github.com/google/go-github/v24/github"
)
// QueryOpenedIssues queries opened issues on specified term (fromto)
func QueryOpenedIssues(c *Client, fromto *FromTo) (map[string]int, error) {
name := Username(c)
page := 1
pulls := make(map[string]int)
from, to := fromto.QueryStr()
for {
result, resp, err := c.Search.Issues(
context.Background(),
fmt.Sprintf("type:issue author:%s created:%s..%s", name, from, to),
&github.SearchOptions{
ListOptions: github.ListOptions{
PerPage: 100,
Page: page,
}})
if err != nil {
panic(err)
}
page = resp.NextPage
for _, v := range result.Issues {
ss := strings.Split(*v.RepositoryURL, "/")
repo := strings.Join(ss[len(ss)-2:], "/")
pulls[repo]++
}
if resp.NextPage == 0 {
break
}
}
return pulls, nil
}
// ShowOpenedIssues shows opened issues
func ShowOpenedIssues(pulls map[string]int) {
keys := make([]string, len(pulls))
index := 0
for k := range pulls {
keys[index] = k
index++
}
sort.Strings(keys)
total := 0
for _, v := range keys {
total += pulls[v]
}
fmt.Printf("Opened %d issues in %d repositories\n", total, len(pulls))
for _, v := range keys {
fmt.Printf("%d\t%s\n", pulls[v], v)
}
}