Skip to content

feat(cli): link a Jira issue to a workspace with worktree set --jira - #11659

Closed
EugeValeiras wants to merge 2 commits into
stablyai:mainfrom
EugeValeiras:feat/worktree-set-jira
Closed

EugeValeiras wants to merge 2 commits into
stablyai:mainfrom
EugeValeiras:feat/worktree-set-jira

Conversation

@EugeValeiras

Copy link
Copy Markdown
Contributor

The gap

Almost all of this already exists:

Piece Status
WorkspaceLinkedItem with provider: 'jira' and jiraIdentifier ✅
getWorktreeCardJiraIssueDisplay → clickable pill on the card ✅
jira-issue card property ✅
worktree.set RPC accepting linkedWorkItem ✅
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. 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

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, 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 getWorktreeCardJiraIssueDisplay expects 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.ts and 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 once jira-issue is enabled as a card property.

✓ src/cli/  55 files  719 tests
✓ tsc -p config/tsconfig.node.json
✓ tsc -p config/tsconfig.tc.cli.json
✓ oxlint

Parser tests cover: bare key, lowercase key, full URL, null to clear, null rejected where clearing makes no sense, non-issue Jira URLs, and a flag passed with no value.

Code review summary

  • Cross-platform: none. Flag parsing plus two RPC calls; no paths, no shell, no platform branches.
  • SSH / remote / local: unaffected. Both calls go through the runtime client like every other CLI command, and Jira credentials are already runtime-side — nothing here assumes a local process or file.
  • Agents / integrations / providers: additive and provider-scoped. --jira writes the same linkedWorkItem the Tasks → Jira flow writes; GitHub/GitLab/Linear links are untouched, and the flag is rejected on worktree create where clearing has no meaning.
  • Performance: two extra requests, only when --jira is passed. Nothing added to any hot path.
  • UI: no visual change of its own — it populates data the card already knows how to render. Users who never pass --jira see nothing different.
  • Security: no new credential path; site resolution and lookup both go through the existing Jira client. A URL cannot point the lookup at an unconnected site — it only selects among already-connected ones, and errors otherwise.

Notes

No platform-, remote- or agent-specific behavior. One deliberate choice worth flagging: number is set to 0, since Jira keys are not numeric and the card renders jiraIdentifier. That mirrors what the existing Jira-linked workspaces already store.

X: @EugenioValeiras

@greptile-apps

greptile-apps Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR adds orca worktree set --jira <key|url|null> so users can attach a Jira ticket to an existing workspace from the CLI — the last missing piece for scripted/non-Tasks worktree flows. Resolution (title + URL) is fetched from the connected Jira site rather than typed by the caller, and site selection correctly delegates to the shared getMatchingJiraSites helper.

  • worktree-jira-issue-link.ts: New module handling flag parsing and async resolution; bare keys resolve against the active site, URLs pin their own site via getMatchingJiraSites, and null clears the link.
  • worktree-jira-issue-link.test.ts: Parser and site-matching tests, including an explicit regression test for the evil-host prefix-attack scenario.
  • worktree.ts / specs/core.ts / help.ts: Wires the new flag into the worktree set handler, usage string, allowedFlags, notes, and help text.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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

Comment thread src/cli/specs/core.ts Resolved
@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

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 Plus

Run ID: 9670eb09-b4f9-48b3-8833-df2750c57234

📥 Commits

Reviewing files that changed from the base of the PR and between aff26923653c48485636a22bc93aa9c53ee59d47 and cdb3a34.

📒 Files selected for processing (5)
  • src/cli/handlers/worktree-jira-issue-link.test.ts
  • src/cli/handlers/worktree-jira-issue-link.ts
  • src/cli/handlers/worktree.ts
  • src/cli/help.ts
  • src/cli/specs/core.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/cli/help.ts
  • src/cli/handlers/worktree-jira-issue-link.test.ts
  • src/cli/specs/core.ts
  • src/cli/handlers/worktree.ts
  • src/cli/handlers/worktree-jira-issue-link.ts

📝 Walkthrough

Walkthrough

Adds Jira issue-link support to worktree set. The CLI accepts Jira issue keys, Jira issue URLs, and null for clearing. It normalizes keys, preserves URL origins, validates input, selects a connected Jira site, and resolves the issue into a WorkspaceLinkedItem. The worktree request includes the resolved Jira link. Tests cover parsing, validation, and site selection. CLI help and specifications document the flag.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes adding Jira issue linking through the worktree set CLI command.
Description check ✅ Passed The description explains the change, usage, testing, review, security, platform impact, and follow-up scope, despite using alternate section headings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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 coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
src/cli/handlers/worktree-jira-issue-link.test.ts (1)

1-69: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for resolveJiraWorkItem.

This file tests getOptionalJiraIssueLinkFlag exhaustively but has no tests for resolveJiraWorkItem, which contains the non-trivial branching (clear, undefined input, active-site selection, origin-pinned selection, no-site error, issue-not-found error). A mocked RuntimeClient test covering the multi-site and no-active-site cases would also have caught the site-matching issues flagged in worktree-jira-issue-link.ts.

src/cli/specs/core.ts (2)

157-160: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add an example for --jira.

The examples array shows --linear-issue usage (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 the linear-issue and worktree create entries.

♻️ 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 win

Align the --jira placeholder notation between usage string and help text. src/cli/specs/core.ts documents --jira as <key-url-or-null> while src/cli/help.ts documents 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 match help.ts and 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 win

Move the present-but-empty string flag helper to a concrete shared module.

getPresentStringFlag is duplicated by getOptionalJiraIssueLinkFlag and getOptionalLinearIssueLinkFlag for the same semantics: required when present and reject empty/boolean values. getOptionalStringFlag uses different semantics, and getRequiredStringFlag is 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.ts
  • src/cli/handlers/worktree-jira-issue-link.ts
  • src/cli/handlers/worktree.ts
  • src/cli/help.ts
  • src/cli/specs/core.ts

Comment on lines 265 to +277
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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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" -C3

Repository: 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' -C2

Repository: 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 || true

Repository: 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/cli/handlers/worktree-jira-issue-link.test.ts (1)

75-91: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert forwarded call arguments in clientWith.

clientWith()'s call mock ignores its second parameter and always returns the same hardcoded issue payload, regardless of the key or siteId passed to jira.lookupIssueSummary. This means the site-matching tests confirm which site gets selected, but not that the correct site.id is actually forwarded to the lookup call. A regression that threads the wrong siteId through would still pass these tests.

Use vi.fn() to capture the call and assert the arguments for the jira.lookupIssueSummary call.

♻️ 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.ts
  • src/cli/handlers/worktree-jira-issue-link.ts
  • src/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

EugeValeiras and others added 2 commits July 31, 2026 18:43
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]>
@EugeValeiras
EugeValeiras force-pushed the feat/worktree-set-jira branch from aff2692 to cdb3a34 Compare July 31, 2026 21:46
@nwparker nwparker removed the P2 label Aug 19, 2026
nwparker added a commit that referenced this pull request Oct 14, 2026
Adapted-code-from: #11659 at cdb3a34
Co-authored-by: Eugenio Valeiras <[email protected]>
@EugeValeiras EugeValeiras closed this by deleting the head repository Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants