aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bridge/jira/client.go7
-rw-r--r--bridge/jira/config.go3
-rw-r--r--bridge/jira/export.go14
-rw-r--r--bridge/jira/import.go33
4 files changed, 37 insertions, 20 deletions
diff --git a/bridge/jira/client.go b/bridge/jira/client.go
index bfc30039..486c1a87 100644
--- a/bridge/jira/client.go
+++ b/bridge/jira/client.go
@@ -1363,6 +1363,9 @@ func (client *Client) DoTransition(
`{"transition":{"id":"%s"}, "resolution": {"name": "Done"}}`,
transitionID)
request, err := http.NewRequest("POST", url, bytes.NewBuffer(buffer.Bytes()))
+ if err != nil {
+ return responseTime, err
+ }
if client.ctx != nil {
ctx, cancel := context.WithTimeout(*client.ctx, defaultTimeout)
@@ -1378,9 +1381,9 @@ func (client *Client) DoTransition(
defer response.Body.Close()
if response.StatusCode != http.StatusNoContent {
- err := fmt.Errorf(
+ err := errors.Wrap(errTransitionNotAllowed, fmt.Sprintf(
"HTTP response %d, query was %s", response.StatusCode,
- request.URL.String())
+ request.URL.String()))
return responseTime, err
}
diff --git a/bridge/jira/config.go b/bridge/jira/config.go
index e33b8f28..62b7364e 100644
--- a/bridge/jira/config.go
+++ b/bridge/jira/config.go
@@ -105,6 +105,9 @@ func (g *Jira) Configure(
fmt.Printf("Attempting to login with credentials...\n")
client := NewClient(serverURL, nil)
err = client.RefreshTokenRaw(jsonData)
+ if err != nil {
+ return nil, err
+ }
// verify access to the project with credentials
_, err = client.GetProject(project)
diff --git a/bridge/jira/export.go b/bridge/jira/export.go
index 6472b212..fc0d4ad3 100644
--- a/bridge/jira/export.go
+++ b/bridge/jira/export.go
@@ -15,8 +15,6 @@ import (
"github.com/MichaelMure/git-bug/entity"
)
-var errDuplicateMatch = errors.New("Ambiguous match")
-
// jiraExporter implement the Exporter interface
type jiraExporter struct {
conf core.Configuration
@@ -199,7 +197,10 @@ func (self *jiraExporter) exportBug(
fields := make(map[string]interface{})
defaultFields, hasConf := self.conf[keyCreateDefaults]
if hasConf {
- json.Unmarshal([]byte(defaultFields), &fields)
+ err = json.Unmarshal([]byte(defaultFields), &fields)
+ if err != nil {
+ panic("Invalid JSON in config")
+ }
} else {
// If there is no configuration provided, at the very least the
// "issueType" field is always required. 10001 is "story" which I'm
@@ -278,9 +279,8 @@ func (self *jiraExporter) exportBug(
var id string
var exportTime time.Time
- switch op.(type) {
+ switch opr := op.(type) {
case *bug.AddCommentOperation:
- opr := op.(*bug.AddCommentOperation)
comment, err := client.AddComment(bugJiraID, opr.Message)
if err != nil {
err := errors.Wrap(err, "adding comment")
@@ -294,7 +294,6 @@ func (self *jiraExporter) exportBug(
self.cachedOperationIDs[op.Id()] = id
case *bug.EditCommentOperation:
- opr := op.(*bug.EditCommentOperation)
if opr.Target == createOp.Id() {
// An EditCommentOpreation with the Target set to the create operation
// encodes a modification to the long-description/summary.
@@ -332,7 +331,6 @@ func (self *jiraExporter) exportBug(
}
case *bug.SetStatusOperation:
- opr := op.(*bug.SetStatusOperation)
jiraStatus, hasStatus := statusMap[opr.Status.String()]
if hasStatus {
exportTime, err = UpdateIssueStatus(client, bugJiraID, jiraStatus)
@@ -355,7 +353,6 @@ func (self *jiraExporter) exportBug(
}
case *bug.SetTitleOperation:
- opr := op.(*bug.SetTitleOperation)
exportTime, err = client.UpdateIssueTitle(bugJiraID, opr.Title)
if err != nil {
err := errors.Wrap(err, "editing title")
@@ -368,7 +365,6 @@ func (self *jiraExporter) exportBug(
id = bugJiraID
case *bug.LabelChangeOperation:
- opr := op.(*bug.LabelChangeOperation)
exportTime, err = client.UpdateLabels(
bugJiraID, opr.Added, opr.Removed)
if err != nil {
diff --git a/bridge/jira/import.go b/bridge/jira/import.go
index 6f8aea1d..3fcac921 100644
--- a/bridge/jira/import.go
+++ b/bridge/jira/import.go
@@ -89,7 +89,10 @@ func (self *jiraImporter) ImportAll(
for commentIter =
client.IterComments(issue.ID, defaultPageSize); commentIter.HasNext(); {
comment := commentIter.Next()
- self.ensureComment(repo, bug, *comment)
+ err := self.ensureComment(repo, bug, *comment)
+ if err != nil {
+ out <- core.NewImportError(err, "")
+ }
}
if commentIter.HasError() {
out <- core.NewImportError(commentIter.Err, "")
@@ -123,10 +126,13 @@ func (self *jiraImporter) ImportAll(
}
}
if opIdx < len(snapshot.Operations) {
- self.ensureChange(
+ err = self.ensureChange(
repo, bug, *changelogEntry, snapshot.Operations[opIdx])
} else {
- self.ensureChange(repo, bug, *changelogEntry, nil)
+ err = self.ensureChange(repo, bug, *changelogEntry, nil)
+ }
+ if err != nil {
+ out <- core.NewImportError(err, "")
}
}
@@ -290,8 +296,8 @@ func (self *jiraImporter) ensureComment(
// timestamp. Note that this must be consistent with the exporter during
// export of an EditCommentOperation
derivedID := getTimeDerivedID(item.ID, item.Updated)
- targetOpID, err = b.ResolveOperationWithMetadata(
- keyJiraID, item.ID)
+ _, err = b.ResolveOperationWithMetadata(
+ keyJiraID, derivedID)
if err == nil {
self.out <- core.NewImportNothing("", "update already imported")
} else if err != cache.ErrNoMatchingOp {
@@ -341,7 +347,7 @@ func labelSetsMatch(jiraSet []string, gitbugSet []bug.Label) bool {
}
sort.Strings(jiraSet)
- gitbugStrSet := make([]string, len(gitbugSet), len(gitbugSet))
+ gitbugStrSet := make([]string, len(gitbugSet))
for idx, label := range gitbugSet {
gitbugStrSet[idx] = label.String()
}
@@ -420,9 +426,12 @@ func (self *jiraImporter) ensureChange(
case "status":
opr, isRightType := potentialOp.(*bug.SetStatusOperation)
if isRightType && statusMap[opr.Status.String()] == item.ToString {
- b.SetMetadata(opr.Id(), map[string]string{
+ _, err := b.SetMetadata(opr.Id(), map[string]string{
keyJiraOperationID: entry.ID,
})
+ if err != nil {
+ panic("Can't set metadata")
+ }
self.out <- core.NewImportNothing("", "matched export")
return nil
}
@@ -432,9 +441,12 @@ func (self *jiraImporter) ensureChange(
// text, but it's the title
opr, isRightType := potentialOp.(*bug.SetTitleOperation)
if isRightType && opr.Title == item.ToString {
- b.SetMetadata(opr.Id(), map[string]string{
+ _, err := b.SetMetadata(opr.Id(), map[string]string{
keyJiraOperationID: entry.ID,
})
+ if err != nil {
+ panic("Can't set metadata")
+ }
self.out <- core.NewImportNothing("", "matched export")
return nil
}
@@ -446,9 +458,12 @@ func (self *jiraImporter) ensureChange(
if isRightType &&
opr.Target == b.Snapshot().Operations[0].Id() &&
opr.Message == item.ToString {
- b.SetMetadata(opr.Id(), map[string]string{
+ _, err := b.SetMetadata(opr.Id(), map[string]string{
keyJiraOperationID: entry.ID,
})
+ if err != nil {
+ panic("Can't set metadata")
+ }
self.out <- core.NewImportNothing("", "matched export")
return nil
}