aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/gitlab
diff options
context:
space:
mode:
authorAmine Hilaly <hilalyamine@gmail.com>2019-07-23 17:29:53 +0200
committerAmine Hilaly <hilalyamine@gmail.com>2019-07-23 17:29:53 +0200
commit0329bfdf440ec48c5c5c5c6dbe2ca8519d99b706 (patch)
treefbff33e372cdd8ca5008a61d9993785baa17b9f4 /bridge/gitlab
parentd098a96407c55281c28bfdea9925df587b4d4400 (diff)
downloadgit-bug-0329bfdf440ec48c5c5c5c6dbe2ca8519d99b706.tar.gz
bridge/gitlab: change validateProjectURL signature
bridge/gitlab: code cleanup
Diffstat (limited to 'bridge/gitlab')
-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
5 files changed, 21 insertions, 34 deletions
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
-}