Have pull requests close linked issues and preserve branch issue links #66

Merged
Christoph merged 2 commits from feat/issue-pr-link into main 2026-10-07 19:14:30 +00:00
Owner

This change adds support for closing an issue from a pull request when the source branch was created from that issue, surfaces linked-issue metadata in the Branch panel, and includes a few related fixes in the Git/Tauri code.

Summary of changes and observable behavior:

  • Pull request behavior

    • The Create Pull Request dialog prefills the title from a linked issue (when present) and offers a checkbox to append a closing reference. When enabled the PR description gets Closes #<number> appended via appendIssueCloseReference.
    • The PR creation call now uses appendIssueCloseReference to modify the description when requested.
    • New helper exported functions in src/lib/issueBranch.ts: issueCloseReference, appendIssueCloseReference, issueLinkMatchesRepository, readBranchIssueLinks, and moveBranchIssueLink. These implement the closing-reference logic, repository-scoped link matching, and link migration when a branch is renamed.
  • Branch UI and link persistence

    • App.svelte now reads all branch issue links (readBranchIssueLinks) into branchIssueLinks and passes them to BranchPanel as the issueLinks prop.
    • BranchPanel.svelte displays the issue number in the branch list and shows #<number> <title> in the branch tooltip/title when a branch is linked.
    • When a linked branch is renamed, moveBranchIssueLink is called from App.svelte to preserve the link; the function returns whether the move succeeded.
  • Tests

    • A new test file scripts/issue-branch.test.mjs was added to cover the append/match/move/read/write behaviors for branch issue links.
  • Git/Tauri fixes

    • src-tauri/src/git/lfs.rs: before running git lfs pull, the code now runs git lfs install --local --skip-repo when repository-local LFS filters are not configured. This avoids leaving LFS pointer files behind when Git LFS is not installed globally and prevents modifying existing repo hooks.
    • src-tauri/src/git/review_cleanup.rs: the cleanup now checks whether the remote-tracking ref exists before calling git update-ref -d .... This avoids an error path when newer Git versions already removed the remote-tracking branch during the push.

Testing

  • No test execution results were provided.

Recommended focused checks for reviewers

  1. UI: create a branch that is recorded as linked to an issue (or simulate by calling writeBranchIssueLink in the console for the repo), open the Create Pull Request dialog:
    • Verify the title is prefilled with the issue title and the checkbox to close the issue is shown.
    • Toggle the checkbox and confirm the description passed to the integration contains (or omits) Closes #<number> accordingly.
  2. Branch list: confirm linked branches show the #<number> badge and the tooltip includes #<number> <title>.
  3. Rename behavior: rename a linked branch and ensure the link moves (badge/tooltip moves to new name) and no stale entry remains for the old name.
  4. Unit tests: run the new scripts/issue-branch.test.mjs via the project test runner (Node.js node:test) to exercise the new helpers.
  5. Git LFS: with Git LFS 3.8+ and no global git lfs install, perform a pull_git_lfs_objects flow and verify pointer files are not left behind and that repository-local filters are configured without touching existing hooks.
  6. Review cleanup: simulate merging/finishing a review where the push removes the remote-tracking branch and confirm no error occurs from update-ref when the tracking ref is already gone.

Compatibility and risks

  • The branch-link storage continues to use localStorage. Link operations catch storage errors and fail gracefully; moveBranchIssueLink returns false on error.
  • No data migration is required; new functions only read/write the same links key.
  • Reviewer attention: inspect the UI changes in CreateReviewDialog.svelte, App.svelte and BranchPanel.svelte, and the new helpers in src/lib/issueBranch.ts. Also review the Tauri native changes in src-tauri/src/git/lfs.rs and src-tauri/src/git/review_cleanup.rs for potential platform-specific side effects.

If you want, I can extract the new helper functions into a separate file for easier testing, or add integration tests that exercise the full PR creation flow with a test integration backend.

