This repository was archived by the owner on Oct 19, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathgithub.go
More file actions
55 lines (44 loc) · 2.15 KB
/
Copy pathgithub.go
File metadata and controls
55 lines (44 loc) · 2.15 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
package prdiff
import (
"context"
"github.com/google/go-github/v29/github"
"golang.org/x/oauth2"
)
// GitHubAPI represents required API calls for GitHub.
type GitHubAPI interface {
GetRepository(ctx context.Context, owner, repo string) (*github.Repository, *github.Response, error)
GetRepositoryLatestRelease(ctx context.Context, owner, repo string) (*github.RepositoryRelease, *github.Response, error)
ListPullRequests(ctx context.Context, owner, repo string, opt *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error)
CompareRepositoryCommits(ctx context.Context, owner, repo, base, head string) (*github.CommitsComparison, *github.Response, error)
}
// GitHub manages GitHub API client from google/go-github.
type GitHub struct {
client *github.Client
}
var _ GitHubAPI = (*GitHub)(nil)
// NewGitHub returns `GitHub` with OAuth access token of github.com.
func NewGitHub(ctx context.Context, accessToken string) *GitHub {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: accessToken},
)
tc := oauth2.NewClient(ctx, ts)
return &GitHub{
client: github.NewClient(tc),
}
}
// GetRepository calls `Repositories.Get`.
func (gh *GitHub) GetRepository(ctx context.Context, owner, repo string) (*github.Repository, *github.Response, error) {
return gh.client.Repositories.Get(ctx, owner, repo)
}
// GetRepositoryLatestRelease calls `Repositories.GetLatestRelease`.
func (gh *GitHub) GetRepositoryLatestRelease(ctx context.Context, owner, repo string) (*github.RepositoryRelease, *github.Response, error) {
return gh.client.Repositories.GetLatestRelease(ctx, owner, repo)
}
// ListPullRequests calls `PullRequests.List`.
func (gh *GitHub) ListPullRequests(ctx context.Context, owner, repo string, opt *github.PullRequestListOptions) ([]*github.PullRequest, *github.Response, error) {
return gh.client.PullRequests.List(ctx, owner, repo, opt)
}
// CompareRepositoryCommits calls `Repositories.CompareCommits`.
func (gh *GitHub) CompareRepositoryCommits(ctx context.Context, owner, repo, base, head string) (*github.CommitsComparison, *github.Response, error) {
return gh.client.Repositories.CompareCommits(ctx, owner, repo, base, head)
}