about summary refs log tree commit diff
path: root/org-clubhouse.el
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-02-22T21·29-0500
committerGriffin Smith <root@gws.fyi>2019-02-22T21·29-0500
commitf657a4c7fa88413c6121062ec38256353e4ad422 (patch)
tree39c92c446cf36e8acb8ded6321d3540f9ec66567 /org-clubhouse.el
parentdfc2335edb652a1be938643aea2b7f1bb20b930a (diff)
feat: Update task list item statuses
Add a clause to org-clubhouse-update-status to update task headline
statuses in addition to story statuses
Diffstat (limited to 'org-clubhouse.el')
-rw-r--r--org-clubhouse.el64
1 files changed, 50 insertions, 14 deletions
diff --git a/org-clubhouse.el b/org-clubhouse.el
index 8163fa3d342a..c3f69f32e835 100644
--- a/org-clubhouse.el
+++ b/org-clubhouse.el
@@ -197,8 +197,8 @@ not be prompted")
     (when (equal 'headline (car current-elt))
       (cadr current-elt))))
 
-(defun org-element-extract-clubhouse-id (elt)
-  (when-let* ((clubhouse-id-link (plist-get elt :CLUBHOUSE-ID)))
+(defun org-element-extract-clubhouse-id (elt &optional property)
+  (when-let* ((clubhouse-id-link (plist-get elt (or property :CLUBHOUSE-ID))))
     (cond
      ((string-match
        (rx "[[" (one-or-more anything) "]"
@@ -741,6 +741,21 @@ allows manually passing a clubhouse ID and list of org-element plists to write"
       (org-todo "TODO"))))
 
 ;;;
+;;; Task Updates
+;;;
+
+(cl-defun org-clubhouse-update-task-internal
+    (story-id task-id &rest attrs)
+  (cl-assert (and (integerp story-id)
+                  (integerp task-id)
+                  (listp attrs)))
+  (org-clubhouse-request
+   "PUT"
+   (format "stories/%d" story-id)
+   :data
+   (json-encode attrs)))
+
+;;;
 ;;; Story updates
 ;;;
 
@@ -777,18 +792,39 @@ Update the status of the Clubhouse story linked to the current element with the
 entry in `org-clubhouse-state-alist' corresponding to the todo-keyword of the
 element."
   (interactive)
-  (when-let* ((clubhouse-id (org-element-clubhouse-id)))
-    (let* ((elt (org-element-find-headline))
-           (todo-keyword (-> elt (plist-get :todo-keyword) (substring-no-properties))))
-      (when-let* ((clubhouse-workflow-state
-                  (alist-get-equal todo-keyword org-clubhouse-state-alist))
-                 (workflow-state-id
-                  (alist-get-equal clubhouse-workflow-state (org-clubhouse-workflow-states))))
-        (org-clubhouse-update-story-internal
-         clubhouse-id
-         :workflow_state_id workflow-state-id)
-        (message "Successfully updated clubhouse status to \"%s\""
-                 clubhouse-workflow-state)))))
+  (let* ((elt (org-element-find-headline))
+         (todo-keyword (-> elt
+                           (plist-get :todo-keyword)
+                           (substring-no-properties)))
+
+         (clubhouse-id (org-element-extract-clubhouse-id elt))
+         (task-id (plist-get elt :CLUBHOUSE-TASK-ID)))
+    (cond
+     (clubhouse-id
+      (let* ((todo-keyword (-> elt
+                               (plist-get :todo-keyword)
+                               (substring-no-properties))))
+        (when-let* ((clubhouse-workflow-state
+                     (alist-get-equal todo-keyword org-clubhouse-state-alist))
+                    (workflow-state-id
+                     (alist-get-equal clubhouse-workflow-state
+                                      (org-clubhouse-workflow-states))))
+          (org-clubhouse-update-story-internal
+           clubhouse-id
+           :workflow_state_id workflow-state-id)
+          (message "Successfully updated clubhouse status to \"%s\""
+                   clubhouse-workflow-state))))
+     (task-id
+      (let ((story-id (org-element-extract-clubhouse-id
+                       elt
+                       :CLUBHOUSE-STORY-ID))
+            (done? (member todo-keyword org-done-keywords)))
+        (org-clubhouse-update-task-internal
+         story-id
+         (string-to-number task-id)
+         :done done?)
+        (message "Successfully marked clubhouse task status as %s"
+                 (if done? "complete" "incomplete")))))))
 
 (defun org-clubhouse-update-description ()
   "Update the description of the Clubhouse story linked to the current element.