about summary refs log tree commit diff
path: root/org-clubhouse.el
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-02-18T17·25-0500
committerGriffin Smith <root@gws.fyi>2019-02-18T17·25-0500
commitd338b4d3043808e0b0d98885c9bb8b80f4bca57e (patch)
tree0ab7c3f0fc633ddbe684e1a2465b1a4603d2982d /org-clubhouse.el
parent5682f4bb573c204c40688e932f1d7e7296213831 (diff)
feat: Use workflow state for todo-keyword
Base the todo-keyword of a created story on its workflow-state in
clubhouse, rather than just hardcoding it to TODO

Fixes #11
Diffstat (limited to 'org-clubhouse.el')
-rw-r--r--org-clubhouse.el20
1 files changed, 18 insertions, 2 deletions
diff --git a/org-clubhouse.el b/org-clubhouse.el
index 50388b3dad..34f51d24b9 100644
--- a/org-clubhouse.el
+++ b/org-clubhouse.el
@@ -120,6 +120,10 @@ not be prompted")
        (-find (lambda (pair) (equal key (car pair))))
        (cdr)))
 
+(defun invert-alist (alist)
+  "Invert the keys and values of ALIST."
+  (-map (lambda (cell) (cons (cdr cell) (car cell))) alist))
+
 (comment
 
  (alist->plist
@@ -427,6 +431,17 @@ not be prompted")
                            (id . :id)
                            (status . :status)))))))
 
+(defun org-clubhouse-workflow-state-id-to-todo-keyword (workflow-state-id)
+  "Convert the named clubhouse WORKFLOW-STATE-ID to an org todo keyword."
+  (let* ((state-name (alist-get-equal
+                      workflow-state-id
+                      (invert-alist (org-clubhouse-workflow-states))))
+         (inv-state-name-alist
+          (-map (lambda (cell) (cons (cdr cell) (car cell)))
+                org-clubhouse-state-alist)))
+    (or (alist-get-equal state-name inv-state-name-alist)
+        (s-upcase state-name))))
+
 ;;;
 ;;; Prompting
 ;;;
@@ -804,7 +819,7 @@ resulting stories at headline level LEVEL."
         (insert
          (mapconcat (lambda (story)
                       (format
-                       "%s TODO %s
+                       "%s %s %s
 :PROPERTIES:
 :clubhouse-id: %s
 :END:
@@ -813,6 +828,8 @@ resulting stories at headline level LEVEL."
 :END:
 "
                        (make-string level ?*)
+                       (org-clubhouse-workflow-state-id-to-todo-keyword
+                        (alist-get 'workflow_state_id story))
                        (alist-get 'name story)
                        (let ((story-id (alist-get 'id story)))
                          (org-make-link-string
@@ -832,6 +849,5 @@ linked ticket in Clubhouse."
             nil
             t))
 
-
 (provide 'org-clubhouse)
 ;;; org-clubhouse.el ends here