diff --git a/package.json b/package.json index 121adffe67..261a71aebd 100644 --- a/package.json +++ b/package.json @@ -349,6 +349,11 @@ "default": "ask", "description": "%githubPullRequests.createOnPublishBranch.description%" }, + "githubPullRequests.createInBrowser": { + "type": "boolean", + "default": false, + "description": "When true, the 'Create Pull Request' command opens GitHub in the browser instead of showing the create view in VS Code." + }, "githubPullRequests.commentExpandState": { "type": "string", "enum": [ diff --git a/src/@types/vscode.proposed.chatParticipantAdditions.d.ts b/src/@types/vscode.proposed.chatParticipantAdditions.d.ts index 71520fa1ec..aa7001a3d2 100644 --- a/src/@types/vscode.proposed.chatParticipantAdditions.d.ts +++ b/src/@types/vscode.proposed.chatParticipantAdditions.d.ts @@ -105,6 +105,7 @@ declare module 'vscode' { isComplete?: boolean; toolSpecificData?: ChatTerminalToolInvocationData; fromSubAgent?: boolean; + presentation?: 'hidden' | 'hiddenAfterComplete' | undefined; constructor(toolName: string, toolCallId: string, isError?: boolean); } diff --git a/src/common/settingKeys.ts b/src/common/settingKeys.ts index 1376c4c7bc..9d26fc0010 100644 --- a/src/common/settingKeys.ts +++ b/src/common/settingKeys.ts @@ -39,6 +39,7 @@ export type PullPRBranchVariants = 'never' | 'pull' | 'pullAndMergeBase' | 'pull export const UPSTREAM_REMOTE = 'upstreamRemote'; export const DEFAULT_CREATE_OPTION = 'defaultCreateOption'; export const CREATE_BASE_BRANCH = 'createDefaultBaseBranch'; +export const CREATE_IN_BROWSER = 'createInBrowser'; export const ISSUES_SETTINGS_NAMESPACE = 'githubIssues'; export const ASSIGN_WHEN_WORKING = 'assignWhenWorking'; diff --git a/src/view/reviewManager.ts b/src/view/reviewManager.ts index b9c31fac14..c183f0bd47 100644 --- a/src/view/reviewManager.ts +++ b/src/view/reviewManager.ts @@ -24,6 +24,7 @@ import Logger from '../common/logger'; import { parseRepositoryRemotes, Remote } from '../common/remote'; import { COMMENTS, + CREATE_IN_BROWSER, FOCUSED_MODE, IGNORE_PR_BRANCHES, NEVER_IGNORE_DEFAULT_BRANCH, @@ -1170,6 +1171,15 @@ export class ReviewManager extends Disposable { } public async createPullRequest(compareBranch?: string): Promise { + // Check if user wants to create PR in browser + const createInBrowser = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get(CREATE_IN_BROWSER, false); + + if (createInBrowser) { + // Open browser to create PR instead of showing the create view + await this.openCreatePullRequestInBrowser(compareBranch); + return; + } + const postCreate = async (createdPR: PullRequestModel | undefined) => { if (!createdPR) { return; @@ -1208,6 +1218,48 @@ export class ReviewManager extends Disposable { return this._createPullRequestHelper.create(this._telemetry, this._context.extensionUri, this._folderRepoManager, compareBranch, postCreate); } + private async openCreatePullRequestInBrowser(compareBranch?: string): Promise { + try { + // Get the current branch + const branch = compareBranch + ? await this._folderRepoManager.repository.getBranch(compareBranch) + : this._folderRepoManager.repository.state.HEAD; + + if (!branch?.name) { + vscode.window.showErrorMessage(vscode.l10n.t('Unable to determine the current branch.')); + return; + } + + // Get pull request defaults which includes the base branch + const pullRequestDefaults = await this._folderRepoManager.getPullRequestDefaults(branch); + + // Get the origin to determine the repository + const compareOrigin = await this._folderRepoManager.getOrigin(branch); + + // Find the GitHub repository for the base + // Note: pullRequestDefaults.owner is the target owner (may differ from current fork) + // compareOrigin.remote.repositoryName is the repository we're working in + const baseRepo = this._folderRepoManager.gitHubRepositories.find( + repo => repo.remote.owner === pullRequestDefaults.owner && + repo.remote.repositoryName === compareOrigin.remote.repositoryName + ); + + if (!baseRepo) { + vscode.window.showErrorMessage(vscode.l10n.t('Unable to find repository to create pull request in.')); + return; + } + + // Construct the GitHub URL + // Format: https://github.com/{owner}/{repo}/compare/{base}...{head} + const url = `${baseRepo.remote.normalizedHost}/${pullRequestDefaults.owner}/${compareOrigin.remote.repositoryName}/compare/${pullRequestDefaults.base}...${encodeURIComponent(branch.name)}`; + + await vscode.env.openExternal(vscode.Uri.parse(url)); + } catch (error) { + Logger.error(`Failed to open create pull request in browser: ${error}`, 'ReviewManager'); + vscode.window.showErrorMessage(vscode.l10n.t('Failed to open create pull request in browser: {0}', formatError(error))); + } + } + public async openDescription(): Promise { const pullRequest = this._folderRepoManager.activePullRequest; if (!pullRequest) {