git-bug/bridge/github/github.go

58 lines
1.1 KiB
Go
Raw Normal View History

2018-10-01 22:47:12 +03:00
// Package github contains the Github bridge implementation
package github
import (
2018-09-24 20:22:32 +03:00
"context"
2020-02-05 00:05:34 +03:00
"time"
2018-09-24 16:25:15 +03:00
2018-09-24 20:22:32 +03:00
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/bridge/core/auth"
)
2020-02-05 00:05:34 +03:00
const (
target = "github"
metaKeyGithubId = "github-id"
metaKeyGithubUrl = "github-url"
metaKeyGithubLogin = "github-login"
confKeyOwner = "owner"
confKeyProject = "project"
confKeyDefaultLogin = "default-login"
2020-02-05 00:05:34 +03:00
githubV3Url = "https://api.github.com"
defaultTimeout = 60 * time.Second
)
var _ core.BridgeImpl = &Github{}
type Github struct{}
2020-02-15 15:45:14 +03:00
func (*Github) Target() string {
return target
}
2020-02-05 00:05:34 +03:00
func (g *Github) LoginMetaKey() string {
return metaKeyGithubLogin
}
2020-02-15 15:45:14 +03:00
func (*Github) NewImporter() core.Importer {
return &githubImporter{}
}
2020-02-15 15:45:14 +03:00
func (*Github) NewExporter() core.Exporter {
return &githubExporter{}
}
func buildClient(token *auth.Token) *githubv4.Client {
2018-09-24 20:22:32 +03:00
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token.Value},
2018-09-24 20:22:32 +03:00
)
httpClient := oauth2.NewClient(context.TODO(), src)
2018-09-24 20:22:32 +03:00
return githubv4.NewClient(httpClient)
}