github.go

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