This change adds support for closing an issue from a pull request when the source branch was created from that issue, surfaces linked-issue metadata in the Branch panel, and includes a few related fixes in the Git/Tauri code. Summary of changes and observable behavior: - Pull request behavior - The Create Pull Request dialog prefills the title from a linked issue (when present) and offers a checkbox to append a closing reference. When enabled the PR description gets `Closes #<number>` appended via `appendIssueCloseReference`. - The PR creation call now uses `appendIssueCloseReference` to modify the description when requested. - New helper exported functions in `src/lib/issueBranch.ts`: `issueCloseReference`, `appendIssueCloseReference`, `issueLinkMatchesRepository`, `readBranchIssueLinks`, and `moveBranchIssueLink`. These implement the closing-reference logic, repository-scoped link matching, and link migration when a branch is renamed. - Branch UI and link persistence - `App.svelte` now reads all branch issue links (`readBranchIssueLinks`) into `branchIssueLinks` and passes them to `BranchPanel` as the `issueLinks` prop. - `BranchPanel.svelte` displays the issue number in the branch list and shows `#<number> <title>` in the branch tooltip/title when a branch is linked. - When a linked branch is renamed, `moveBranchIssueLink` is called from `App.svelte` to preserve the link; the function returns whether the move succeeded. - Tests - A new test file `scripts/issue-branch.test.mjs` was added to cover the append/match/move/read/write behaviors for branch issue links. - Git/Tauri fixes - `src-tauri/src/git/lfs.rs`: before running `git lfs pull`, the code now runs `git lfs install --local --skip-repo` when repository-local LFS filters are not configured. This avoids leaving LFS pointer files behind when Git LFS is not installed globally and prevents modifying existing repo hooks. - `src-tauri/src/git/review_cleanup.rs`: the cleanup now checks whether the remote-tracking ref exists before calling `git update-ref -d ...`. This avoids an error path when newer Git versions already removed the remote-tracking branch during the push. Testing - No test execution results were provided. Recommended focused checks for reviewers 1. UI: create a branch that is recorded as linked to an issue (or simulate by calling `writeBranchIssueLink` in the console for the repo), open the Create Pull Request dialog: - Verify the title is prefilled with the issue title and the checkbox to close the issue is shown. - Toggle the checkbox and confirm the description passed to the integration contains (or omits) `Closes #<number>` accordingly. 2. Branch list: confirm linked branches show the `#<number>` badge and the tooltip includes `#<number> <title>`. 3. Rename behavior: rename a linked branch and ensure the link moves (badge/tooltip moves to new name) and no stale entry remains for the old name. 4. Unit tests: run the new `scripts/issue-branch.test.mjs` via the project test runner (Node.js `node:test`) to exercise the new helpers. 5. Git LFS: with Git LFS 3.8+ and no global `git lfs install`, perform a `pull_git_lfs_objects` flow and verify pointer files are not left behind and that repository-local filters are configured without touching existing hooks. 6. Review cleanup: simulate merging/finishing a review where the push removes the remote-tracking branch and confirm no error occurs from `update-ref` when the tracking ref is already gone. Compatibility and risks - The branch-link storage continues to use `localStorage`. Link operations catch storage errors and fail gracefully; `moveBranchIssueLink` returns `false` on error. - No data migration is required; new functions only read/write the same links key. - Reviewer attention: inspect the UI changes in `CreateReviewDialog.svelte`, `App.svelte` and `BranchPanel.svelte`, and the new helpers in `src/lib/issueBranch.ts`. Also review the Tauri native changes in `src-tauri/src/git/lfs.rs` and `src-tauri/src/git/review_cleanup.rs` for potential platform-specific side effects. If you want, I can extract the new helper functions into a separate file for easier testing, or add integration tests that exercise the full PR creation flow with a test integration backend.
When the source branch of a new pull request was created from an issue,
the Create Pull Request dialog prefills the title with the issue title and
offers a checkbox (on by default) that appends "Closes #<n>" to the
description on submit, so the reference survives AI-generated drafts. The
link only applies when the PR repository matches the issue's repository.

Linked local branches show a #<n> badge in the Branches panel, and renaming
a branch moves its issue link along.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- pull_git_lfs_objects installs the repository-local LFS filters first
  (git lfs install --local --skip-repo) when none are configured. Git LFS
  3.8+ otherwise downloads the objects but skips the checkout, leaving
  pointer files in the working tree. --skip-repo keeps existing hooks.
- Review cleanup only deletes the remote-tracking ref of the source branch
  when it still exists. Newer Git already removes it when pushing the
  deletion to a URL that matches the remote, which made update-ref fail.

Both fix the previously failing Rust tests
pulls_git_lfs_objects_from_local_remote and
review_cleanup_switches_to_actual_target_and_deletes_after_merge_and_squash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.