diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-26 20:10:42 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-26 20:10:42 -0500 |
| commit | cfc42c41426d61f53c49b1f192751bcd061e57ae (patch) | |
| tree | 0091739c4f499c5a6a849f6241139479a23f14f0 | |
| parent | 34c67ddc3b72f92033ced3f86346f3483f5ba463 (diff) | |
| download | pearl-cfc42c41426d61f53c49b1f192751bcd061e57ae.tar.gz pearl-cfc42c41426d61f53c49b1f192751bcd061e57ae.zip | |
fix(commands): run add-comment and delete from anywhere in a ticket
pearl-add-comment and pearl-delete-current-issue guarded position with the nearest-heading check, so from inside a comment subtree, or any heading without a LINEAR-ID, they errored "Not on a Linear issue heading". Both docstrings already claimed they work from anywhere in the subtree, so the behavior was just wrong.
The edit and save commands already climb to the issue via pearl--goto-issue-heading-or-error. I switched these two to the same guard, so every ticket-scoped command resolves the enclosing issue from anywhere in its subtree, including from inside a comment. The redundant LINEAR-ID re-checks are gone since the guard guarantees it. Walk-up tests added for both.
| -rw-r--r-- | pearl.el | 10 | ||||
| -rw-r--r-- | tests/test-pearl-comment-editing.el | 19 | ||||
| -rw-r--r-- | tests/test-pearl-delete.el | 14 |
3 files changed, 30 insertions, 13 deletions
@@ -2527,11 +2527,9 @@ non-interactively, is sent as-is. Works from anywhere inside an issue subtree; the new comment is the viewer's own, so it renders editable." (interactive (list nil)) (save-excursion - (pearl--goto-heading-or-error) + (pearl--goto-issue-heading-or-error) (let ((issue-id (org-entry-get nil "LINEAR-ID")) (marker (point-marker))) - (unless issue-id - (user-error "Not on a Linear issue heading")) (if body (pearl--create-and-append-comment issue-id marker body) (pearl--compose-in-buffer @@ -2599,13 +2597,9 @@ Works from anywhere inside an issue subtree. Confirms first, then issues a soft delete (Linear moves the issue to Trash, recoverable for about 30 days); on success the issue's Org subtree is removed from the buffer." (interactive) - (unless (save-excursion (ignore-errors (org-back-to-heading t) t)) - (user-error "Not on a Linear issue heading")) - (let* ((marker (save-excursion (org-back-to-heading t) (point-marker))) + (let* ((marker (save-excursion (pearl--goto-issue-heading-or-error) (point-marker))) (issue-id (org-entry-get marker "LINEAR-ID")) (ident (or (org-entry-get marker "LINEAR-IDENTIFIER") "this issue"))) - (unless issue-id - (user-error "Not on a Linear issue heading")) (when (yes-or-no-p (format "Delete %s from Linear (moves it to Trash)? " ident)) (pearl--delete-issue-async issue-id diff --git a/tests/test-pearl-comment-editing.el b/tests/test-pearl-comment-editing.el index 372cd95..32b194d 100644 --- a/tests/test-pearl-comment-editing.el +++ b/tests/test-pearl-comment-editing.el @@ -328,12 +328,21 @@ the refresh / add-comment / view-merge paths, never on the initial render." (when (find-buffer-visiting tmp) (kill-buffer (find-buffer-visiting tmp))) (ignore-errors (delete-file tmp))))) -(ert-deftest test-pearl-add-comment-from-inside-comment-refuses () - "Running add-comment from inside a comment subtree refuses — no issue id there." +(ert-deftest test-pearl-add-comment-from-inside-comment-walks-up () + "From inside a comment subtree, add-comment walks up to the enclosing issue and +adds the comment there rather than refusing." (test-pearl--in-org (test-pearl--comment-doc "u-me" "stored" "uniquecommentline") - (goto-char (point-min)) - (re-search-forward "uniquecommentline") ; point inside the comment subtree - (should-error (pearl-add-comment "hi") :type 'user-error))) + (let ((created-on nil)) + (cl-letf (((symbol-function 'pearl--create-comment-async) + (lambda (id _body cb) + (setq created-on id) + (funcall cb (list :id "cnew" :author "Me" + :created-at "2026-05-26T00:00:00.000Z" :body "hi"))))) + (goto-char (point-min)) + (re-search-forward "uniquecommentline") ; point inside the comment subtree + (pearl-add-comment "hi")) + ;; resolved the enclosing issue's LINEAR-ID ("a"), not the comment's + (should (equal "a" created-on))))) (ert-deftest test-pearl-edit-comment-missing-id-refuses-no-network () "A comment subtree without LINEAR-COMMENT-ID is refused with no network call." diff --git a/tests/test-pearl-delete.el b/tests/test-pearl-delete.el index 02d3380..ea5027f 100644 --- a/tests/test-pearl-delete.el +++ b/tests/test-pearl-delete.el @@ -93,6 +93,20 @@ (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t))) (should-error (pearl-delete-current-issue) :type 'user-error)))) +(ert-deftest test-pearl-delete-current-issue-from-inside-comment-walks-up () + "Delete run from inside a comment subtree walks up and deletes the enclosing issue." + (test-pearl--in-org + "*** TODO ENG-1 Doomed\n:PROPERTIES:\n:LINEAR-ID: a\n:LINEAR-IDENTIFIER: ENG-1\n:END:\nbody\n**** Comments\n***** Someone — ts\n:PROPERTIES:\n:LINEAR-COMMENT-ID: c1\n:END:\ncommentbody\n" + (let ((deleted nil)) + (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t)) + ((symbol-function 'pearl--delete-issue-async) + (lambda (id cb) (setq deleted id) (funcall cb '(:success t))))) + (re-search-forward "commentbody") ; point inside the comment subtree + (pearl-delete-current-issue) + (should (equal "a" deleted)) ; climbed to the enclosing issue + (goto-char (point-min)) + (should-not (re-search-forward "Doomed" nil t)))))) + (ert-deftest test-pearl-delete-current-issue-failure-keeps-subtree () "A confirmed delete that fails on the remote leaves the subtree and its sibling intact." (test-pearl--in-org |
