Repository navigation
feat(sidebar): link Linear issues from Edit Worktree Details - #12380
Conversation
The Issue field only accepted GitHub numbers, so a workspace tracking a Linear issue had no way to say so from the dialog — the link could only be set at creation time or through `orca worktree set --linear-issue`. Replaces the field with one provider-aware row: a chip suffix inside the input selects GitHub or Linear, and pasting a URL flips the chip to match. A bare key never steers the provider — Linear and Jira issue keys are byte-identical in shape, so shape alone cannot decide one. One issue per workspace. A changed field displaces the other provider's slot and the row names what Save is about to unlink. GitLab and Jira links are left alone: the row cannot display them, and nothing else in the UI could restore one it dropped. - Folder workspaces read-only (their link is creation-time only) - Remote runtimes assert the capability before writing or clearing, since `worktree.set` parses in strip mode and would silently drop the keys - `updateWorktreeMeta` now reports failure so the dialog can stay open instead of closing over a save that refetch reverted - Parses are length-bounded — `matchGitHubItemPath` strips trailing slashes with an unanchored regex that is quadratic on a large paste
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe change adds shared GitHub and Linear issue-link parsing and update builders. Worktree metadata updates now use draft and snapshot state, preserve unrelated links, and return structured results. The issue-link hook and controlled field support provider selection, validation, opening, and failure states. The metadata dialog supports indexed and folder workspaces, displaced-link warnings, read-only behavior, and failed-save handling. Tests cover parsing, update construction, dialog behavior, and persistence outcomes. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (7)
src/renderer/src/components/sidebar/WorktreeIssueLinkField.tsx (2)
243-253: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAnnounce the helper text when it changes without focus movement.
openIssueFailedis set after a button click. The input keeps focus elsewhere or the click target is the open-issue button, so a change inaria-describedbycontent is not reliably announced. Add a live region role so screen-reader users receive the failure and displacement messages.♿ Proposed fix
<p id={helperId} + role="status" + aria-live="polite" className={cn(
246-250: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUse the existing warning color token for this field.
main.cssdefinesvar(--warning,#f59e0b)and no light/dark text color mapping exists. Add a--color-warningmapping tomain.css, then replace bothtext-amber-*classes here with the token-based style.Source: Coding guidelines
src/renderer/src/components/sidebar/WorktreeMetaDialog.tsx (1)
244-261: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueClear
saveErrorwhen a new save starts.A failed save keeps
saveErrorvisible. If the user edits a field and clicks Save again, the previous error stays on screen for the whole in-flight request. Reset it withsetSaving(true).♻️ Proposed fix
setSaving(true) + setSaveError(null) try {src/renderer/src/components/sidebar/WorktreeMetaDialog.test.tsx (1)
216-238: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick winAdd a test for the displaced-link payload, not only the warning text.
These tests assert the warning copy. No test asserts the update payload that the displacement produces. The one-issue-per-workspace rule is enforced by
buildWorktreeMetaUpdates, so a regression there would clear the wrong slot without failing any test here.💚 Proposed test
+ it('clears the displaced GitHub link when a Linear value is saved', async () => { + openDialog({ worktree: { linkedIssue: 42 } }) + + fireEvent.click(screen.getByRole('menuitemradio', { name: 'Linear' })) + fireEvent.change(issueInput(), { target: { value: 'STA-335' } }) + await act(async () => { + fireEvent.click(saveButton()) + }) + + await waitFor(() => expect(updateWorktreeMeta).toHaveBeenCalledTimes(1)) + const updates = updateWorktreeMeta.mock.calls[0]?.[1] ?? {} + expect(updates.linkedLinearIssue).toBe('STA-335') + expect(updates.linkedIssue).toBeNull() + })src/shared/issue-link-input.test.ts (1)
65-70: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a test for the safe-integer bound.
parseIssueLinkInputrejects digit strings that exceedNumber.MAX_SAFE_INTEGER, and the source comment states this guard is load-bearing. No test covers it, so a regression would pass CI.💚 Proposed test addition
it('rejects non-positive numbers and junk', () => { expect(parseIssueLinkInput('0', 'github')).toBeNull() expect(parseIssueLinkInput('-1', 'github')).toBeNull() expect(parseIssueLinkInput('not an issue', 'github')).toBeNull() expect(parseIssueLinkInput(' ', 'github')).toBeNull() }) + + it('rejects numbers beyond the safe-integer range', () => { + expect(parseIssueLinkInput('9'.repeat(400), 'github')).toBeNull() + })src/renderer/src/components/sidebar/worktree-meta-updates.ts (1)
137-144: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument or guard the PR field's unconditional write.
buildPrLinkUpdatealways emitslinkedPR, includingnullfor a blank input. This is safe only while the dialog seedsprInputfrom the persistedlinkedPRon open. The issue field received a snapshot-based dirty guard to defend against exactly this failure mode. Add the seeding requirement as a comment here, or gate the write on a snapshot comparison as the issue field does.♻️ Proposed comment
+// Requires the dialog to seed `prInput` from the persisted `linkedPR`. An +// unseeded field would clear the link on an untouched save. function buildPrLinkUpdate(draft: WorktreeMetaDraft): Partial<WorktreeMeta> {src/renderer/src/components/sidebar/worktree-meta-updates.test.ts (1)
159-166: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winThis test cannot fail.
buildWorktreeMetaUpdatesnever writeslinkedGitLabIssueon any branch, so both assertions hold regardless of the displacement logic. The comment states the intent correctly, but the test does not protect it.Assert on the fields the builder can actually write for a GitLab-owned work item —
linkedWorkItemandlinkedTaskSourceContext— which is what the displacement gate decides. Note that lines 147-157 already cover that case, so this test may be redundant.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 78101784-f91a-456a-abd0-b7158a7adc59
📒 Files selected for processing (17)
src/cli/handlers/worktree-linear-issue-link.tssrc/cli/index.test.tssrc/renderer/src/components/sidebar/WorktreeCard.tsxsrc/renderer/src/components/sidebar/WorktreeIssueLinkField.tsxsrc/renderer/src/components/sidebar/WorktreeMetaDialog.test.tsxsrc/renderer/src/components/sidebar/WorktreeMetaDialog.tsxsrc/renderer/src/components/sidebar/use-worktree-issue-link.tssrc/renderer/src/components/sidebar/worktree-issue-displacement.tssrc/renderer/src/components/sidebar/worktree-meta-updates.test.tssrc/renderer/src/components/sidebar/worktree-meta-updates.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/store/slices/worktree-helpers.tssrc/renderer/src/store/slices/worktrees.tssrc/shared/issue-link-input.test.tssrc/shared/issue-link-input.tssrc/shared/linear-links.test.tssrc/shared/linear-links.ts
Only clear displaced issue links when they actually existed, preventing unnecessary Linear keys in GitHub-only workspaces. Skip comment updates when unchanged to avoid workspace reordering. Add accessibility to displacement messages and improve folder workspace error handling.
|
@coderabbitai[bot] fixed |
|
Tip For best results, initiate chat on the files or code changes.
If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! You are interacting with an AI system. |
The same workspace ID can exist under multiple hosts — the owner index reports this as ambiguous rather than guessing. Dialog callers now pass their repoId so lookups are unambiguous. Linear identifiers without an org key are resolved across all workspaces (not just the active organization). Added race-condition protection for async issue lookups and better change detection to avoid clearing work-item titles when re-saving an identifier in different spelling.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/renderer/src/components/sidebar/use-worktree-issue-link.ts (2)
201-204: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winScope
openingIssuecleanup to the request generation.If
resetOpeningIssue()retires request A and request B starts before A settles, A clearsopeningIssuein eitherfinallyblock. The hook then reports B as idle and can accept duplicate opens. Clear loading state only whenopenRequestRef.current === generation. Apply the change in both branches.Proposed fix
const isCurrentRequest = (): boolean => mountedRef.current && openRequestRef.current === generation && latestRequestKeyRef.current === requestKey + const isActiveGeneration = (): boolean => + mountedRef.current && openRequestRef.current === generation ... } finally { - if (mountedRef.current) { + if (isActiveGeneration()) { setOpeningIssue(false) } }Also applies to: 240-243, 263-265
273-276: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAssociate an open failure with the selected provider.
If a Linear lookup for
ENG-123fails and the user selects GitHub without changing the text,openIssueFailedremainstrue. Store the provider-plus-input request key when a lookup fails, then compare that key here. Add a provider-switch regression test.Based on the PR objective, provider selection can change without changing a bare identifier.
🧹 Nitpick comments (1)
src/renderer/src/components/sidebar/WorktreeMetaDialog.test.tsx (1)
430-444: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAssert the full argument list for the cross-workspace lookup.
slice(0, 2)ignores any further arguments, so a wrong third argument such as a workspace scope or organization key still passes. Assert the whole call instead.♻️ Proposed tightening
- expect(fetchLinearIssue.mock.calls[0]?.slice(0, 2)).toEqual(['STA-999', 'all']) + expect(fetchLinearIssue).toHaveBeenCalledWith('STA-999', 'all')If the caller intentionally passes extra arguments, keep the current form and ignore this suggestion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: acdaf834-ca7e-4dae-ac02-dc3440586c42
📒 Files selected for processing (9)
src/renderer/src/components/right-sidebar/ChecksPanel.tsxsrc/renderer/src/components/sidebar/WorktreeCard.tsxsrc/renderer/src/components/sidebar/WorktreeContextMenu.tsxsrc/renderer/src/components/sidebar/WorktreeMetaDialog.test.tsxsrc/renderer/src/components/sidebar/WorktreeMetaDialog.tsxsrc/renderer/src/components/sidebar/use-worktree-issue-link.tssrc/renderer/src/components/sidebar/use-worktree-meta-workspace.tssrc/renderer/src/components/sidebar/worktree-meta-updates.test.tssrc/renderer/src/components/sidebar/worktree-meta-updates.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/renderer/src/components/sidebar/WorktreeMetaDialog.tsx
- src/renderer/src/components/sidebar/worktree-meta-updates.test.ts
- src/renderer/src/components/sidebar/WorktreeCard.tsx
…i#12380) * feat(sidebar): link Linear issues from Edit Worktree Details The Issue field only accepted GitHub numbers, so a workspace tracking a Linear issue had no way to say so from the dialog — the link could only be set at creation time or through `orca worktree set --linear-issue`. Replaces the field with one provider-aware row: a chip suffix inside the input selects GitHub or Linear, and pasting a URL flips the chip to match. A bare key never steers the provider — Linear and Jira issue keys are byte-identical in shape, so shape alone cannot decide one. One issue per workspace. A changed field displaces the other provider's slot and the row names what Save is about to unlink. GitLab and Jira links are left alone: the row cannot display them, and nothing else in the UI could restore one it dropped. - Folder workspaces read-only (their link is creation-time only) - Remote runtimes assert the capability before writing or clearing, since `worktree.set` parses in strip mode and would silently drop the keys - `updateWorktreeMeta` now reports failure so the dialog can stay open instead of closing over a save that refetch reverted - Parses are length-bounded — `matchGitHubItemPath` strips trailing slashes with an unanchored regex that is quadratic on a large paste * fix(sidebar): respect one-issue-per-workspace rule conditionally Only clear displaced issue links when they actually existed, preventing unnecessary Linear keys in GitHub-only workspaces. Skip comment updates when unchanged to avoid workspace reordering. Add accessibility to displacement messages and improve folder workspace error handling. * fix(sidebar): resolve workspace ambiguity and improve Linear issue linki The same workspace ID can exist under multiple hosts — the owner index reports this as ambiguous rather than guessing. Dialog callers now pass their repoId so lookups are unambiguous. Linear identifiers without an org key are resolved across all workspaces (not just the active organization). Added race-condition protection for async issue lookups and better change detection to avoid clearing work-item titles when re-saving an identifier in different spelling.
Problem
The Edit Worktree Details dialog has a single GH Issue field. A workspace whose work is tracked in Linear had no way to say so from the UI — the link could only be set when the workspace was created, or out-of-band via
orca worktree set --linear-issue. The data model already had the slots; the editor didn't.What changed
One provider-aware Issue row replaces the GitHub-only field. No extra rows, no extra dialog height:
LINEAR_IDENTIFIER_PATTERNand Jira's issue-key pattern are byte-identical, so shape alone cannot decide one — letting it try would silently override an explicit choice.One issue per workspace
A changed field displaces the other provider's slot, and the helper line names what Save is about to unlink (both, when clearing the field drops both). Only a dirty field displaces anything — the dialog opens focused on Comment, and an untouched row leaves every link alone.
GitLab and Jira links are deliberately left alone. The row cannot render them,
displacedLinkLabelshas no branch to name one, and there is no CLI flag or card property to restore one from. Displacing what it cannot display would destroy a link the user was never shown.Correctness notes
undefinedkeys erase fields.setWorktreeMetaraw-spreads{...existing, ...meta}, so a key that must not be written has to be structurally absent, notundefined. Every build inworktree-meta-updates.test.tsasserts this invariant.orca worktree set --linear-issuewhile the dialog is open would otherwise make the untouched field read as dirty, and the next comment-only save would write the stale seed back over the new link.worktree.setparses in strip mode, so an older runtime drops an unknown key and applies the rest of the payload. A dropped clear is as damaging as a dropped write: the stale link it strands is one the Issue row then hides while the card still badges it. Two capabilities are asserted, becauselinkedWorkItem/linkedTaskSourceContextentered the schema six weeks aftertask-source-context.v1.updateWorktreeMetareturns a result instead of swallowing. A failed save refetches, which reverts the optimistic write — closing the dialog there reported success for an edit that undid itself, and discarded the name, comment and PR changes in the same payload. The dialog now stays open with arole="alert"line. (Result-return rather than rethrow: ~20void updateWorktreeMeta(...)call sites would otherwise produce unhandled rejections.)matchGitHubItemPathstrips trailing slashes with an unanchored/\/+$/, which is quadratic — a 160 KB paste of slashes froze the renderer for ~19s. These parses run on every keystroke, so the field, the hook, and the PR gate all take the same bound; the check short-circuits on length, so it stays O(1) on a huge paste.updateWorktreeMetadrops link keys for them entirely. The row still shows the link (they live outsideworktreesByRepo, so the indexed lookup alone left it blank).file://linear.app/...; the parsed value is later handed toshell.openUrl.Also fixed while here: a bare identifier now clears
linkedLinearIssueWorkspaceId/OrganizationUrlKeyinstead of inheriting them. A stale org key pinsresolveLegacyLinearLinkWorkspaceto the wrong org — not-found, or a silently wrong issue on a team-prefix collision.Performance
The dialog's worktree lookup goes through the existing owner index. The code it replaced was
Object.values().flat().find()— an N-element allocation on every store notification, not a plainArray.find.Testing
npm run typecheck— cleannpx oxlint <changed files>— cleannpx oxfmt --check— cleannpx vitest run --config config/vitest.config.ts src/shared src/renderer/src/components/sidebar src/renderer/src/store src/cli— 811 files / 8592 tests passedNew coverage: provider detection and parse (
issue-link-input.test.ts), payload shape and the erasure invariant (worktree-meta-updates.test.ts), dialog behavior incl. seeding, chip flips, displacement notices, the frozen baseline, folder workspaces, and the save-failure surface (WorktreeMetaDialog.test.tsx), and the Linear protocol gate (linear-links.test.ts).Two rounds of
/readiness-checklistwere run with sub-agents across functional, performance, security, back-compat and cross-platform seats; round 2 caught three defects introduced by round 1's own fixes.Not in scope
Jira. The chip menu lists only GitHub and Linear — no disabled "coming soon" item.
ISSUE_LINK_PROVIDERSnarrows the canonical provider union rather than minting a parallel one, so adding Jira later is a one-entry change.Made with Orca 🐋