2019-07-09 23:56:38 +03:00
|
|
|
package gitlab
|
|
|
|
|
|
|
|
import (
|
2019-07-19 20:39:15 +03:00
|
|
|
"net/http"
|
2019-07-19 19:56:58 +03:00
|
|
|
"time"
|
|
|
|
|
2019-07-09 23:56:38 +03:00
|
|
|
"github.com/xanzy/go-gitlab"
|
2019-07-17 23:41:42 +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"
|
2019-07-09 23:56:38 +03:00
|
|
|
)
|
|
|
|
|
2019-07-19 19:56:58 +03:00
|
|
|
const (
|
2019-07-23 18:29:53 +03:00
|
|
|
target = "gitlab"
|
|
|
|
|
2019-11-10 19:48:13 +03:00
|
|
|
metaKeyGitlabId = "gitlab-id"
|
|
|
|
metaKeyGitlabUrl = "gitlab-url"
|
|
|
|
metaKeyGitlabLogin = "gitlab-login"
|
|
|
|
metaKeyGitlabProject = "gitlab-project-id"
|
2019-12-10 22:30:29 +03:00
|
|
|
metaKeyGitlabBaseUrl = "gitlab-base-url"
|
2019-07-23 18:29:53 +03:00
|
|
|
|
2020-02-15 04:55:19 +03:00
|
|
|
confKeyProjectID = "project-id"
|
|
|
|
confKeyGitlabBaseUrl = "base-url"
|
2019-07-19 19:56:58 +03:00
|
|
|
|
2019-12-10 22:30:29 +03:00
|
|
|
defaultBaseURL = "https://gitlab.com/"
|
2019-07-19 19:56:58 +03:00
|
|
|
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{}
|
|
|
|
|
2020-02-15 04:55:19 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-02-15 04:55:19 +03:00
|
|
|
func (Gitlab) NewImporter() core.Importer {
|
2019-07-09 23:56:38 +03:00
|
|
|
return &gitlabImporter{}
|
|
|
|
}
|
|
|
|
|
2020-02-15 04:55:19 +03:00
|
|
|
func (Gitlab) NewExporter() core.Exporter {
|
2019-07-26 04:22:07 +03:00
|
|
|
return &gitlabExporter{}
|
2019-07-09 23:56:38 +03:00
|
|
|
}
|
|
|
|
|
2019-12-10 22:30:29 +03:00
|
|
|
func buildClient(baseURL string, token *auth.Token) (*gitlab.Client, error) {
|
|
|
|
httpClient := &http.Client{
|
2019-07-19 20:39:15 +03:00
|
|
|
Timeout: defaultTimeout,
|
|
|
|
}
|
2019-07-10 01:41:43 +03:00
|
|
|
|
2019-12-10 22:30:29 +03:00
|
|
|
gitlabClient := gitlab.NewClient(httpClient, token.Value)
|
|
|
|
err := gitlabClient.SetBaseURL(baseURL)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return gitlabClient, nil
|
2019-07-10 01:41:43 +03:00
|
|
|
}
|