about summary refs log tree commit diff
path: root/org-clubhouse.el
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-03-14T20·21-0400
committerGriffin Smith <root@gws.fyi>2019-03-14T20·21-0400
commitd1f8a1e41f899add01b2f6800ba9e2621f51080f (patch)
tree8404e7aff58161158b5e8f8616a5df5f5f0b8b76 /org-clubhouse.el
parent453e6dc36c65215f8227d395ee7529735577fe29 (diff)
feat: Implement org-clubhouse-sync-status
Implement a command that pulls down the status from clubhouse for a list
of story headlines, and updates the todo keyword accordingly
Diffstat (limited to 'org-clubhouse.el')
-rw-r--r--org-clubhouse.el24
1 files changed, 24 insertions, 0 deletions
diff --git a/org-clubhouse.el b/org-clubhouse.el
index 7bab1ee2d068..568a476e0a5a 100644
--- a/org-clubhouse.el
+++ b/org-clubhouse.el
@@ -987,6 +987,30 @@ resulting stories at headline level LEVEL."
        (message "Successfully claimed story"))
     (warn "Can't claim story if `org-clubhouse-username' is unset")))
 
+(defun org-clubhouse-sync-status (&optional beg end)
+  "Pull the status(es) for the story(ies) in region and update the todo state.
+
+Uses `org-clubhouse-state-alist'. Operates over stories from BEG to END"
+  (interactive
+   (when (use-region-p)
+     (list (region-beginning) (region-end))))
+  (let ((elts (-filter (lambda (e) (plist-get e :CLUBHOUSE-ID))
+                       (org-clubhouse-collect-headlines beg end))))
+    (save-mark-and-excursion
+      (dolist (e elts)
+        (goto-char (plist-get e :begin))
+        (let* ((clubhouse-id (org-element-extract-clubhouse-id e))
+               (story (org-clubhouse-get-story clubhouse-id))
+               (workflow-state-id (alist-get 'workflow_state_id story))
+               (todo-keyword (org-clubhouse-workflow-state-id-to-todo-keyword
+                              workflow-state-id)))
+          (let ((org-after-todo-state-change-hook
+                 (remove 'org-clubhouse-update-status
+                         org-after-todo-state-change-hook)))
+            (org-todo todo-keyword)))))
+    (message "Successfully synchronized status of %d stories from Clubhouse"
+             (length elts))))
+
 (comment
  (org-clubhouse--search-stories "train")
  (org-clubhouse-request "GET" "search/stories" :params `((query ,"")))