Commits

Hugh Giddens committed effb6bc

Work on fixing the interactive portion of update-issue-status.

  • Participants
  • Parent commits 6795bae

Comments (0)

Files changed (1)

               (jira-show-issue instance key))
             (list instance key)))
 
+(defun jira-get-issue-transitions (instance issue-key)
+  "Finds the transitions that can be performed on ISSUE-KEY in INSTANCE.
+
+This function performs a synchronous request."
+  (jira-get instance
+            (jira-issue-transitions-endpoint issue-key)
+            (lambda (result)
+              (let ((transitions (assoc 'transitions result)))
+                (if transitions
+                    (cdr transitions)
+                  result)))
+            nil 'synchronous))
+
 ;; TODO this and functions like this should accept transition names and transition ids
 (defun jira-update-issue-status (instance key transition-name &optional resolution-name)
   "Changes the status of the issue with key KEY via the transition named by TRANSITION-NAME.
                       (transition-completer
                        (completion-table-dynamic
                         (lambda (prefix)
-                          (jira-get instance
-                                    (jira-issue-transitions-endpoint key)
-                                    (lambda (result)
-                                      (loop for transition in (cdr (assoc 'transitions result))
-                                            as name = (cdr (assoc 'name transition))
-                                            when (and (<= (length prefix) (length name))
-                                                      (string= prefix (subseq name 0 (length prefix))))
-                                            collect name))
-                                    nil 'synchronous))))
+                          (loop for transition in (jira-get-issue-transitions instance key)
+                                as name = (jira-item-name transition)
+                                when (and (<= (length prefix) (length name))
+                                          (string= prefix (subseq name 0 (length prefix))))
+                                collect name))))
                       (transition-name (jira-required-read "Transition" transition-completer))
                       (resolution
                        (jira-get instance
                                  (jira-issue-endpoint key)
-                                 (lambda (result)
-                                   (cdr (assoc 'resolution (cdr (assoc 'fields result)))))
+                                 (lambda (issue)
+                                   (jira-issue-resolution issue))
                                  nil 'synchronous))
                       (resolution-completer
                        (completion-table-dynamic
                         (lambda (prefix)
-                          (jira-get instance
-                                    (jira-resolutions-endpoint)
-                                    (lambda (result)
-                                      (loop for resolution in result as name = (cdr (assoc 'name resolution))
-                                            when (and (<= (length prefix) (length name))
-                                                      (string= prefix (subseq name 0 (length prefix))))
-                                            collect name))
-                                    nil 'synchronous))))
+                          (condition-case e
+                              (jira-get instance
+                                        (jira-resolutions-endpoint)
+                                        (lambda (result)
+                                          (loop for resolution in result as name = (cdr (assoc 'name resolution))
+                                                when (and (<= (length prefix) (length name))
+                                                          (string= prefix (subseq name 0 (length prefix))))
+                                                collect name))
+                                        nil 'synchronous)
+                            (error
+                             (if (equal (cdr e) '(http 405))
+                                 ;; We're talking to 4.4 and the endpoint doesn't exist.
+                                 nil
+                               (signal e)))))))
                       (resolution-name
                        (if (and (null resolution)
                                 ;; TODO Presumably there's a better way to do this but the REST