forked from jstemmer/rehook
/
issue_api.go
82 lines (64 loc) · 1.6 KB
/
issue_api.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
80
81
82
package main
import (
"log"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
const paginage = false
type IssueAPI struct {
Client *github.Client
}
func NewIssueAPI() *IssueAPI {
token, err := queryToken("Github_Token", "vampirewalk")
if err != nil {
client := github.NewClient(nil)
return &IssueAPI{Client: client}
}
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
client := github.NewClient(tc)
return &IssueAPI{Client: client}
}
func (i IssueAPI) ListIssues(user, repo string) ([]github.Issue, error) {
opts := &github.IssueListByRepoOptions{
Sort: "created",
}
allIssues := make([]github.Issue, 0)
for {
log.Println("querying github for issues: page", opts.ListOptions.Page)
iss, resp, err := i.Client.Issues.ListByRepo(user, repo, opts)
if err != nil {
return nil, err
}
allIssues = append(allIssues, iss...)
/*for _, i := range iss {
fmt.Println(i)
}*/
if !paginage || resp.NextPage == 0 {
break
}
opts.ListOptions.Page = resp.NextPage
}
return allIssues, nil
}
func (i IssueAPI) ListIssueEvents(user, repo string, issueNum int) ([]github.IssueEvent, error) {
opts := &github.ListOptions{Page: 0}
allEvents := make([]github.IssueEvent, 0)
for {
events, resp, err := i.Client.Issues.ListIssueEvents(user, repo, issueNum, opts)
if err != nil {
return nil, err
}
allEvents = append(allEvents, events...)
/*for _, e := range events {
fmt.Println(e)
}*/
if !paginage || resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return allEvents, nil
}