about summary refs log tree commit diff
path: root/org-clubhouse.el
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-02-18T19·58-0500
committerGriffin Smith <root@gws.fyi>2019-02-18T19·58-0500
commit205e4fcde6e7c94e071760e6190444517c2455b6 (patch)
tree224737a3d5a5e93652dfb1e0a80587333746661c /org-clubhouse.el
parentd338b4d3043808e0b0d98885c9bb8b80f4bca57e (diff)
feat: Allow pulling stories by story ID
Adds org-clubhouse-headline-from-story, which allows passing a single
story ID to make a headline from.

Fixes #14
Diffstat (limited to 'org-clubhouse.el')
-rw-r--r--org-clubhouse.el55
1 files changed, 34 insertions, 21 deletions
diff --git a/org-clubhouse.el b/org-clubhouse.el
index 34f51d24b929..125be37faef4 100644
--- a/org-clubhouse.el
+++ b/org-clubhouse.el
@@ -799,6 +799,37 @@ contents of a drawer inside the element called DESCRIPTION, if any."
      :description new-description)
     (message "Successfully updated story description")))
 
+
+(defun org-clubhouse--story-to-headline-text (story)
+  (let ((story-id (alist-get 'id story)))
+    (format
+     "%s %s %s
+:PROPERTIES:
+:clubhouse-id: %s
+:END:
+:DESCRIPTION:
+%s
+:END:
+"
+     (make-string level ?*)
+     (org-clubhouse-workflow-state-id-to-todo-keyword
+      (alist-get 'workflow_state_id story))
+     (alist-get 'name story)
+     (org-make-link-string
+      (org-clubhouse-link-to-story story-id)
+      (number-to-string story-id))
+     (alist-get 'description story))))
+
+(defun org-clubhouse-headline-from-story (level story-id)
+  "Create a single `org-mode' headline at LEVEL based on the given clubhouse STORY-ID."
+
+  (interactive "*nLevel: \nnStory ID: ")
+  (let* ((story (org-clubhouse-request "GET" (format "/stories/%d" story-id))))
+    (if (equal '((message . "Resource not found.")) story)
+        (message "Story ID not found: %d" story-id)
+      (save-mark-and-excursion
+        (insert (org-clubhouse--story-to-headline-text story))))))
+
 (defun org-clubhouse-headlines-from-query (level query)
   "Create `org-mode' headlines from a clubhouse query.
 
@@ -816,27 +847,8 @@ resulting stories at headline level LEVEL."
     (if (null sprint-story-list)
         (message "Query returned no stories: %s" query)
       (save-mark-and-excursion
-        (insert
-         (mapconcat (lambda (story)
-                      (format
-                       "%s %s %s
-:PROPERTIES:
-:clubhouse-id: %s
-:END:
-:DESCRIPTION:
-%s
-:END:
-"
-                       (make-string level ?*)
-                       (org-clubhouse-workflow-state-id-to-todo-keyword
-                        (alist-get 'workflow_state_id story))
-                       (alist-get 'name story)
-                       (let ((story-id (alist-get 'id story)))
-                         (org-make-link-string
-                          (org-clubhouse-link-to-story story-id)
-                          (number-to-string story-id)))
-                       (alist-get 'description story)))
-                    (reject-archived sprint-story-list) "\n"))))))
+        (insert (mapconcat #'org-clubhouse--story-to-headline-text
+                           (reject-archived sprint-story-list) "\n"))))))
 
 (define-minor-mode org-clubhouse-mode
   "If enabled, updates to the todo keywords on org headlines will update the
@@ -850,4 +862,5 @@ linked ticket in Clubhouse."
             t))
 
 (provide 'org-clubhouse)
+
 ;;; org-clubhouse.el ends here