forked from gitploy-io/gitploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.go
More file actions
55 lines (44 loc) · 1017 Bytes
/
github.go
File metadata and controls
55 lines (44 loc) · 1017 Bytes
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 github
import (
"context"
"github.com/google/go-github/v32/github"
graphql "github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
)
type (
Github struct {
baseURL string
}
GithubConfig struct {
BaseURL string
}
)
func NewGithub(c *GithubConfig) *Github {
return &Github{
baseURL: c.BaseURL,
}
}
func (g *Github) Client(c context.Context, token string) *github.Client {
tc := oauth2.NewClient(c, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
))
var client *github.Client
if g.baseURL != "" {
client, _ = github.NewEnterpriseClient(g.baseURL, g.baseURL, tc)
} else {
client = github.NewClient(tc)
}
return client
}
func (g *Github) GraphQLClient(c context.Context, token string) *graphql.Client {
tc := oauth2.NewClient(c, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
))
var client *graphql.Client
if g.baseURL != "" {
client = graphql.NewEnterpriseClient(g.baseURL, tc)
} else {
client = graphql.NewClient(tc)
}
return client
}