From 0bca01b8775a7240f4e71dba062a72a427d71324 Mon Sep 17 00:00:00 2001 From: Tatu Lahtela Date: Mon, 30 Mar 2020 11:18:07 +0300 Subject: Iterations support Ability retrieve headlines from a single iteration --- org-clubhouse.el | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'org-clubhouse.el') 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. -- cgit 1.4.1