diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-24 14:36:04 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-24 14:36:04 -0500 |
| commit | 049661b4c2f9047b2bf40868a6f327a4eae7075c (patch) | |
| tree | 28c4e9b86d5fea5e6a0f84fe4b651e4a005cee2a | |
| parent | dcaf2061e08feb6ca3d957950d91c292cef99b68 (diff) | |
| download | pearl-049661b4c2f9047b2bf40868a6f327a4eae7075c.tar.gz pearl-049661b4c2f9047b2bf40868a6f327a4eae7075c.zip | |
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.
| -rw-r--r-- | pearl.el | 89 |
1 files changed, 42 insertions, 47 deletions
@@ -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) |
