Commits

Hugh Giddens committed 829ac35

Added code for enriching search results.

  • Participants
  • Parent commits b61c370

Comments (0)

Files changed (1)

       (format "summary ~ \"%s\" OR description ~ \"%s\" OR comment ~ \"%s\""
               quote-escaped quote-escaped quote-escaped))))
 
+(defun jira-issue-needs-enrichment-p (issue)
+  (null (assoc 'fields issue)))
+
+(defun jira-enrich-issue (issue instance outstanding callback callback-args)
+  ;; We should be using the self link.
+  (jira-get instance
+            (jira-issue-endpoint (cdr (assoc 'key issue)))
+            (lambda (issue-details issue outstanding callback callback-args)
+              (unwind-protect
+                  (let* ((required-fields '(status priority assignee summary))
+                         (field-list (loop for field in (cdr (assoc 'fields issue-details))
+                                           when (memq (car field) required-fields)
+                                           collect field)))
+                    (setf (nthcdr (length issue) issue) `((fields . ,field-list))))
+                (when (zerop (decf (car outstanding)))
+                  (apply callback callback-args))))
+            (list issue outstanding callback callback-args)))
+
+(defun jira-enrich-issues (issue-list instance callback &optional callback-args)
+  ;; 4.4 search results are just '((key . "key-1") (self
+  ;; . "https://url/to/key-1")); Here we enrich them so they match the
+  ;; cool search results we get from 5. There doesn't seem to be a way
+  ;; to coerce 4.4 to do this for us with the expand parameter.
+  (let ((outstanding (list (length issue-list))))
+    (if (not (find-if 'jira-issue-needs-enrichment-p issue-list))
+        (apply callback callback-args)
+      (dolist (issue issue-list)
+        (jira-enrich-issue issue instance outstanding callback callback-args)))))
+
 ;;; XXX We seem to be getting back much richer documents here than the documentation says we should be
 (defun jira-search-issues (instance text)
   "Displays a list of issues matching TEXT on INSTANCE.
               (jira-search-endpoint)
               `((jql . ,(or (jira-jql-text-search text) ""))
                 (maxResults . 20))
-              (lambda (search-results text max-results target-buffer)
-                (with-jira-buffer target-buffer
-                  (insert (propertize "Issue search\n" 'face 'jira-title-face) "\n")
-                  (unless (zerop (length text))
-                    (insert (propertize "Query text\n" 'face 'jira-heading-face) text "\n\n"))
-                  (jira-display-issues (cdr (assoc 'issues search-results)))))
-              (list text 20 (current-buffer))))
+              (lambda (search-results instance text target-buffer)
+                (let ((issue-list (cdr (assoc 'issues search-results))))
+                  (jira-enrich-issues issue-list
+                                      instance
+                                      (lambda (issue-list text target-buffer)
+                                        (with-jira-buffer target-buffer
+                                          (insert (propertize "Issue search\n" 'face 'jira-title-face) "\n")
+                                          (unless (zerop (length text))
+                                            (insert (propertize "Query text\n" 'face 'jira-heading-face) text "\n\n"))
+                                          (jira-display-issues issue-list)))
+                                      (list issue-list text target-buffer))))
+              (list instance text (current-buffer))))
   (jira-revert-buffer))
 
 (defun jira-search-project-issues (instance project text)