about summary refs log tree commit diff
path: root/org-clubhouse.el
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-03-06T18·55-0500
committerGriffin Smith <root@gws.fyi>2019-03-06T18·55-0500
commit9b9254123942126e4f2ce40253e60f6847f96c5b (patch)
tree940d6f3efdeb98cfc47fa96397039dca9f06ee84 /org-clubhouse.el
parent3ee1fcc71c85fe7270b70c14b89078cef212b524 (diff)
feat: Allow updating story assignee
Add a configuration parameter,
`org-clubhouse-claim-story-on-status-update`, which allows updating the
assignee of stories on status update, either always or for specific todo
keywords
Diffstat (limited to 'org-clubhouse.el')
-rw-r--r--org-clubhouse.el64
1 files changed, 56 insertions, 8 deletions
diff --git a/org-clubhouse.el b/org-clubhouse.el
index 808ce7fd5f..ee741b434d 100644
--- a/org-clubhouse.el
+++ b/org-clubhouse.el
@@ -47,10 +47,17 @@
 ;;;
 
 (defvar org-clubhouse-auth-token nil
-  "Authorization token for the Clubhouse API")
+  "Authorization token for the Clubhouse API.")
+
+(defvar org-clubhouse-username nil
+  "Username for the current Clubhouse user.
+
+Unfortunately, the Clubhouse API doesn't seem to provide this via the API given
+an API token, so we need to configure this for
+`org-clubhouse-claim-story-on-status-updates' to work")
 
 (defvar org-clubhouse-team-name nil
-  "Team name to use in links to Clubhouse
+  "Team name to use in links to Clubhouse.
 ie https://app.clubhouse.io/<TEAM_NAME>/stories")
 
 (defvar org-clubhouse-project-ids nil
@@ -91,7 +98,19 @@ not be prompted")
     ("prompt"  . "**Prompt each time (do not set a default story type)**")))
 
 (defvar org-clubhouse-default-state "Proposed"
-  "Default state to create all new stories in")
+  "Default state to create all new stories in.")
+
+(defvar org-clubhouse-claim-story-on-status-update 't
+  "Controls the assignee behavior of stories on status update.
+
+If set to 't, will mark the current user as the owner of any clubhouse
+stories on any update to the status.
+
+If set to nil, will never automatically update the assignee of clubhouse
+stories.
+
+If set to a list of todo-state's, will mark the current user as the owner of
+clubhouse stories whenever updating the status to one of those todo states.")
 
 ;;;
 ;;; Utilities
@@ -410,6 +429,19 @@ not be prompted")
                       'name
                       'id)))
 
+(defcache org-clubhouse-whoami
+  "Returns the ID of the logged in user"
+  (->> (org-clubhouse-request
+        "GET"
+        "/members")
+       ->list
+       (find-if (lambda (m)
+                  (->> m
+                       (alist-get 'profile)
+                       (alist-get 'mention_name)
+                       (equal org-clubhouse-username))))
+       (alist-get 'id)))
+
 (defun org-clubhouse-stories-in-project (project-id)
   "Return the stories in the given PROJECT-ID as org headlines."
   (let ((resp-json (org-clubhouse-request "GET" (format "/projects/%d/stories" project-id))))
@@ -809,11 +841,27 @@ element."
                     (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 ((update-assignee?
+                 (if (or (eq 't org-clubhouse-claim-story-on-status-update)
+                         (member todo-keyword
+                                 org-clubhouse-claim-story-on-status-update))
+                     (if org-clubhouse-username
+                         't
+                       (warn "Not claiming story since `org-clubhouse-username'
+                       is not set")
+                       nil))))
+
+            (org-clubhouse-update-story-internal
+             clubhouse-id
+             :workflow_state_id workflow-state-id
+             :owner_ids (when update-assignee?
+                          (list (org-clubhouse-whoami))))
+            (message
+             (if update-assignee?
+                 "Successfully claimed story and updated clubhouse status to \"%s\""
+               "Successfully updated clubhouse status to \"%s\"")
+             clubhouse-workflow-state)))))
+
      (task-id
       (let ((story-id (org-element-extract-clubhouse-id
                        elt