aboutsummaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
Diffstat (limited to 'bridge')
-rw-r--r--bridge/core/bridge.go4
-rw-r--r--bridge/gitlab/config.go26
-rw-r--r--bridge/gitlab/export.go3
-rw-r--r--bridge/gitlab/gitlab.go12
-rw-r--r--bridge/gitlab/import.go6
-rw-r--r--bridge/gitlab/iterator.go8
6 files changed, 24 insertions, 35 deletions
diff --git a/bridge/core/bridge.go b/bridge/core/bridge.go
index abb57ed7..645dac3d 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 dbbd1bd9..15172871 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 0aafeef9..85b5ee2e 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 743ab172..a52ea2c1 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 67d9aa25..b19587a9 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 8b7177f6..320f2a50 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
-}