-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.go
68 lines (54 loc) · 1.62 KB
/
github.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
package main
import (
"context"
"github.com/google/go-github/v32/github"
"golang.org/x/oauth2"
)
type GithubApi struct {
// owner and repo name
owner, repo string
client *github.Client
}
// NewGithub create
func NewGithub(owner, repo, token string) *GithubApi {
gha := &GithubApi{
owner: owner,
repo: repo,
}
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(ctx, ts)
// create client
gha.client = github.NewClient(tc)
return gha
}
// AddLabelsToIssue by PR number
func (gha *GithubApi) AddLabelsToIssue(number int, labels []string) ([]*github.Label, *github.Response, error) {
return gha.client.Issues.AddLabelsToIssue(context.Background(), gha.owner, gha.repo, number, labels)
}
// GetPullRequest by PR number
func (gha *GithubApi) GetPullRequest(prNumber int) (*github.PullRequest, *github.Response, error) {
return gha.client.PullRequests.Get(context.Background(), gha.owner, gha.repo, prNumber)
}
// ListPullRequestFiles by PR number
func (gha *GithubApi) ListPullRequestFiles(prNumber int, options *github.ListOptions) ([]*github.CommitFile, *github.Response, error) {
return gha.client.PullRequests.ListFiles(context.Background(), gha.owner, gha.repo, prNumber, options)
}
// Repositories service get
func (gha *GithubApi) Repositories() *github.RepositoriesService {
return gha.client.Repositories
}
// Repo name
func (gha *GithubApi) Repo() string {
return gha.repo
}
// Owner name
func (gha *GithubApi) Owner() string {
return gha.owner
}
// Client get github client
func (gha *GithubApi) Client() *github.Client {
return gha.client
}