Add Source Control Create PR flow (#5436)

* Add Source Control Create PR intent flow

Implements the Source Control Create PR flow described in docs/source-control-create-pr-flow.md.

* Keep Commit visible beside Create PR

* Fix Create PR partial staging action band

* Integrate hosted review creation into Create PR intent flow

- Automatically create the pull or merge request on GitHub/GitLab after
  successfully staging, committing, and pushing in the intent flow.
- Introduce a unified `updateCommitDrafts` helper to keep React state and
  its ref synchronized, preventing draft-overwrite race conditions.
- Split primary action tests into focused files to satisfy the ESLint
  `max-lines` rule.
- Replace hardcoded "Local Mac" strings with dynamic host labels.

* Support Azure DevOps and Gitea PR creation and limit large diffs

Implement automated pull request creation for Azure DevOps and Gitea
repositories. This includes REST API integration, credential checks via
environment variables, template support, and error classification.

Additionally, introduce limits on large diff payloads in git status
extraction to prevent renderer-freezing performance bottlenecks when
loading extremely large files.

* Skip source control refetches when PR creation intent is in flight

Avoid recomputing branch eligibility while isCreatePrIntentInFlight is true.
This prevents tearing down the PR composer or rotating dropdown hints
prematurely if ahead/behind or dirty states are temporarily perturbed
temporarily perturbed mid-flow.

* Expose manual prerequisite actions next to Create PR button

Previously, the Create PR intent only supported "Stage All" as a
sibling action. This expands prerequisite resolution to handle other
intermediate steps such as committing, publishing, and pushing
(including force pushing).

This ensures the edit-commit-push-review loop remains streamlined
directly within the CommitArea by displaying the specific required
next action beside the primary Create PR button.

* Move PR creation actions from CommitArea to sidebar header

- Decouples PR creation and PR intent actions from the local commit area
  primary button, ensuring local/remote git actions remain primary.
- Renders a dedicated PR creation button in the source control header
  beside the hosted review status.
- Simplifies CommitArea by removing prerequisite split-button rendering
  and review composer logic.

* Delete source control create PR flow design document

Remove the design document for the source control create PR flow as the feature has been successfully implemented.

* Display PR creation errors in inline notice

Unify PR/review creation error reporting by replacing the duplicate
createPrErrors state with the shared createPrIntentNotice. Validation
and API errors are now shown directly within the visible inline alert
notice to improve layout consistency and visibility.

Also refactor the execution host platform label lookup to use simple
if statements instead of a switch block.

* Improve Create PR intent flow safety and provider awareness

- Integrate the hosted review composer directly into the Source Control
  panel when a direct review creation action is available.
- Abort the in-flight PR creation intent flow early if the current git
  branch changes to prevent staging or committing on the wrong target.
- Keep in-flight action labels provider-aware (e.g., "Create MR" on GitLab)
  by passing hosted review inputs to the action resolver.
- Omit large diff text payloads from git status responses when line counts
  exceed safe rendering limits to avoid UI performance degradation.
- Ensure field generation does not retarget the base branch of a PR/MR without
  explicit user confirmation.

* Preserve PR and MR templates in AI pull request generation

- Preload templates (including GitLab merge requests) into the AI
  context before generation to prevent bypassing provider-side fallbacks.
- Instruct the AI generator to fill out and preserve existing template
  headings, required sections, and checklists instead of deleting them.
- Pass provider and template settings from the renderer to the backend
  RPC and runtime handlers.

* Mock DropdownMenuShortcut in tab-title-tooltip test

Add a mock for the DropdownMenuShortcut component in the dropdown menu
mock to prevent test failures.
This commit is contained in:
Jinjing
2026-06-16 15:36:27 -07:00
committed by GitHub
parent ca05dbf652
commit a300e2c7b4
64 changed files with 4161 additions and 528 deletions
+5 -3
View File
@@ -1,8 +1,10 @@
import { describe, expect, it } from 'vitest'
import { getExecutionHostLabel } from './execution-host'
import { MIN_COMPATIBLE_RUNTIME_SERVER_VERSION, RUNTIME_PROTOCOL_VERSION } from './protocol-version'
import { getLocalExecutionHostLabel } from './execution-host'
import { buildExecutionHostRegistry } from './execution-host-registry'
const LOCAL_HOST_LABEL = getExecutionHostLabel('local')
describe('execution host registry', () => {
it('returns only the local host for local-only state', () => {
expect(
@@ -14,7 +16,7 @@ describe('execution host registry', () => {
{
id: 'local',
kind: 'local',
label: getLocalExecutionHostLabel(),
label: LOCAL_HOST_LABEL,
detail: 'This computer',
health: 'local'
}
@@ -189,7 +191,7 @@ describe('execution host registry', () => {
})
expect(hosts).toMatchObject([
{ id: 'local', label: getLocalExecutionHostLabel() },
{ id: 'local', label: LOCAL_HOST_LABEL },
{ id: 'ssh:repo-ssh', label: 'Derived SSH' }
])
})
+6
View File
@@ -71,4 +71,10 @@ describe('execution host identity', () => {
'runtime:runtime-1'
)
})
it('labels local execution hosts by platform', () => {
expect(getLocalExecutionHostLabel('darwin')).toBe('Local Mac')
expect(getLocalExecutionHostLabel('linux')).toBe('Local Linux')
expect(getLocalExecutionHostLabel('win32')).toBe('Local Windows')
})
})
+30 -31
View File
@@ -13,42 +13,41 @@ export type ParsedExecutionHost =
| { kind: 'ssh'; id: `ssh:${string}`; targetId: string }
| { kind: 'runtime'; id: `runtime:${string}`; environmentId: string }
function getCurrentLocalPlatform(): NodeJS.Platform | null {
const globalNavigator = (globalThis as { navigator?: { userAgent?: string; platform?: string } })
.navigator
const userAgent = globalNavigator?.userAgent || globalNavigator?.platform || ''
if (/Windows/i.test(userAgent)) {
return 'win32'
}
if (/Mac/i.test(userAgent)) {
return 'darwin'
}
if (/Linux|X11/i.test(userAgent)) {
return 'linux'
}
return typeof process === 'undefined' ? null : process.platform
}
export function getLocalExecutionHostLabel(platform: NodeJS.Platform | null = null): string {
const localPlatform = platform ?? getCurrentLocalPlatform()
if (localPlatform === 'darwin') {
return 'Local Mac'
}
if (localPlatform === 'win32') {
return 'Local Windows'
}
if (localPlatform === 'linux') {
return 'Local Linux'
}
return 'This computer'
}
function normalizeHostPart(value: string | null | undefined): string | null {
const trimmed = value?.trim()
return trimmed ? trimmed : null
}
function getCurrentHostPlatform(): string {
if (typeof process !== 'undefined' && typeof process.platform === 'string') {
return process.platform
}
if (typeof navigator !== 'undefined') {
if (navigator.userAgent.includes('Windows')) {
return 'win32'
}
if (navigator.userAgent.includes('Linux')) {
return 'linux'
}
if (navigator.userAgent.includes('Mac')) {
return 'darwin'
}
}
return ''
}
export function getLocalExecutionHostLabel(platform = getCurrentHostPlatform()): string {
switch (platform) {
case 'darwin':
return 'Local Mac'
case 'win32':
return 'Local Windows'
case 'linux':
return 'Local Linux'
default:
return 'This computer'
}
}
export function toSshExecutionHostId(targetId: string): `ssh:${string}` {
return `ssh:${encodeURIComponent(targetId)}`
}
@@ -0,0 +1,20 @@
import type { HostedReviewProvider } from './hosted-review'
export type HostedReviewCreationProvider = 'github' | 'gitlab' | 'azure-devops' | 'gitea'
export function supportsHostedReviewCreation(
provider: HostedReviewProvider | null | undefined
): provider is HostedReviewCreationProvider {
return (
provider === 'github' ||
provider === 'gitlab' ||
provider === 'azure-devops' ||
provider === 'gitea'
)
}
export function resolveHostedReviewCreationProvider(
provider: HostedReviewProvider | null | undefined
): HostedReviewCreationProvider {
return supportsHostedReviewCreation(provider) ? provider : 'github'
}
@@ -27,6 +27,19 @@ describe('buildPullRequestFieldsPrompt', () => {
expect(prompt).toContain('Additional user prompt:')
expect(prompt).toContain('Use conventional PR titles.')
})
it('tells the agent to preserve existing review templates', () => {
const prompt = buildPullRequestFieldsPrompt(
{
...context,
currentBody: '## Summary\n\n## Testing\n\n- [ ] Required checks'
},
''
)
expect(prompt).toContain('preserve its headings, required sections, and checklists')
expect(prompt).toContain('Leave genuinely unknown template items as TODO or unchecked')
})
})
describe('parseGeneratedPullRequestFields', () => {
+2
View File
@@ -41,6 +41,8 @@ export function buildPullRequestFieldsPrompt(
'- Keep the base branch as the current base unless the diff clearly targets a different branch.',
'- Title: concise, specific, no trailing period.',
'- Body: useful Markdown summary for reviewers. Include testing notes only when evidence exists.',
'- If Current description contains a pull request or merge request template, preserve its headings, required sections, and checklists while filling relevant sections from the branch changes.',
'- Leave genuinely unknown template items as TODO or unchecked instead of deleting them.',
'- draft: true only when the changes clearly look unfinished, WIP, or unsafe to review.',
'- Do not include labels, reviewers, code fences, prose, or any keys beyond base/title/body/draft.',
'',