From d338b4d3043808e0b0d98885c9bb8b80f4bca57e Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 18 Feb 2019 12:25:01 -0500 Subject: [PATCH] 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 --- org-clubhouse.el | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/org-clubhouse.el b/org-clubhouse.el index 50388b3da..34f51d24b 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