aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/github/github.go
blob: a02d94607bb22ca5746cf9e294ed124f5c68a72d (plain) (blame)
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 github contains the Github bridge implementation
package github

import (
	"context"
	"time"

	"github.com/shurcooL/githubv4"
	"golang.org/x/oauth2"

	"github.com/MichaelMure/git-bug/bridge/core"
	"github.com/MichaelMure/git-bug/bridge/core/auth"
)

const (
	target = "github"

	metaKeyGithubId    = "github-id"
	metaKeyGithubUrl   = "github-url"
	metaKeyGithubLogin = "github-login"

	confKeyOwner   = "owner"
	confKeyProject = "project"

	githubV3Url    = "https://api.github.com"
	defaultTimeout = 60 * time.Second
)

var _ core.BridgeImpl = &Github{}

type Github struct{}

func (Github) Target() string {
	return target
}

func (g *Github) LoginMetaKey() string {
	return metaKeyGithubLogin
}

func (Github) NewImporter() core.Importer {
	return &githubImporter{}
}

func (Github) NewExporter() core.Exporter {
	return &githubExporter{}
}

func buildClient(token *auth.Token) *githubv4.Client {
	src := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: token.Value},
	)
	httpClient := oauth2.NewClient(context.TODO(), src)

	return githubv4.NewClient(httpClient)
}