about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTatu Lahtela <tatu.lahtela@vincit.fi>2020-03-30T08·18+0300
committerGriffin Smith <glittershark@users.noreply.github.com>2020-03-30T12·15-0400
commit0bca01b8775a7240f4e71dba062a72a427d71324 (patch)
treef0e60345546282d13d95b5240ab184b72ef1bdaa
parent750f0fd82d01a72ecb451888769e1813f13a2e0c (diff)
Iterations support
Ability retrieve headlines from a single iteration
-rw-r--r--org-clubhouse.el39
1 files changed, 39 insertions, 0 deletions
diff --git a/org-clubhouse.el b/org-clubhouse.el
index 3be5b4098395..b3f7a7f75a9f 100644
--- a/org-clubhouse.el
+++ b/org-clubhouse.el
@@ -490,6 +490,10 @@ If set to nil, will never create stories with labels")
                        (equal org-clubhouse-username))))
        (alist-get 'id)))
 
+(defcache org-clubhouse-iterations
+  "Returns iterations as (project-id . name)"
+  (org-clubhouse-fetch-as-id-name-pairs "iterations"))
+
 (defun org-clubhouse-stories-in-project (project-id)
   "Return the stories in the given PROJECT-ID as org headlines."
   (let ((resp-json (org-clubhouse-request "GET" (format "/projects/%d/stories" project-id))))
@@ -1043,6 +1047,41 @@ which labels to set."
         (append nil)
         reject-archived)))
 
+(defun org-clubhouse-prompt-for-iteration (cb)
+  "Prompt for iteration and call CB with that iteration"
+  (ivy-read
+   "Select an interation: "
+   (-map #'cdr (org-clubhouse-iterations))
+   :require-match t
+   :history 'org-clubhouse-iteration-history
+   :action (lambda (selected)
+             (let ((iteration-id
+                    (find-match-in-alist selected (org-clubhouse-iterations))))
+               (funcall cb iteration-id)))))
+
+(defun org-clubhouse--get-iteration (iteration-id)
+  (-> (org-clubhouse-request "GET" (format "iterations/%d/stories" iteration-id))
+      (append nil)))
+
+(defun org-clubhouse-headlines-from-iteration (level)
+  "Create `org-mode' headlines from a clubhouse iteration.
+
+Create `org-mode' headlines from all the resulting stories at headline level LEVEL."
+  (interactive "*nLevel: ")
+  (org-clubhouse-prompt-for-iteration
+   (lambda (iteration-id) 
+     (let ((story-list (org-clubhouse--get-iteration iteration-id)))
+       (if (null story-list)
+           (message "Iteration id returned no stories: %d" iteration-id)
+         (let ((text (mapconcat (apply-partially
+                                 #'org-clubhouse--story-to-headline-text
+                                 level)
+                                (reject-archived story-list) "\n")))
+               (save-mark-and-excursion
+                 (insert text)
+                 (org-align-all-tags))
+             text))))))
+
 (defun org-clubhouse-headlines-from-query (level query)
   "Create `org-mode' headlines from a clubhouse query.