about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-03-08T15·42-0500
committerGriffin Smith <root@gws.fyi>2019-03-08T15·42-0500
commit453e6dc36c65215f8227d395ee7529735577fe29 (patch)
tree20f92113708ef3a322cb01604758c923c1f2c142
parent9b9254123942126e4f2ce40253e60f6847f96c5b (diff)
feat: Add org-clubhouse-claim
Add a standalone org-clubhouse-claim function for claiming the current
story without making any other updates
-rw-r--r--README.org10
-rw-r--r--org-clubhouse.el61
2 files changed, 46 insertions, 25 deletions
diff --git a/README.org b/README.org
index f312b02a74a0..423dfc21ae87 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* Org-Clubhouse
+#+TITLE: Org-Clubhouse
 
 Simple, unopinionated integration between Emacs's [[https://orgmode.org/][org-mode]] and the [[https://clubhouse.io/][Clubhouse]] issue tracker
 
@@ -34,11 +34,12 @@ Simple, unopinionated integration between Emacs's [[https://orgmode.org/][org-mo
 
 * Setup
 
-Once installed, you'll need to set two global config vars:
+Once installed, you'll need to set three global config vars:
 
 #+BEGIN_SRC emacs-lisp
 (setq org-clubhouse-auth-token "<your-token>"
-      org-clubhouse-team-name "<your-team-name>")
+      org-clubhouse-team-name "<your-team-name>"
+      org-clubhouse-username "<your-username>")
 #+END_SRC
 
 You can generate a new personal API token by going to the "API Tokens" tab on
@@ -79,6 +80,9 @@ org-clubhouse provides the following commands:
   Create org-mode headlines from a clubhouse query at the cursor's current
   position, prompting for the headline indentation level and clubhouse query
   text
+- ~org-clubhouse-claim~
+  Adds the user configured in ~org-clubhouse-username~ as the owner of the
+  clubhouse story associated with the headline at point
 
 * Configuration
 
diff --git a/org-clubhouse.el b/org-clubhouse.el
index ee741b434d97..7bab1ee2d068 100644
--- a/org-clubhouse.el
+++ b/org-clubhouse.el
@@ -791,22 +791,6 @@ allows manually passing a clubhouse ID and list of org-element plists to write"
 ;;; Story updates
 ;;;
 
-(defun org-clubhouse-update-story-title ()
-  "Update the title of the Clubhouse story linked to the current headline.
-
-Update the title of the story linked to the current headline with the text of
-the headline."
-  (interactive)
-
-  (when-let (clubhouse-id (org-element-clubhouse-id))
-    (let* ((elt (org-element-find-headline))
-           (title (plist-get elt :title)))
-    (org-clubhouse-update-story-internal
-     clubhouse-id
-     :name title)
-    (message "Successfully updated story title to \"%s\""
-             title))))
-
 (cl-defun org-clubhouse-update-story-internal
     (story-id &rest attrs)
   (cl-assert (and (integerp story-id)
@@ -817,6 +801,29 @@ the headline."
    :data
    (json-encode attrs)))
 
+(cl-defun org-clubhouse-update-story-at-point (&rest attrs)
+  (when-let* ((clubhouse-id (org-element-clubhouse-id)))
+    (apply
+     #'org-clubhouse-update-story-internal
+     (cons clubhouse-id attrs))
+    t))
+
+(defun org-clubhouse-update-story-title ()
+  "Update the title of the Clubhouse story linked to the current headline.
+
+Update the title of the story linked to the current headline with the text of
+the headline."
+  (interactive)
+
+  (let* ((elt (org-element-find-headline))
+         (title (plist-get elt :title)))
+    (and
+     (org-clubhouse-update-story-at-point
+      clubhouse-id
+      :name title)
+     (message "Successfully updated story title to \"%s\""
+              title))))
+
 (defun org-clubhouse-update-status ()
   "Update the status of the Clubhouse story linked to the current element.
 
@@ -880,12 +887,12 @@ element."
 Update the status of the Clubhouse story linked to the current element with the
 contents of a drawer inside the element called DESCRIPTION, if any."
   (interactive)
-  (when-let* ((clubhouse-id (org-element-clubhouse-id))
-              (new-description (org-clubhouse-find-description-drawer)))
-    (org-clubhouse-update-story-internal
-     clubhouse-id
-     :description new-description)
-    (message "Successfully updated story description")))
+  (when-let* ((new-description (org-clubhouse-find-description-drawer)))
+    (and
+     (org-clubhouse-update-story-at-point
+      clubhouse-id
+      :description new-description)
+     (message "Successfully updated story description"))))
 
 ;;;
 ;;; Creating headlines from existing stories
@@ -970,6 +977,16 @@ resulting stories at headline level LEVEL."
       (org-clubhouse-workflow-state-id-to-todo-keyword
        (alist-get 'workflow_state_id story))))))
 
+(defun org-clubhouse-claim ()
+  "Assign the clubhouse story associated with the headline at point to yourself."
+  (interactive)
+  (if org-clubhouse-username
+      (and
+       (org-clubhouse-update-story-at-point
+        :owner_ids (list (org-clubhouse-whoami)))
+       (message "Successfully claimed story"))
+    (warn "Can't claim story if `org-clubhouse-username' is unset")))
+
 (comment
  (org-clubhouse--search-stories "train")
  (org-clubhouse-request "GET" "search/stories" :params `((query ,"")))