From 049661b4c2f9047b2bf40868a6f327a4eae7075c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 24 May 2026 14:36:04 -0500 Subject: refactor: share the push-and-report tail of the field setters set-priority, set-state, set-assignee, and set-labels each repeated the same tail: push the issueUpdate field, and on success update the heading or drawer at the marker, message, and surface the buffer; on failure, message. I pulled that into pearl--push-issue-field, which takes the fields alist, a success thunk (the per-field buffer update), and the two messages. Each command keeps its own completion source, guards, and id resolution. No behavior change; 353 tests green. --- pearl.el | 89 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/pearl.el b/pearl.el index ce56cf7..5ce5811 100644 --- a/pearl.el +++ b/pearl.el @@ -2425,6 +2425,23 @@ locally so #D is accepted regardless of the user's `org-priority' settings." (_ (org-priority 'remove)))))) ;;;###autoload +(defun pearl--push-issue-field (issue-id marker fields on-success success-message fail-message) + "Push FIELDS (an `issueUpdate' input alist) for ISSUE-ID. +On success, run the ON-SUCCESS thunk at MARKER, report SUCCESS-MESSAGE, and +surface the buffer; on failure report FAIL-MESSAGE. The shared push-and-report +tail of the field-setter commands (priority/state/assignee/labels)." + (pearl--update-issue-async + issue-id fields + (lambda (result) + (if (plist-get result :success) + (progn + (save-excursion + (goto-char marker) + (funcall on-success)) + (message "%s" success-message) + (pearl--surface-buffer (marker-buffer marker))) + (message "%s" fail-message))))) + (defun pearl-set-priority (priority-name) "Set the priority of the Linear issue at point to PRIORITY-NAME. Interactively, completes over None/Urgent/High/Medium/Low. Pushes the numeric @@ -2441,17 +2458,11 @@ anywhere inside an issue subtree." (user-error "Not on a Linear issue heading")) (unless priority-num (user-error "Unknown priority: %s" priority-name)) - (pearl--update-issue-async - issue-id `(("priority" . ,priority-num)) - (lambda (result) - (if (plist-get result :success) - (progn - (save-excursion - (goto-char marker) - (pearl--set-priority-cookie priority-num)) - (message "Set %s priority to %s" issue-id priority-name) - (pearl--surface-buffer (marker-buffer marker))) - (message "Failed to set priority for %s" issue-id))))))) + (pearl--push-issue-field + issue-id marker `(("priority" . ,priority-num)) + (lambda () (pearl--set-priority-cookie priority-num)) + (format "Set %s priority to %s" issue-id priority-name) + (format "Failed to set priority for %s" issue-id))))) (defun pearl--set-heading-state (state-name state-id) "Update the heading at point to STATE-NAME / STATE-ID. @@ -2494,17 +2505,11 @@ success. Works from anywhere inside an issue subtree." (user-error "Not on a Linear issue heading")) (unless state-id (user-error "No workflow state named %s in this team" state-name)) - (pearl--update-issue-async - issue-id `(("stateId" . ,state-id)) - (lambda (result) - (if (plist-get result :success) - (progn - (save-excursion - (goto-char marker) - (pearl--set-heading-state state-name state-id)) - (message "Set %s state to %s" issue-id state-name) - (pearl--surface-buffer (marker-buffer marker))) - (message "Failed to set state for %s" issue-id))))))) + (pearl--push-issue-field + issue-id marker `(("stateId" . ,state-id)) + (lambda () (pearl--set-heading-state state-name state-id)) + (format "Set %s state to %s" issue-id state-name) + (format "Failed to set state for %s" issue-id))))) (defun pearl--team-collection-names (kind team-id) "Return the display labels of the KIND collection for TEAM-ID, for completion." @@ -2535,18 +2540,13 @@ anywhere inside an issue subtree." (user-error "Not on a Linear issue heading")) (unless assignee-id (user-error "No team member matching %s" assignee-name)) - (pearl--update-issue-async - issue-id `(("assigneeId" . ,assignee-id)) - (lambda (result) - (if (plist-get result :success) - (progn - (save-excursion - (goto-char marker) - (org-entry-put nil "LINEAR-ASSIGNEE-NAME" assignee-name) - (org-entry-put nil "LINEAR-ASSIGNEE-ID" assignee-id)) - (message "Set %s assignee to %s" issue-id assignee-name) - (pearl--surface-buffer (marker-buffer marker))) - (message "Failed to set assignee for %s" issue-id))))))) + (pearl--push-issue-field + issue-id marker `(("assigneeId" . ,assignee-id)) + (lambda () + (org-entry-put nil "LINEAR-ASSIGNEE-NAME" assignee-name) + (org-entry-put nil "LINEAR-ASSIGNEE-ID" assignee-id)) + (format "Set %s assignee to %s" issue-id assignee-name) + (format "Failed to set assignee for %s" issue-id))))) ;;;###autoload (defun pearl-set-labels (label-names) @@ -2575,19 +2575,14 @@ issue subtree." label-names))) (unless issue-id (user-error "Not on a Linear issue heading")) - (pearl--update-issue-async - issue-id `(("labelIds" . ,label-ids)) - (lambda (result) - (if (plist-get result :success) - (progn - (save-excursion - (goto-char marker) - (org-entry-put nil "LINEAR-LABELS" - (format "[%s]" (mapconcat #'identity label-names ", ")))) - (message "Set %s labels to %s" issue-id - (if label-names (mapconcat #'identity label-names ", ") "none")) - (pearl--surface-buffer (marker-buffer marker))) - (message "Failed to set labels for %s" issue-id))))))) + (pearl--push-issue-field + issue-id marker `(("labelIds" . ,label-ids)) + (lambda () + (org-entry-put nil "LINEAR-LABELS" + (format "[%s]" (mapconcat #'identity label-names ", ")))) + (format "Set %s labels to %s" issue-id + (if label-names (mapconcat #'identity label-names ", ") "none")) + (format "Failed to set labels for %s" issue-id))))) ;;; User-facing Commands (Async) -- cgit v1.2.3