2018-10-01 22:47:12 +03:00
|
|
|
// Package github contains the Github bridge implementation
|
2018-09-21 13:54:48 +03:00
|
|
|
package github
|
|
|
|
|
2018-09-21 19:23:46 +03:00
|
|
|
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"
|
2019-05-24 22:32:13 +03:00
|
|
|
|
|
|
|
"github.com/MichaelMure/git-bug/bridge/core"
|
2019-12-08 23:15:06 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bridge/core/auth"
|
2018-09-21 19:23:46 +03:00
|
|
|
)
|
|
|
|
|
2020-02-05 00:05:34 +03:00
|
|
|
const (
|
|
|
|
target = "github"
|
|
|
|
|
|
|
|
metaKeyGithubId = "github-id"
|
|
|
|
metaKeyGithubUrl = "github-url"
|
|
|
|
metaKeyGithubLogin = "github-login"
|
|
|
|
|
2020-02-23 16:05:03 +03:00
|
|
|
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{}
|
|
|
|
|
2018-09-21 19:23:46 +03:00
|
|
|
type Github struct{}
|
|
|
|
|
2020-02-15 15:45:14 +03:00
|
|
|
func (*Github) Target() string {
|
2019-06-22 00:25:23 +03:00
|
|
|
return target
|
2018-09-21 19:23:46 +03:00
|
|
|
}
|
|
|
|
|
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 {
|
2018-09-21 19:23:46 +03:00
|
|
|
return &githubImporter{}
|
|
|
|
}
|
|
|
|
|
2020-02-15 15:45:14 +03:00
|
|
|
func (*Github) NewExporter() core.Exporter {
|
2019-06-09 00:14:59 +03:00
|
|
|
return &githubExporter{}
|
2018-09-21 19:23:46 +03:00
|
|
|
}
|
|
|
|
|
2019-12-08 23:15:06 +03:00
|
|
|
func buildClient(token *auth.Token) *githubv4.Client {
|
2018-09-24 20:22:32 +03:00
|
|
|
src := oauth2.StaticTokenSource(
|
2019-12-08 23:15:06 +03:00
|
|
|
&oauth2.Token{AccessToken: token.Value},
|
2018-09-24 20:22:32 +03:00
|
|
|
)
|
|
|
|
httpClient := oauth2.NewClient(context.TODO(), src)
|
2018-09-21 19:23:46 +03:00
|
|
|
|
2018-09-24 20:22:32 +03:00
|
|
|
return githubv4.NewClient(httpClient)
|
2018-09-21 13:54:48 +03:00
|
|
|
}
|