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"
|
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"
|
2018-09-21 19:23:46 +03:00
|
|
|
)
|
|
|
|
|
2018-09-24 16:25:15 +03:00
|
|
|
func init() {
|
|
|
|
core.Register(&Github{})
|
|
|
|
}
|
|
|
|
|
2018-09-21 19:23:46 +03:00
|
|
|
type Github struct{}
|
|
|
|
|
2018-09-24 16:25:15 +03:00
|
|
|
func (*Github) Target() string {
|
2019-06-22 00:25:23 +03:00
|
|
|
return target
|
2018-09-21 19:23:46 +03:00
|
|
|
}
|
|
|
|
|
2018-10-06 12:55:16 +03:00
|
|
|
func (*Github) NewImporter() core.Importer {
|
2018-09-21 19:23:46 +03:00
|
|
|
return &githubImporter{}
|
|
|
|
}
|
|
|
|
|
2018-10-06 12:55:16 +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-05-04 18:38:03 +03:00
|
|
|
func buildClient(token string) *githubv4.Client {
|
2018-09-24 20:22:32 +03:00
|
|
|
src := oauth2.StaticTokenSource(
|
2019-05-04 18:38:03 +03:00
|
|
|
&oauth2.Token{AccessToken: token},
|
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
|
|
|
}
|