diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go index abb57ed74c965d3fb9720c05bee63b650481ebf8..645dac3d2b502d66334bfaa449a1ae4e8e722c5b 100644 --- a/bridge/core/bridge.go +++ b/bridge/core/bridge.go @@ -19,7 +19,9 @@ var ErrImportNotSupported = errors.New("import is not supported") var ErrExportNotSupported = errors.New("export is not supported") const ( - KeyTarget = "target" + KeyTarget = "target" + KeyOrigin = "origin" + bridgeConfigKeyPrefix = "git-bug.bridge" ) diff --git a/bridge/gitlab/config.go b/bridge/gitlab/config.go index dbbd1bd9339391c3a707b17e4c499c9bd34c2f02..1517287173430153f3d90d7ad1e679f38d8d94a6 100644 --- a/bridge/gitlab/config.go +++ b/bridge/gitlab/config.go @@ -61,26 +61,22 @@ func (*Gitlab) Configure(repo repository.RepoCommon, params core.BridgeParams) ( } } - var ok bool // validate project url and get its ID - ok, id, err := validateProjectURL(url, token) + id, err := validateProjectURL(url, token) if err != nil { return nil, errors.Wrap(err, "project validation") } - if !ok { - return nil, fmt.Errorf("invalid project id or incorrect token scope") - } conf[keyProjectID] = strconv.Itoa(id) conf[keyToken] = token - conf[keyTarget] = target + conf[core.KeyTarget] = target return conf, nil } func (*Gitlab) ValidateConfig(conf core.Configuration) error { - if v, ok := conf[keyTarget]; !ok { - return fmt.Errorf("missing %s key", keyTarget) + if v, ok := conf[core.KeyTarget]; !ok { + return fmt.Errorf("missing %s key", core.KeyTarget) } else if v != target { return fmt.Errorf("unexpected target name: %v", v) } @@ -147,7 +143,7 @@ func promptURL(remotes map[string]string) (string, error) { line = strings.TrimRight(line, "\n") index, err := strconv.Atoi(line) - if err != nil || (index < 0 && index > len(validRemotes)) { + if err != nil || index < 0 || index > len(validRemotes) { fmt.Println("invalid input") continue } @@ -205,18 +201,18 @@ func getValidGitlabRemoteURLs(remotes map[string]string) []string { return urls } -func validateProjectURL(url, token string) (bool, int, error) { - client := buildClient(token) - +func validateProjectURL(url, token string) (int, error) { projectPath, err := getProjectPath(url) if err != nil { - return false, 0, err + return 0, err } + client := buildClient(token) + project, _, err := client.Projects.GetProject(projectPath, &gitlab.GetProjectOptions{}) if err != nil { - return false, 0, err + return 0, err } - return true, project.ID, nil + return project.ID, nil } diff --git a/bridge/gitlab/export.go b/bridge/gitlab/export.go index 0aafeef92f0d481fef04e20ebf2af9d467e76675..85b5ee2ed24bbe35fb1a2a629796d98d7bf711d4 100644 --- a/bridge/gitlab/export.go +++ b/bridge/gitlab/export.go @@ -14,8 +14,7 @@ var ( ) // gitlabExporter implement the Exporter interface -type gitlabExporter struct { -} +type gitlabExporter struct{} // Init . func (ge *gitlabExporter) Init(conf core.Configuration) error { diff --git a/bridge/gitlab/gitlab.go b/bridge/gitlab/gitlab.go index 743ab1728de114c25f114f431844f76e8538c1d3..a52ea2c13eaf438b431bdaa3ebbb5fd21d14837f 100644 --- a/bridge/gitlab/gitlab.go +++ b/bridge/gitlab/gitlab.go @@ -10,14 +10,14 @@ import ( ) const ( - target = "gitlab" - keyProjectID = "project-id" + target = "gitlab" + keyGitlabId = "gitlab-id" keyGitlabUrl = "gitlab-url" keyGitlabLogin = "gitlab-login" - keyToken = "token" - keyTarget = "target" - keyOrigin = "origin" + + keyProjectID = "project-id" + keyToken = "token" defaultTimeout = 60 * time.Second ) @@ -37,7 +37,7 @@ func (*Gitlab) NewImporter() core.Importer { } func (*Gitlab) NewExporter() core.Exporter { - return &gitlabExporter{} + return nil } func buildClient(token string) *gitlab.Client { diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go index 67d9aa2568adba5f7eaa53babde0079db77ee81d..b19587a9d4d7520da77483cc2b62fb40ee39ef20 100644 --- a/bridge/gitlab/import.go +++ b/bridge/gitlab/import.go @@ -108,9 +108,9 @@ func (gi *gitlabImporter) ensureIssue(repo *cache.RepoCache, issue *gitlab.Issue cleanText, nil, map[string]string{ - keyOrigin: target, - keyGitlabId: parseID(issue.ID), - keyGitlabUrl: issue.WebURL, + core.KeyOrigin: target, + keyGitlabId: parseID(issue.ID), + keyGitlabUrl: issue.WebURL, }, ) diff --git a/bridge/gitlab/iterator.go b/bridge/gitlab/iterator.go index 8b7177f62af531845fcd5ad9cab6fd32304a4793..320f2a50623fc070f50da42d096a2f44a1589893 100644 --- a/bridge/gitlab/iterator.go +++ b/bridge/gitlab/iterator.go @@ -243,11 +243,3 @@ func (i *iterator) NextLabelEvent() bool { func (i *iterator) LabelEventValue() *gitlab.LabelEvent { return i.labelEvent.cache[i.labelEvent.index] } - -func min(a, b int) int { - if a > b { - return b - } - - return a -}