orca icon indicating copy to clipboard operation
orca copied to clipboard

Add Copy Branch Name and Copy Pull Request URL to the worktree menu

Open brennanb2025 opened this issue 5 months ago • 6 comments

What changes

The worktree right-click context menu groups its copy actions under a single Copy submenu and adds two new items beside the existing Copy Path:

  • Copy Branch Name — copies the worktree's branch (the same name shown on the card). Disabled in detached-HEAD state.
  • Copy Pull Request URL — copies the review's web URL. Provider-neutral: the label reads Copy Merge Request URL for GitLab and Copy Pull Request URL for GitHub, Bitbucket, Azure DevOps, and Gitea.

The PR/MR item appears only when a review URL is actually known for that worktree (the same condition that makes the card's PR badge clickable), so there's never a dead "copy" item with nothing to copy.

What does not change

No new fetch, IPC, store subscription, or toast is introduced. The submenu reuses the branch name and review URL already resolved by WorktreeCard (prDisplay) and writes to the clipboard via the existing window.api.ui.writeClipboardText path — identical to the previous Copy Path. Multi-select context menus are unchanged (copy actions remain single-worktree). Copy Path keeps its existing behavior and string.

Design approach

WorktreeContextMenu is rendered only by WorktreeCard, which already computes the displayed PR/MR review. Two primitive props (pullRequestUrl, pullRequestProvider) are passed down so the menu copies the exact URL the card shows, with no second lookup. The provider-neutral label uses the same GitLab-vs-rest split as the existing getReviewLabel helper; branch name comes from getWorktreeGitIdentityDisplay (the same source the sidebar uses, so the copied value matches what's displayed).

Validation

  • Design review (Brennan's PR process): converged clean in 2 rounds; the substantive fix was making the disabled contract explicit on all three items (Copy Branch Name disabled on detached HEAD, all disabled mid-delete to match sibling items).
  • Completeness verification: all requirements and edge cases confirmed against the implementation.
  • Headline behavior: implemented. All three copy actions run in production against real renderer state and write real values to the clipboard.
  • Performance audit: no action needed. New props are primitives that preserve React.memo; getWorktreeGitIdentityDisplay matches existing per-row precedent and feeds no memo boundary; submenu content is portal-mounted (lazy), so it costs nothing until the menu opens.
  • Code-review loop: both reviewers returned clean in one round (one non-actionable test-coverage nit, judged over-engineering for a one-line inline ternary).
  • Manual Electron validation: launched a dev build and exercised the live menu. Clipboard read-back confirmed:
    • Copy Branch Name → brennanb2025/Anemone
    • Copy Path → /Users/.../demo-project/Anemone
    • Copy Pull Request URL → https://github.com/stablyai/demo-project/pull/21 (GitHub PR #21, labeled "Pull Request")
    • Detached-HEAD worktree → Copy Branch Name correctly disabled, no PR item.
    • Screenshots of the expanded submenu and the detached-HEAD disabled state are attached in a comment below.
  • Static checks: pnpm run typecheck:web, pnpm run lint (incl. localization catalog + coverage parity across en/es/ja/ko/zh), and WorktreeContextMenu.test.ts (19 tests) all pass. Full sidebar suite (1277 tests) passes.

Accepted gaps / notes

  • GitLab "Copy Merge Request URL" labeling was verified by code/logic only (no live GitLab repo was available); the label is driven by pullRequestProvider === 'gitlab' and the i18n key exists in all five catalogs.
  • Non-English locale catalogs carry the new keys with English source strings (the established convention for these auto-generated keys), pending translation.

Cross-platform / SSH

Clipboard writes route through the existing Electron main-process handler, so they work identically for local and SSH/remote worktrees, and the values are already in renderer state (no remote round-trip). The menu items are mouse-driven only — no keyboard accelerators or platform-specific modifier handling added.

Closes #6167

Made with Orca 🐋

brennanb2025 avatar Jun 29 '26 09:06 brennanb2025

Manual validation evidence

Exercised the live right-click menu in a dev Electron build (clipboard read-back via pbpaste after seeding sentinels):

Item Copied value
Copy Branch Name brennanb2025/Anemone (matches card branch)
Copy Path /Users/.../demo-project/Anemone (matches worktree path)
Copy Pull Request URL https://github.com/stablyai/demo-project/pull/21 (matches PR #21)

Screenshots captured (not committed, per repo policy):

  1. Copy submenu expanded on a PR worktree — shows all three items (Copy Path, Copy Branch Name, Copy Pull Request URL) with icons, on a GitHub PR worktree → labeled "Pull Request" (not "Merge Request"), confirming provider-neutral logic.
  2. Detached-HEAD worktree — Copy submenu shows Copy Branch Name greyed/disabled and Copy Path enabled, with no PR item; the "Detached HEAD @ " badge is visible on the card.

I can drag these images into this conversation if useful — they live on the validation machine at /tmp/orca-6167-04-pr-submenu-expanded.png and /tmp/orca-6167-05-detached-disabled.png.

brennanb2025 avatar Jun 29 '26 09:06 brennanb2025

@coderabbitai review

brennanb2025 avatar Jun 29 '26 09:06 brennanb2025

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Jun 29 '26 09:06 coderabbitai[bot]

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e0575830-5545-411d-a3bc-ac632b555a0f

📥 Commits

Reviewing files that changed from the base of the PR and between c9d395e8957fdbd65139cbaa31c3aa95946a46fa and 58dc44ec2daace2db52a2a256f6d887373da59d1.

📒 Files selected for processing (1)
  • src/renderer/src/components/sidebar/WorktreeContextMenu.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/sidebar/WorktreeContextMenu.tsx

📝 Walkthrough

Walkthrough

WorktreeCard now passes pullRequestUrl and pullRequestProvider from prDisplay to WorktreeContextMenu. The menu adds branch-name and PR/MR URL copy actions, derives branch identity with getWorktreeGitIdentityDisplay, and labels GitLab URLs as merge requests. The single copy item is replaced with a "Copy" submenu. New locale strings were added in en, es, ja, ko, and zh.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the added copy actions in the worktree menu, including branch name and PR URL.
Description check ✅ Passed The description is mostly complete and includes summary, validation, and platform notes, with only some template sections missing.
Linked Issues check ✅ Passed The PR implements the requested Copy submenu with path, branch name, and PR URL items, matching #6167's core requirements.
Out of Scope Changes check ✅ Passed The changes stay within the worktree copy-menu scope and only add related context, localization, and clipboard wiring.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • [ ] Create stacked PR
  • [ ] Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Jun 29 '26 09:06 coderabbitai[bot]

@coderabbitai review

brennanb2025 avatar Jun 29 '26 10:06 brennanb2025

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot] avatar Jun 29 '26 10:06 coderabbitai[bot]

Closing as superseded by #12240's implementation of the same worktree-menu copy feature.

I compared the complete production changes at the live heads (58dc44ec2daace2db52a2a256f6d887373da59d1 here, d09b196be6bdbdeb3366828689ced7c2d427a9fd in #12240). The replacement carries all three core actions: copy the exact workspace path, copy its branch through getWorktreeGitIdentityDisplay, and copy the owning card's resolved hosted-review URL with GitLab MR terminology. It handles detached/no-branch and no-link cases and keeps the existing multi-selection/deletion guards. It also adds clipboard success/failure reporting instead of leaving rejected clipboard writes unhandled.

The presentation differs: #12240 uses a labelled flat Copy section and disabled explanations where this PR uses a submenu and hides a missing review link. That does not leave a distinct copy capability to implement here. The original request remains tracked by #12240; it is still open, and this closure does not imply it has merged. Thank you for the earlier implementation.

OrcaWin avatar Oct 26 '26 22:10 OrcaWin