1// Package github contains the Github bridge implementation
2package github
3
4import (
5 "context"
6 "time"
7
8 "golang.org/x/oauth2"
9
10 "github.com/MichaelMure/git-bug/bridge/core"
11 "github.com/MichaelMure/git-bug/bridge/core/auth"
12)
13
14const (
15 target = "github"
16
17 metaKeyGithubId = "github-id"
18 metaKeyGithubUrl = "github-url"
19 metaKeyGithubLogin = "github-login"
20
21 confKeyOwner = "owner"
22 confKeyProject = "project"
23 confKeyDefaultLogin = "default-login"
24
25 githubV3Url = "https://api.github.com"
26 defaultTimeout = 60 * time.Second
27)
28
29var _ core.BridgeImpl = &Github{}
30
31type Github struct{}
32
33func (*Github) Target() string {
34 return target
35}
36
37func (g *Github) LoginMetaKey() string {
38 return metaKeyGithubLogin
39}
40
41func (*Github) NewImporter() core.Importer {
42 return &githubImporter{}
43}
44
45func (*Github) NewExporter() core.Exporter {
46 return &githubExporter{}
47}
48
49func buildClient(token *auth.Token) *rateLimitHandlerClient {
50 src := oauth2.StaticTokenSource(
51 &oauth2.Token{AccessToken: token.Value},
52 )
53 httpClient := oauth2.NewClient(context.TODO(), src)
54 return newRateLimitHandlerClient(httpClient)
55}