/
client.go
56 lines (42 loc) · 1004 Bytes
/
client.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
package githubclient
import (
"context"
"github.com/giantswarm/microerror"
"github.com/google/go-github/v61/github"
"github.com/sirupsen/logrus"
"golang.org/x/oauth2"
)
type Config struct {
DryRun bool
Logger *logrus.Logger
AccessToken string
}
type Client struct {
dryRun bool
logger *logrus.Logger
accessToken string
}
func New(config Config) (*Client, error) {
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
if config.AccessToken == "" {
return nil, microerror.Maskf(invalidConfigError, "%T.AccessToken must not be empty", config)
}
c := &Client{
dryRun: config.DryRun,
logger: config.Logger,
accessToken: config.AccessToken,
}
return c, nil
}
func (c *Client) getUnderlyingClient(ctx context.Context) *github.Client {
ts := oauth2.StaticTokenSource(
&oauth2.Token{
AccessToken: c.accessToken,
},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
return client
}