about summary refs log tree commit diff
path: root/org-clubhouse.el
diff options
context:
space:
mode:
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 ,"")))