feat: Implement org-clubhouse-link

Implement an interactive function for linking existing org headlines
with existing clubhouse stories.
This commit is contained in:
Griffin Smith 2019-02-18 16:26:49 -05:00
parent 205e4fcde6
commit 910a6af627

View file

@ -799,6 +799,9 @@ contents of a drawer inside the element called DESCRIPTION, if any."
:description new-description) :description new-description)
(message "Successfully updated story description"))) (message "Successfully updated story description")))
;;;
;;; Creating headlines from existing stories
;;;
(defun org-clubhouse--story-to-headline-text (story) (defun org-clubhouse--story-to-headline-text (story)
(let ((story-id (alist-get 'id 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 (save-mark-and-excursion
(insert (org-clubhouse--story-to-headline-text story)))))) (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) (defun org-clubhouse-headlines-from-query (level query)
"Create `org-mode' headlines from a clubhouse 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." resulting stories at headline level LEVEL."
(interactive (interactive
"*nLevel: \nMQuery: ") "*nLevel: \nMQuery: ")
(let* ((sprint-stories (let* ((story-list (org-clubhouse--search-stories query)))
(org-clubhouse-request
"GET"
"search/stories"
:params `((query ,query))))
(sprint-story-list (-> sprint-stories cdr car cdr (append nil)
reject-archived)))
(if (null sprint-story-list) (if (null sprint-story-list)
(message "Query returned no stories: %s" query) (message "Query returned no stories: %s" query)
(save-mark-and-excursion (save-mark-and-excursion
(insert (mapconcat #'org-clubhouse--story-to-headline-text (insert (mapconcat #'org-clubhouse--story-to-headline-text
(reject-archived sprint-story-list) "\n")))))) (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 (define-minor-mode org-clubhouse-mode
"If enabled, updates to the todo keywords on org headlines will update the "If enabled, updates to the todo keywords on org headlines will update the
linked ticket in Clubhouse." linked ticket in Clubhouse."