aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/jira/jira.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-15 16:01:15 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-15 16:01:15 +0100
commit5c230cb81e399f12cc7a1c1688b73f549b12a5f0 (patch)
treed8795111b390d98274a644cc88dd64c7d24e598b /bridge/jira/jira.go
parent0bb9ed9b0e6a53fd668be0c60127af78ddd061b5 (diff)
downloadgit-bug-5c230cb81e399f12cc7a1c1688b73f549b12a5f0.tar.gz
jira: rework to use the credential system + adapt to refactors
Diffstat (limited to 'bridge/jira/jira.go')
-rw-r--r--bridge/jira/jira.go59
1 files changed, 47 insertions, 12 deletions
diff --git a/bridge/jira/jira.go b/bridge/jira/jira.go
index 43a11c05..0ba27df3 100644
--- a/bridge/jira/jira.go
+++ b/bridge/jira/jira.go
@@ -2,27 +2,36 @@
package jira
import (
+ "context"
+ "fmt"
"sort"
"time"
"github.com/MichaelMure/git-bug/bridge/core"
+ "github.com/MichaelMure/git-bug/bridge/core/auth"
+ "github.com/MichaelMure/git-bug/input"
)
const (
target = "jira"
- metaKeyJiraLogin = "jira-login"
-
- keyServer = "server"
- keyProject = "project"
- keyCredentialsType = "credentials-type"
- keyCredentialsFile = "credentials-file"
- keyUsername = "username"
- keyPassword = "password"
- keyIDMap = "bug-id-map"
- keyIDRevMap = "bug-id-revmap"
- keyCreateDefaults = "create-issue-defaults"
- keyCreateGitBug = "create-issue-gitbug-id"
+ metaKeyJiraId = "jira-id"
+ metaKeyJiraOperationId = "jira-derived-id"
+ metaKeyJiraKey = "jira-key"
+ metaKeyJiraUser = "jira-user"
+ metaKeyJiraProject = "jira-project"
+ metaKeyJiraExportTime = "jira-export-time"
+ metaKeyJiraLogin = "jira-login"
+
+ confKeyBaseUrl = "base-url"
+ confKeyProject = "project"
+ confKeyCredentialType = "credentials-type" // "SESSION" or "TOKEN"
+ confKeyIDMap = "bug-id-map"
+ confKeyIDRevMap = "bug-id-revmap"
+ // the issue type when exporting a new bug. Default is Story (10001)
+ confKeyCreateDefaults = "create-issue-defaults"
+ // if set, the bridge fill this JIRA field with the `git-bug` id when exporting
+ confKeyCreateGitBug = "create-issue-gitbug-id"
defaultTimeout = 60 * time.Second
)
@@ -51,6 +60,32 @@ func (*Jira) NewExporter() core.Exporter {
return &jiraExporter{}
}
+func buildClient(ctx context.Context, baseURL string, credType string, cred auth.Credential) (*Client, error) {
+ client := NewClient(ctx, baseURL)
+
+ var login, password string
+
+ switch cred := cred.(type) {
+ case *auth.LoginPassword:
+ login = cred.Login
+ password = cred.Password
+ case *auth.Login:
+ login = cred.Login
+ p, err := input.PromptPassword(fmt.Sprintf("Password for %s", login), "password", input.Required)
+ if err != nil {
+ return nil, err
+ }
+ password = p
+ }
+
+ err := client.Login(credType, login, password)
+ if err != nil {
+ return nil, err
+ }
+
+ return client, nil
+}
+
// stringInSlice returns true if needle is found in haystack
func stringInSlice(needle string, haystack []string) bool {
for _, match := range haystack {