Skip to content

Add {linkedIssue} template variable for commit and PR generation - #10640

Merged
AmethystLiang merged 6 commits into
mainfrom
gh-commit-should-contain-gh-issue
Jul 26, 2026
Merged

AmethystLiang merged 6 commits into
mainfrom
gh-commit-should-contain-gh-issue

Conversation

@AmethystLiang

Copy link
Copy Markdown
Contributor

Summary

Adds support for the {linkedIssue} recipe variable in commit message and pull request generation templates. This allows users to reference the GitHub issue linked to a workspace in their custom agent prompts (e.g., Fixes #{linkedIssue}).

Implementation Details

  • New modules: source-control-ai-linked-issue.ts resolves the workspace-linked GitHub issue by validating worktree ID against the request path, supporting both local and SSH cases
  • Live metadata read: Uses getWorktreeLinkedIssue() in the runtime to read fresh linked-issue state, bypassing the short-TTL resolved-worktree cache
  • Template substitution: {linkedIssue} expands to the issue number or empty string when unlinked; only available for commit message and PR templates, not branch names or launch actions
  • Workspace previews: The variable chips now show workspace-specific previews alongside the generic description, clarifying that bare Fixes #{linkedIssue} degrades to Fixes # when unlinked

Cross-Platform Support

  • SSH remote paths are compared as raw POSIX strings from Windows hosts (no path rewriting)
  • Local paths use normalized comparisons with platform-aware case-folding on Windows
  • Validation works for folder-repo workspace instances (keeps ::workspace:<uuid> suffix in meta key)

Testing

  • Unit tests cover validation guard (path matching, repoId cross-check, folder-workspace suffix handling)
  • Integration test verifies live metadata freshness (linked/unlinked state changes are reflected immediately)
  • E2E tests for both commit and PR templates (substitution with linked issue, empty expansion when unlinked)
  • Template chip tests verify workspace previews display correctly alongside descriptions

Notes

  • Resolves linked issue from live store metadata, not cached worktree projections, to prevent stale reads
  • Renderer-supplied worktreeId is validated against request path before meta read (cheap defense-in-depth for independent callers: relay, CLI, future in-process)
  • GitHub-only in v1 (no fallback to GitLab-linked issues)

AmethystLiang and others added 5 commits July 25, 2026 12:53
… and PR prompts

Custom commit-message and pull-request recipes can now reference the GitHub
issue linked to the workspace, so a template like "Fixes #{linkedIssue}" lands
the closing trailer without the user retyping the number.

- register `linkedIssue` on the commitMessage and pullRequest actions only,
  with the VARIABLE_INFO entry the chip hover card requires
- substitute unconditionally via `formatLinkedIssueTemplateValue` (empty string
  when nothing resolves) so the token never survives into a prompt; enrich the
  draft context conditionally via `withLinkedIssueDraftContext` so unlinked
  workspaces keep their existing context shape
- attach at the 7 call boundaries (runtime commit x2, runtime PR shared, IPC
  commit x2, IPC PR x2); the pure git gather stays pure
- validate the renderer-supplied worktreeId against the request path and repoId
  before any meta read, comparing SSH paths as raw strings so a Windows host
  cannot rewrite a remote POSIX path
- built-in prompts are unchanged; no GitLab dual-read and no default trailer
…ings

Addresses 13 of the 14 findings from the {linkedIssue} code review
(6 minor, 8 nit, 0 critical, 0 major); Issue 5 (GitLab provider naming)
is deferred to design Open Question 3 as product expansion.

Behavior:
- Dialog previews the workspace's real linked issue instead of the
  synthetic 123, in both the chip hover card and the plan preview, so an
  unlinked workspace previews the `Fixes #` it will actually generate.
  Settings dry-runs stay fully synthetic.
- Reject non-positive, fractional and unsafe-integer issue numbers at the
  IPC resolver via a shared isLinkedIssueNumber predicate, so corrupt meta
  never reaches a draft context (previously -7 rendered `Fixes #-7` and
  1e21 rendered `Fixes #1e+21`).
- Fail closed on an empty-string repoId instead of skipping the cross-check.

Structure:
- Split the variable registry into source-control-ai-action-variables.ts
  and re-export it, restoring max-lines headroom with no consumer churn
  and no lint disable.
- Constrain withLinkedIssueDraftContext to contexts declaring linkedIssue.
- Move the misplaced shared imports into their import group.

Docs and tests:
- Document that the IPC id/path validator guards relay/CLI/future callers,
  not the renderer (whose path is id-derived), and rename the three tests
  that read as proof of a protection that cannot fire.
- Add PR-side coverage that was missing: three git:generatePullRequestFields
  handler tests, a built-in PR prompt no-leak guard, and the runtime PR
  unlinked case.
- Replace the coincidental '42' assertion with a fixture-unique sentinel.
- Type the runtime worktree fixture with satisfies, which surfaced and
  fixed pre-existing drift in its git sub-object.
- Add an e2e case covering the preload -> main -> meta -> template chain.

Co-authored-by: Orca <[email protected]>
…indings

Addresses all 8 findings from the {linkedIssue} code re-review
(2 minor, 6 nit, 0 critical, 0 major); none deferred.

Behavior:
- Revert the variableOverrides parameter on planSourceControlTextGeneration.
  Its result is a Save/Generate gate, not a preview, and the recipe it
  validates is saved repo- or globally scoped -- so rendering it against the
  active workspace disabled both buttons with "Command input is empty." for a
  {linkedIssue}-only template on any unlinked workspace, blocking a global
  settings write. Validation is synthetic again; chip previews are unchanged.
- Make the chip hover card additive instead of either/or. A supplied preview
  now appends a "This workspace" sample below the description and Example
  rather than replacing them, so the GitLab-empty and dangling `Fixes #`
  warning survives on the two dialogs where recipes are actually authored.
  basePrompt keeps its preview-only shape, where the preview is the content.

Structure:
- Drop the registry re-export from source-control-ai-actions.ts and move the
  last two consumers onto source-control-ai-action-variables, so one import
  path per symbol keeps a grep of the registry's consumers complete.
- Split the registry/helper suites into source-control-ai-action-variables.test.ts
  so each test file mirrors its module.

Tests:
- Cover the Save/Generate gate at the canRunGeneration level for a bare
  {linkedIssue} recipe on linked and unlinked workspaces, with a negative
  control proving the buttons can still be disabled.
- Cover the chip hover card directly; the dialog tests mock it away.
- Guard the PR mismatched-id test with toHaveLength(1) so it cannot pass
  vacuously on an unrelated early return.
- Add an unlinked-workspace e2e case (saw-issue:empty), which is what
  distinguishes a real resolver from one that always returns a number.
  Spec now runs green: 3 passed.
- Rename the dialog test that claimed a synthetic-fallback assertion it did
  not make, and route its renders through one shared helper.

Docs are worktree-local (.gitignore:84 ignores docs/**): the design doc's
plan-preview and chip-surface claims, the manual QA rows, and both reviews'
statements about pre-existing PR-handler tests are corrected there.
…est falsifiable

The e2e unlinked case extracted the echoed issue with `ORCA_E2E_ISSUE=(\d*)`,
which matches zero digits in front of an unexpanded `{linkedIssue}` and reported
it as `empty` — so the case that exists to catch a literal token surviving into
a prompt passed on exactly that regression. Capture the whole line instead: a
literal now arrives as `saw-issue:{linkedIssue}` and fails, verified by dropping
the substitution key for unlinked contexts and watching the case go red.

Also drop the inert `not.toContain('Command input is empty.')` assertion — that
copy is click-driven `generationError` state and this suite renders statically,
so it could never fail; the claim it reached for is carried by the plan test.
Rename two plan tests off the "plan preview" framing the design now rejects.

Local review artifacts (design doc, implementation notes, final review) were
swept to match the tree in the same pass; they are gitignored here.
Resolved worktrees are cached for a second, causing commit and PR
generation to use stale linked-issue state. Hosts now implement
getWorktreeLinkedIssue to provide fresh issue metadata by worktree id,
with proper fallback for unlinked workspaces. Updates both commit
message and PR field generation paths; includes integration and e2e
coverage.
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6bb72d75-e934-4ad5-afcb-8a74d070e226

📥 Commits

Reviewing files that changed from the base of the PR and between f405e68 and dba35c7.

📒 Files selected for processing (8)
  • src/main/ipc/filesystem.test.ts
  • src/main/runtime/orca-runtime-git.test.ts
  • src/main/runtime/orca-runtime-git.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/components/right-sidebar/SourceControlTextGenerationDialog.test.ts
  • tests/e2e/helpers/source-control-ai-generators.ts
  • tests/e2e/source-control-commit-message-ai.spec.ts
  • tests/e2e/source-control-pr-linked-issue-ai.spec.ts

📝 Walkthrough

Walkthrough

Adds linked issue context to Source Control AI commit-message and pull-request generation. Worktree metadata is validated and propagated through IPC and runtime paths, including local and SSH flows. Templates now substitute linked issue values, while dialogs display workspace previews. Shared contracts, resolver logic, runtime freshness, renderer behavior, unit tests, integration tests, and end-to-end scenarios are expanded accordingly.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change well, but it omits required template sections for Screenshots, AI Review Report, and Security Audit. Add the missing template sections, including Screenshots (or "No visual change"), AI Review Report, and Security Audit, and complete the Testing checklist.
Docstring Coverage ⚠️ Warning Docstring coverage is 34.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding the {linkedIssue} template variable for commit and PR generation.
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.
✨ 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 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 (2)
src/renderer/src/components/right-sidebar/SourceControlTextGenerationDialog.test.ts (1)

113-115: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Condense the test-rationale comments.

Reduce these to one-line, non-obvious rationale comments where needed.

  • src/renderer/src/components/right-sidebar/SourceControlTextGenerationDialog.test.ts#L113-L115: condense the preview rationale.
  • src/renderer/src/components/right-sidebar/SourceControlTextGenerationDialog.test.ts#L164-L165: condense the generation-gating rationale.
  • src/renderer/src/components/right-sidebar/SourceControlTextGenerationDialog.test.ts#L175-L176: condense the static-markup assertion rationale.
  • src/renderer/src/components/right-sidebar/SourceControlTextGenerationDialog.test.ts#L183-L184: condense the negative-control rationale.

Based on coding guidelines: “Comments must be concise, limited to non-obvious information, and preferably one line.”

Source: Coding guidelines

tests/e2e/source-control-commit-message-ai.spec.ts (1)

43-63: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Verify the generator script writer isn't duplicated across specs.

writeLinkedIssueEchoGenerator here and writeLinkedIssuePrEchoGenerator in tests/e2e/source-control-pr-linked-issue-ai.spec.ts share the same stdin-capture and ORCA_E2E_ISSUE extraction logic, differing only in the emitted payload. Consider extracting a single writer (e.g. in tests/e2e/helpers/source-control-ai-generation.ts) that takes an output-formatting snippet.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9ad1b08b-53f1-45ed-ac04-629f7e1f37cb

📥 Commits

Reviewing files that changed from the base of the PR and between c4b7aed and f405e68.

📒 Files selected for processing (35)
  • src/main/ipc/filesystem.test.ts
  • src/main/ipc/filesystem.ts
  • src/main/ipc/source-control-ai-linked-issue.test.ts
  • src/main/ipc/source-control-ai-linked-issue.ts
  • src/main/runtime/orca-runtime-git.test.ts
  • src/main/runtime/orca-runtime-git.ts
  • src/main/runtime/orca-runtime-linked-issue-live-meta.integration.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/text-generation/commit-message-text-generation.test.ts
  • src/main/text-generation/commit-message-text-generation.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/right-sidebar/SourceControl.tsx
  • src/renderer/src/components/right-sidebar/SourceControlTextGenerationDialog.test.ts
  • src/renderer/src/components/right-sidebar/SourceControlTextGenerationDialog.tsx
  • src/renderer/src/components/right-sidebar/SourceControlTextGenerationDialogForm.tsx
  • src/renderer/src/components/source-control/SourceControlActionVariableChips.test.tsx
  • src/renderer/src/components/source-control/SourceControlActionVariableChips.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/source-control-generation-plan.test.ts
  • src/renderer/src/lib/source-control-generation-plan.ts
  • src/renderer/src/runtime/runtime-git-client.test.ts
  • src/renderer/src/runtime/runtime-git-client.ts
  • src/shared/commit-message-generation.ts
  • src/shared/pull-request-generation.ts
  • src/shared/source-control-ai-action-variables.test.ts
  • src/shared/source-control-ai-action-variables.ts
  • src/shared/source-control-ai-actions.test.ts
  • src/shared/source-control-ai-actions.ts
  • tests/e2e/source-control-commit-message-ai.spec.ts
  • tests/e2e/source-control-pr-linked-issue-ai.spec.ts

Comment thread src/main/ipc/filesystem.test.ts Resolved
Comment thread src/main/runtime/orca-runtime.ts Resolved
Return undefined from getWorktreeLinkedIssue when live metadata cannot be read
(store not ready), distinguishing it from null (unlinked). The caller now falls
back to the cached worktree value instead of treating unavailable as unlinked.

Also extract the linked-issue echo generator as a shared e2e test helper.
@AmethystLiang
AmethystLiang merged commit ca70be8 into main Jul 26, 2026
5 of 6 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…blyai#10640)

* feat(source-control-ai): add {linkedIssue} recipe variable for commit and PR prompts

Custom commit-message and pull-request recipes can now reference the GitHub
issue linked to the workspace, so a template like "Fixes #{linkedIssue}" lands
the closing trailer without the user retyping the number.

- register `linkedIssue` on the commitMessage and pullRequest actions only,
  with the VARIABLE_INFO entry the chip hover card requires
- substitute unconditionally via `formatLinkedIssueTemplateValue` (empty string
  when nothing resolves) so the token never survives into a prompt; enrich the
  draft context conditionally via `withLinkedIssueDraftContext` so unlinked
  workspaces keep their existing context shape
- attach at the 7 call boundaries (runtime commit x2, runtime PR shared, IPC
  commit x2, IPC PR x2); the pure git gather stays pure
- validate the renderer-supplied worktreeId against the request path and repoId
  before any meta read, comparing SSH paths as raw strings so a Windows host
  cannot rewrite a remote POSIX path
- built-in prompts are unchanged; no GitLab dual-read and no default trailer

* fix(source-control-ai): resolve {linkedIssue} adversarial review findings

Addresses 13 of the 14 findings from the {linkedIssue} code review
(6 minor, 8 nit, 0 critical, 0 major); Issue 5 (GitLab provider naming)
is deferred to design Open Question 3 as product expansion.

Behavior:
- Dialog previews the workspace's real linked issue instead of the
  synthetic 123, in both the chip hover card and the plan preview, so an
  unlinked workspace previews the `Fixes #` it will actually generate.
  Settings dry-runs stay fully synthetic.
- Reject non-positive, fractional and unsafe-integer issue numbers at the
  IPC resolver via a shared isLinkedIssueNumber predicate, so corrupt meta
  never reaches a draft context (previously -7 rendered `Fixes #-7` and
  1e21 rendered `Fixes #1e+21`).
- Fail closed on an empty-string repoId instead of skipping the cross-check.

Structure:
- Split the variable registry into source-control-ai-action-variables.ts
  and re-export it, restoring max-lines headroom with no consumer churn
  and no lint disable.
- Constrain withLinkedIssueDraftContext to contexts declaring linkedIssue.
- Move the misplaced shared imports into their import group.

Docs and tests:
- Document that the IPC id/path validator guards relay/CLI/future callers,
  not the renderer (whose path is id-derived), and rename the three tests
  that read as proof of a protection that cannot fire.
- Add PR-side coverage that was missing: three git:generatePullRequestFields
  handler tests, a built-in PR prompt no-leak guard, and the runtime PR
  unlinked case.
- Replace the coincidental '42' assertion with a fixture-unique sentinel.
- Type the runtime worktree fixture with satisfies, which surfaced and
  fixed pre-existing drift in its git sub-object.
- Add an e2e case covering the preload -> main -> meta -> template chain.

Co-authored-by: Orca <[email protected]>

* fix(source-control-ai): resolve {linkedIssue} adversarial re-review findings

Addresses all 8 findings from the {linkedIssue} code re-review
(2 minor, 6 nit, 0 critical, 0 major); none deferred.

Behavior:
- Revert the variableOverrides parameter on planSourceControlTextGeneration.
  Its result is a Save/Generate gate, not a preview, and the recipe it
  validates is saved repo- or globally scoped -- so rendering it against the
  active workspace disabled both buttons with "Command input is empty." for a
  {linkedIssue}-only template on any unlinked workspace, blocking a global
  settings write. Validation is synthetic again; chip previews are unchanged.
- Make the chip hover card additive instead of either/or. A supplied preview
  now appends a "This workspace" sample below the description and Example
  rather than replacing them, so the GitLab-empty and dangling `Fixes #`
  warning survives on the two dialogs where recipes are actually authored.
  basePrompt keeps its preview-only shape, where the preview is the content.

Structure:
- Drop the registry re-export from source-control-ai-actions.ts and move the
  last two consumers onto source-control-ai-action-variables, so one import
  path per symbol keeps a grep of the registry's consumers complete.
- Split the registry/helper suites into source-control-ai-action-variables.test.ts
  so each test file mirrors its module.

Tests:
- Cover the Save/Generate gate at the canRunGeneration level for a bare
  {linkedIssue} recipe on linked and unlinked workspaces, with a negative
  control proving the buttons can still be disabled.
- Cover the chip hover card directly; the dialog tests mock it away.
- Guard the PR mismatched-id test with toHaveLength(1) so it cannot pass
  vacuously on an unrelated early return.
- Add an unlinked-workspace e2e case (saw-issue:empty), which is what
  distinguishes a real resolver from one that always returns a number.
  Spec now runs green: 3 passed.
- Rename the dialog test that claimed a synthetic-fallback assertion it did
  not make, and route its renders through one shared helper.

Docs are worktree-local (.gitignore:84 ignores docs/**): the design doc's
plan-preview and chip-surface claims, the manual QA rows, and both reviews'
statements about pre-existing PR-handler tests are corrected there.

* fix(source-control-ai): make the {linkedIssue} e2e guard and dialog test falsifiable

The e2e unlinked case extracted the echoed issue with `ORCA_E2E_ISSUE=(\d*)`,
which matches zero digits in front of an unexpanded `{linkedIssue}` and reported
it as `empty` — so the case that exists to catch a literal token surviving into
a prompt passed on exactly that regression. Capture the whole line instead: a
literal now arrives as `saw-issue:{linkedIssue}` and fails, verified by dropping
the substitution key for unlinked contexts and watching the case go red.

Also drop the inert `not.toContain('Command input is empty.')` assertion — that
copy is click-driven `generationError` state and this suite renders statically,
so it could never fail; the claim it reached for is carried by the plan test.
Rename two plan tests off the "plan preview" framing the design now rejects.

Local review artifacts (design doc, implementation notes, final review) were
swept to match the tree in the same pass; they are gitignored here.

* Resolve {linkedIssue} from live metadata, not cache

Resolved worktrees are cached for a second, causing commit and PR
generation to use stale linked-issue state. Hosts now implement
getWorktreeLinkedIssue to provide fresh issue metadata by worktree id,
with proper fallback for unlinked workspaces. Updates both commit
message and PR field generation paths; includes integration and e2e
coverage.

* Keep cached linkedIssue when metadata is unavailable

Return undefined from getWorktreeLinkedIssue when live metadata cannot be read
(store not ready), distinguishing it from null (unlinked). The caller now falls
back to the cached worktree value instead of treating unavailable as unlinked.

Also extract the linked-issue echo generator as a shared e2e test helper.

---------

Co-authored-by: Orca <[email protected]>
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.

1 participant