about summary refs log tree commit diff
path: root/org-clubhouse.el
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-02-18T21·26-0500
committerGriffin Smith <root@gws.fyi>2019-02-18T21·26-0500
commit910a6af62700aa5ecc9b7da73ad41bcd1fb451c9 (patch)
tree7a428fb6a67ad7888a97b48704bce186c1d7900b /org-clubhouse.el
parent205e4fcde6e7c94e071760e6190444517c2455b6 (diff)
feat: Implement org-clubhouse-link
Implement an interactive function for linking existing org headlines
with existing clubhouse stories.
Diffstat (limited to 'org-clubhouse.el')
-rw-r--r--org-clubhouse.el55
1 files changed, 48 insertions, 7 deletions
diff --git a/org-clubhouse.el b/org-clubhouse.el
index 125be37faef4..f11e938f6d61 100644
--- a/org-clubhouse.el
+++ b/org-clubhouse.el
@@ -799,6 +799,9 @@ contents of a drawer inside the element called DESCRIPTION, if any."
      :description new-description)
     (message "Successfully updated story description")))
 
+;;;
+;;; Creating headlines from existing stories
+;;;
 
 (defun org-clubhouse--story-to-headline-text (story)
   (let ((story-id (alist-get 'id story)))
@@ -830,6 +833,13 @@ contents of a drawer inside the element called DESCRIPTION, if any."
       (save-mark-and-excursion
         (insert (org-clubhouse--story-to-headline-text story))))))
 
+(defun org-clubhouse--search-stories (query)
+  (unless (string= "" query)
+    (-> (org-clubhouse-request "GET" "search/stories" :params `((query ,query)))
+        cdadr
+        (append nil)
+        reject-archived)))
+
 (defun org-clubhouse-headlines-from-query (level query)
   "Create `org-mode' headlines from a clubhouse query.
 
@@ -837,19 +847,50 @@ Submits QUERY to clubhouse, and creates `org-mode' headlines from all the
 resulting stories at headline level LEVEL."
   (interactive
    "*nLevel: \nMQuery: ")
-  (let* ((sprint-stories
-          (org-clubhouse-request
-           "GET"
-           "search/stories"
-           :params `((query ,query))))
-         (sprint-story-list (-> sprint-stories cdr car cdr (append nil)
-                                reject-archived)))
+  (let* ((story-list (org-clubhouse--search-stories query)))
     (if (null sprint-story-list)
         (message "Query returned no stories: %s" query)
       (save-mark-and-excursion
         (insert (mapconcat #'org-clubhouse--story-to-headline-text
                            (reject-archived sprint-story-list) "\n"))))))
 
+(defun org-clubhouse-prompt-for-story (cb)
+  "Prompt the user for a clubhouse story, then call CB with the full story."
+  (ivy-read "Story title: "
+            (lambda (search-term)
+              (let* ((stories (org-clubhouse--search-stories
+                               (if search-term (format "\"%s\"" search-term)
+                                 ""))))
+                (-map (lambda (story)
+                        (propertize (alist-get 'name story) 'story story))
+                      stories)))
+            :dynamic-collection t
+            :history 'org-clubhouse-story-prompt
+            :action (lambda (s) (funcall cb (get-text-property 0 'story s)))
+            :require-match t))
+
+(defun org-clubhouse-link ()
+  "Link the current `org-mode' headline with an existing clubhouse story."
+  (interactive)
+  (org-clubhouse-prompt-for-story
+   (lambda (story)
+     (org-clubhouse-populate-created-story (org-element-find-headline) story)
+     (org-todo
+      (org-clubhouse-workflow-state-id-to-todo-keyword
+       (alist-get 'workflow_state_id story))))))
+
+(comment
+ (org-clubhouse--search-stories "train")
+ (org-clubhouse-request "GET" "search/stories" :params `((query ,"")))
+
+ (get-text-property
+  0 'clubhouse-id
+  (propertize "foo" 'clubhouse-id 1234))
+
+ )
+
+;;;
+
 (define-minor-mode org-clubhouse-mode
   "If enabled, updates to the todo keywords on org headlines will update the
 linked ticket in Clubhouse."