-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
github.go
54 lines (46 loc) · 1.87 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
package github
import (
"context"
"io"
"net/http"
"net/url"
"os"
"github.com/google/go-github/v56/github"
"golang.org/x/oauth2"
)
type (
ReleaseAsset = github.ReleaseAsset
ListOptions = github.ListOptions
RepositoryRelease = github.RepositoryRelease
RepositoriesServiceImpl = github.RepositoriesService
Repository = github.Repository
RepositoryContentGetOptions = github.RepositoryContentGetOptions
RepositoryContent = github.RepositoryContent
Response = github.Response
RepositoryTag = github.RepositoryTag
ArchiveFormat = github.ArchiveFormat
)
const Tarball = github.Tarball
func New(ctx context.Context) *RepositoriesServiceImpl {
return github.NewClient(getHTTPClientForGitHub(ctx, getGitHubToken())).Repositories
}
type RepositoriesService interface {
GetArchiveLink(ctx context.Context, owner, repo string, archiveformat github.ArchiveFormat, opts *github.RepositoryContentGetOptions, maxRedirects int) (*url.URL, *github.Response, error)
GetReleaseByTag(ctx context.Context, owner, repoName, version string) (*github.RepositoryRelease, *github.Response, error)
DownloadReleaseAsset(ctx context.Context, owner, repoName string, assetID int64, httpClient *http.Client) (io.ReadCloser, string, error)
GetContents(ctx context.Context, repoOwner, repoName, path string, opt *github.RepositoryContentGetOptions) (*github.RepositoryContent, []*github.RepositoryContent, *github.Response, error)
}
func getGitHubToken() string {
if token := os.Getenv("AQUA_GITHUB_TOKEN"); token != "" {
return token
}
return os.Getenv("GITHUB_TOKEN")
}
func getHTTPClientForGitHub(ctx context.Context, token string) *http.Client {
if token == "" {
return http.DefaultClient
}
return oauth2.NewClient(ctx, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
))
}