-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.go
More file actions
66 lines (56 loc) · 1.51 KB
/
Copy pathgithub.go
File metadata and controls
66 lines (56 loc) · 1.51 KB
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
package main
import (
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
type tokenSource struct {
token *oauth2.Token
}
func (t *tokenSource) Token() (*oauth2.Token, error) {
return t.token, nil
}
// Issues and pull requests of GitHub.
type Issues struct {
client *github.Client
}
// NewIssues to generate issues object.
func NewIssues(token string) *Issues {
source := &tokenSource{
&oauth2.Token{AccessToken: token},
}
client := oauth2.NewClient(oauth2.NoContext, source)
return &Issues{
client: github.NewClient(client),
}
}
// ListByOptions to get issues and pull requests from GitHub.
func (issues Issues) ListByOptions(options *Options) ([]github.Issue, *github.Response, error) {
if len(options.repository) > 0 || options.CurrentRepo {
return issues.listByRepo(options)
}
listOptions := &github.IssueListOptions{
Filter: options.Filter(),
State: options.State,
Sort: options.Sort,
ListOptions: github.ListOptions{
Page: options.Page,
PerPage: options.PerPage,
},
}
return issues.client.Issues.List(!options.Self, listOptions)
}
func (issues Issues) listByRepo(options *Options) ([]github.Issue, *github.Response, error) {
owner, repo, err := options.getOwnerAndRepo()
if err != nil {
return nil, nil, err
}
listOptions := &github.IssueListByRepoOptions{
State: options.State,
Sort: options.Sort,
ListOptions: github.ListOptions{
Page: options.Page,
PerPage: options.PerPage,
},
}
return issues.client.Issues.ListByRepo(owner, repo, listOptions)
}