git-bug/bridge/gitlab/gitlab.go

62 lines
1.2 KiB
Go
Raw Normal View History

2019-07-09 23:56:38 +03:00
package gitlab
import (
"net/http"
"time"
2019-07-09 23:56:38 +03:00
"github.com/xanzy/go-gitlab"
"github.com/MichaelMure/git-bug/bridge/core"
"github.com/MichaelMure/git-bug/bridge/core/auth"
2019-07-09 23:56:38 +03:00
)
const (
target = "gitlab"
metaKeyGitlabId = "gitlab-id"
metaKeyGitlabUrl = "gitlab-url"
metaKeyGitlabLogin = "gitlab-login"
metaKeyGitlabProject = "gitlab-project-id"
metaKeyGitlabBaseUrl = "gitlab-base-url"
confKeyProjectID = "project-id"
confKeyGitlabBaseUrl = "base-url"
defaultBaseURL = "https://gitlab.com/"
defaultTimeout = 60 * time.Second
)
2020-02-05 00:05:34 +03:00
var _ core.BridgeImpl = &Gitlab{}
2019-07-09 23:56:38 +03:00
type Gitlab struct{}
func (Gitlab) Target() string {
2019-07-09 23:56:38 +03:00
return target
}
2020-02-05 00:05:34 +03:00
func (g *Gitlab) LoginMetaKey() string {
return metaKeyGitlabLogin
}
func (Gitlab) NewImporter() core.Importer {
2019-07-09 23:56:38 +03:00
return &gitlabImporter{}
}
func (Gitlab) NewExporter() core.Exporter {
return &gitlabExporter{}
2019-07-09 23:56:38 +03:00
}
func buildClient(baseURL string, token *auth.Token) (*gitlab.Client, error) {
httpClient := &http.Client{
Timeout: defaultTimeout,
}
gitlabClient := gitlab.NewClient(httpClient, token.Value)
err := gitlabClient.SetBaseURL(baseURL)
if err != nil {
return nil, err
}
return gitlabClient, nil
}