Repository navigation
feat(cli): link a Jira issue to a workspace with worktree set --jira - #11659
EugeValeiras wants to merge 2 commits into
Conversation
Greptile SummaryThis PR adds
Confidence Score: 5/5Safe to merge — the change is purely additive, touches no hot paths, and site matching correctly uses the shared getMatchingJiraSites utility. Site matching uses the shared getMatchingJiraSites helper (origin + sitePath equality, not a prefix test), the null-clear and multi-site ambiguity paths are handled explicitly, and all changes are isolated to the --jira flag on worktree set. The only gaps are style-level: a duplicated helper, missing unit coverage for the issue-not-found return, and absent examples in the spec — none of which affect correctness. Files Needing Attention: No files require special attention. The new worktree-jira-issue-link.ts and its test are the core of the change and both look correct.
|
| Filename | Overview |
|---|---|
| src/cli/handlers/worktree-jira-issue-link.ts | New module implementing --jira flag parsing and Jira issue resolution; correctly delegates site matching to getMatchingJiraSites and handles all edge cases (bare key, URL, null-clear, no sites, multiple sites with no active). |
| src/cli/handlers/worktree-jira-issue-link.test.ts | Comprehensive parser and site-matching tests; covers the evil-host prefix-attack case explicitly. Missing a unit test for jira.lookupIssueSummary returning null (issue-not-found path), though this is covered by end-to-end testing per the PR description. |
| src/cli/handlers/worktree.ts | Integrates Jira resolution into the worktree set handler by spreading jiraLink alongside the existing linearIssueLink; resolveJiraWorkItem is awaited before the worktree selector is resolved, but this is a minor UX ordering issue, not a functional bug. |
| src/cli/help.ts | Adds `--jira <key |
| src/cli/specs/core.ts | Adds --jira to the worktree set usage string, allowedFlags, and notes; no --jira examples added to the examples array, which is a minor omission relative to how --linear-issue examples are shown. |
Reviews (4): Last reviewed commit: "fix(cli): match the Jira site exactly in..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between aff26923653c48485636a22bc93aa9c53ee59d47 and cdb3a34. 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughAdds Jira issue-link support to 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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: 2
🧹 Nitpick comments (4)
src/cli/handlers/worktree-jira-issue-link.test.ts (1)
1-69: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for
resolveJiraWorkItem.This file tests
getOptionalJiraIssueLinkFlagexhaustively but has no tests forresolveJiraWorkItem, which contains the non-trivial branching (clear, undefined input, active-site selection, origin-pinned selection, no-site error, issue-not-found error). A mockedRuntimeClienttest covering the multi-site and no-active-site cases would also have caught the site-matching issues flagged inworktree-jira-issue-link.ts.src/cli/specs/core.ts (2)
157-160: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd an example for
--jira.The
examplesarray shows--linear-issueusage (set and clear) but has no equivalent for--jira, even though the notes at line 153 describe both key and URL forms plus clearing. Add examples for consistency with thelinear-issueandworktree createentries.♻️ Proposed addition
examples: [ 'orca worktree set --worktree active --linear-issue STA-335 --json', - 'orca worktree set --worktree active --linear-issue null --json' + 'orca worktree set --worktree active --linear-issue null --json', + 'orca worktree set --worktree active --jira PROJ-123 --json', + 'orca worktree set --worktree active --jira null --json' ]
139-139: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAlign the
--jiraplaceholder notation between usage string and help text.src/cli/specs/core.tsdocuments--jiraas<key-url-or-null>whilesrc/cli/help.tsdocuments it as<key|url|null>; both describe the same three accepted values but use different separator conventions, and the core.ts form also breaks with sibling flags in the same usage string (<number|null>,<identifier-or-url|null>) that already use|.
src/cli/specs/core.ts#L139: change[--jira <key-url-or-null>]to[--jira <key|url|null>]to matchhelp.tsand the sibling flags' pipe convention.src/cli/help.ts#L513: no change needed; keep<key|url|null>as the canonical form.src/cli/handlers/worktree-jira-issue-link.ts (1)
54-66: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMove the present-but-empty string flag helper to a concrete shared module.
getPresentStringFlagis duplicated bygetOptionalJiraIssueLinkFlagandgetOptionalLinearIssueLinkFlagfor the same semantics: required when present and reject empty/boolean values.getOptionalStringFlaguses different semantics, andgetRequiredStringFlagis not optional, so export a more concrete helper instead of copying the helper into the issue-link handler.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: a0d3c0f4-6eda-41dd-b923-19c120ab3469
📥 Commits
Reviewing files that changed from the base of the PR and between 1b4d2f3 and aed64a2ef40014c3131d06baaf8b496187e77102.
📒 Files selected for processing (5)
src/cli/handlers/worktree-jira-issue-link.test.tssrc/cli/handlers/worktree-jira-issue-link.tssrc/cli/handlers/worktree.tssrc/cli/help.tssrc/cli/specs/core.ts
| const linearIssueLink = getOptionalLinearIssueLinkFlag(flags, 'linear-issue', { | ||
| allowNull: true | ||
| }) | ||
| const jiraLink = await resolveJiraWorkItem( | ||
| getOptionalJiraIssueLinkFlag(flags, 'jira', { allowNull: true }), | ||
| client | ||
| ) | ||
| const result = await client.call<{ worktree: RuntimeWorktreeRecord }>('worktree.set', { | ||
| worktree: await getRequiredWorktreeSelector(flags, 'worktree', cwd, client), | ||
| displayName: getOptionalStringFlag(flags, 'display-name'), | ||
| linkedIssue: getOptionalNullableNumberFlag(flags, 'issue'), | ||
| ...linearIssueLink, | ||
| ...jiraLink, |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Description: Inspect the Linear issue-link resolver return shape and any existing exclusivity checks.
fd -e ts . src/cli/handlers | xargs rg -n "getOptionalLinearIssueLinkFlag|linkedWorkItem|assert.*Compatible" -C3Repository: stablyai/orca
Length of output: 8647
🏁 Script executed:
#!/bin/bash
# Read the relevant resolver implementations and worktree handler around the reported flags.
sed -n '1,170p' src/cli/handlers/worktree-linear-issue-link.ts
printf '\n--- resolveJiraWorkItem ---\n'
sed -n '68,150p' src/cli/handlers/worktree-jira-issue-link.ts
printf '\n--- worktree set handler ---\n'
sed -n '240,305p' src/cli/handlers/worktree.ts
printf '\n--- WorkspaceLinkedItem definition ---\n'
rg -n "interface WorkspaceLinkedItem|type WorkspaceLinkedItem|WorkspaceLinkedItem" src/shared src -g '*.ts' -C3
printf '\n--- worktree set allowed flags ---\n'
rg -n "worktree set|'worktree set'|set.*allowedFlags|linear-issue|jira" src/cli/specs src/cli -g '*.ts' -C2Repository: stablyai/orca
Length of output: 50370
🏁 Script executed:
#!/bin/bash
# Locate and inspect the workspace-set RPC implementation and any existing linear-workitem fields.
rg -n "interface RuntimeWorktreeSet|type RuntimeWorktreeSet|worktree\.set|linkedLinearIssue|linkedLinearIssueWorkspace|linkedLinearIssueOrganizationUrl|linkedWorkItem" src/main src/shared src/cli -g '*.ts' -C3
printf '\n--- worktree ipc slice likely section ---\n'
FILE=$(fd 'worktrees.ts' src/main/ipc src -e ts | head -n1)
rg -n "async .*worktree\.set|set.*worktree|RuntimeWorktreeSet" "$FILE" -C8 || trueRepository: stablyai/orca
Length of output: 50369
Reject simultaneous Linear and Jira links on worktree set.
--linear-issue sends separate Linear metadata fields, while --jira sends linkedWorkItem, so the current spread does not overwrite Linear. There is still no single linked work item to preserve instead, and the RPC accepts both. Add an incompatibility check before resolving either link, or reject multiple provider links at the RPC layer if that policy should apply upstream.
aed64a2 to
ea0aa73
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/cli/handlers/worktree-jira-issue-link.test.ts (1)
75-91: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert forwarded call arguments in
clientWith.
clientWith()'scallmock ignores its second parameter and always returns the same hardcoded issue payload, regardless of thekeyorsiteIdpassed tojira.lookupIssueSummary. This means the site-matching tests confirm which site gets selected, but not that the correctsite.idis actually forwarded to the lookup call. A regression that threads the wrongsiteIdthrough would still pass these tests.Use
vi.fn()to capture the call and assert the arguments for thejira.lookupIssueSummarycall.♻️ Proposed refactor to verify forwarded arguments
-function clientWith(sites: JiraSite[], activeSiteId: string | null): RuntimeClient { +function clientWith(sites: JiraSite[], activeSiteId: string | null) { + const call = vi.fn(async (method: string, params?: unknown) => { + if (method === 'jira.status') { + return { result: { connected: true, sites, activeSiteId } } + } + return { + result: { + key: 'PROJ-9', + title: 'A ticket', + url: 'https://acme.atlassian.net/browse/PROJ-9', + siteId: (params as { siteId?: string })?.siteId + } + } + }) return { - call: async (method: string) => { - if (method === 'jira.status') { - return { result: { connected: true, sites, activeSiteId } } - } - return { - result: { - key: 'PROJ-9', - title: 'A ticket', - url: 'https://acme.atlassian.net/browse/PROJ-9', - siteId: sites[0]?.id - } - } - } - } as unknown as RuntimeClient + call + } as unknown as RuntimeClient }Then in the relevant test:
await expect(resolveJiraWorkItem(input, client)).resolves.toMatchObject({ linkedWorkItem: { jiraIdentifier: 'PROJ-9' } }) + expect(client.call).toHaveBeenCalledWith( + 'jira.lookupIssueSummary', + expect.objectContaining({ siteId: '1' }) + )
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8469bacf-a30a-474c-9530-6c946b57ed02
📥 Commits
Reviewing files that changed from the base of the PR and between ea0aa73bf144133845f7998711038862ffe80b72 and aff26923653c48485636a22bc93aa9c53ee59d47.
📒 Files selected for processing (3)
src/cli/handlers/worktree-jira-issue-link.test.tssrc/cli/handlers/worktree-jira-issue-link.tssrc/cli/specs/core.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- src/cli/specs/core.ts
- src/cli/handlers/worktree-jira-issue-link.ts
The workspace model already stores a linked Jira work item, and the card already renders it: `WorkspaceLinkedItem` has `provider: 'jira'` and a `jiraIdentifier`, `getWorktreeCardJiraIssueDisplay` turns it into a clickable pill, and `jira-issue` is a supported card property. The RPC `worktree.set` accepts `linkedWorkItem` too. The only thing missing was a way to set it on a workspace that already exists. Today the link is only created when the workspace is born from Tasks → Jira, so anyone whose workspaces come from `worktree create` — scripted flows in particular — has no way to attach the ticket afterwards. orca worktree set --worktree <sel> --jira PROJ-123 orca worktree set --worktree <sel> --jira https://acme.atlassian.net/browse/PROJ-123 orca worktree set --worktree <sel> --jira null # clears it Title and URL are resolved from the connected Jira site rather than typed: a card showing a key with no title or dead URL is worse than no link, and the renderer expects both. A bare key resolves against the active site; a URL pins the site it came from, which matters when several are connected. This is the CLI half of #10905, which asks for the same link from the Create Worktree composer. The composer side is untouched — happy to follow up, or for someone to build it on top of this. Tests cover the parser: bare key, lowercase key, URL, null-to-clear, null-rejected-where-clearing-makes-no-sense, non-issue URLs, and a flag with no value. X: [@EugenioValeiras](https://x.com/EugenioValeiras)
Review feedback on #11659. `siteUrl.startsWith(origin)` let a look-alike host stand in for the real one (acme.atlassian.net.evil.example matched acme.atlassian.net), and it ignored the site path, so two Jira Server instances on the same host were indistinguishable. Uses the existing getMatchingJiraSites, which compares origin and site path. A bare key with several sites connected and none active now errors instead of picking the first one: the same key can exist on more than one site, and guessing links the wrong ticket. Also unifies the usage notation with --linear-issue. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
aff2692 to
cdb3a34
Compare
Adapted-code-from: #11659 at cdb3a34 Co-authored-by: Eugenio Valeiras <[email protected]>
The gap
Almost all of this already exists:
WorkspaceLinkedItemwithprovider: 'jira'andjiraIdentifiergetWorktreeCardJiraIssueDisplay→ clickable pill on the cardjira-issuecard propertyworktree.setRPC acceptinglinkedWorkItemToday the link is only created when the workspace is born from Tasks → Jira. If your workspaces come from
worktree create— scripted flows especially — there is no way to attach the ticket afterwards, even though the model and the renderer are both ready for it.The change
Title and URL are resolved from the connected Jira site, not typed by the caller. A card showing a key with no title and a dead URL is worse than no link at all, and
getWorktreeCardJiraIssueDisplayexpects both — so a failed lookup is a hard error rather than a partial link.A bare key resolves against the active site; a URL pins the site it came from, which matters when several Jira sites are connected and the same key exists on more than one.
Shaped after
--linear-issue, which solves the same problem for Linear.Relationship to #10905
#10905 asks for this link from the Create Worktree composer. This is the CLI half; the composer is untouched. I'm happy to follow up with it, or for someone to build it on top — the resolution logic lives in
worktree-jira-issue-link.tsand is reusable as-is.Verification
Tested end-to-end against a real Jira Cloud site: linking by key and by URL, clearing with
null, and a non-existent key (which surfaces Jira's own message rather than a generic one). The card renders the ticket oncejira-issueis enabled as a card property.Parser tests cover: bare key, lowercase key, full URL,
nullto clear,nullrejected where clearing makes no sense, non-issue Jira URLs, and a flag passed with no value.Code review summary
--jirawrites the samelinkedWorkItemthe Tasks → Jira flow writes; GitHub/GitLab/Linear links are untouched, and the flag is rejected onworktree createwhere clearing has no meaning.--jirais passed. Nothing added to any hot path.--jirasee nothing different.Notes
No platform-, remote- or agent-specific behavior. One deliberate choice worth flagging:
numberis set to0, since Jira keys are not numeric and the card rendersjiraIdentifier. That mirrors what the existing Jira-linked workspaces already store.X: @EugenioValeiras