From d1f8a1e41f899add01b2f6800ba9e2621f51080f Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Thu, 14 Mar 2019 16:21:29 -0400 Subject: feat: Implement org-clubhouse-sync-status Implement a command that pulls down the status from clubhouse for a list of story headlines, and updates the todo keyword accordingly --- org-clubhouse.el | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'org-clubhouse.el') diff --git a/org-clubhouse.el b/org-clubhouse.el index 7bab1ee2d068..568a476e0a5a 100644 --- a/org-clubhouse.el +++ b/org-clubhouse.el @@ -987,6 +987,30 @@ resulting stories at headline level LEVEL." (message "Successfully claimed story")) (warn "Can't claim story if `org-clubhouse-username' is unset"))) +(defun org-clubhouse-sync-status (&optional beg end) + "Pull the status(es) for the story(ies) in region and update the todo state. + +Uses `org-clubhouse-state-alist'. Operates over stories from BEG to END" + (interactive + (when (use-region-p) + (list (region-beginning) (region-end)))) + (let ((elts (-filter (lambda (e) (plist-get e :CLUBHOUSE-ID)) + (org-clubhouse-collect-headlines beg end)))) + (save-mark-and-excursion + (dolist (e elts) + (goto-char (plist-get e :begin)) + (let* ((clubhouse-id (org-element-extract-clubhouse-id e)) + (story (org-clubhouse-get-story clubhouse-id)) + (workflow-state-id (alist-get 'workflow_state_id story)) + (todo-keyword (org-clubhouse-workflow-state-id-to-todo-keyword + workflow-state-id))) + (let ((org-after-todo-state-change-hook + (remove 'org-clubhouse-update-status + org-after-todo-state-change-hook))) + (org-todo todo-keyword))))) + (message "Successfully synchronized status of %d stories from Clubhouse" + (length elts)))) + (comment (org-clubhouse--search-stories "train") (org-clubhouse-request "GET" "search/stories" :params `((query ,""))) -- cgit 1.4.1