Skip to content

Commit f60aad2

Browse files
Copilotalexr00
andcommitted
Change approach: Add createInBrowser setting instead of UI button
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 8e48889 commit f60aad2

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@
349349
"default": "ask",
350350
"description": "%githubPullRequests.createOnPublishBranch.description%"
351351
},
352+
"githubPullRequests.createInBrowser": {
353+
"type": "boolean",
354+
"default": false,
355+
"description": "When true, the 'Create Pull Request' command opens GitHub in the browser instead of showing the create view in VS Code."
356+
},
352357
"githubPullRequests.commentExpandState": {
353358
"type": "string",
354359
"enum": [

src/common/settingKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type PullPRBranchVariants = 'never' | 'pull' | 'pullAndMergeBase' | 'pull
3939
export const UPSTREAM_REMOTE = 'upstreamRemote';
4040
export const DEFAULT_CREATE_OPTION = 'defaultCreateOption';
4141
export const CREATE_BASE_BRANCH = 'createDefaultBaseBranch';
42+
export const CREATE_IN_BROWSER = 'createInBrowser';
4243

4344
export const ISSUES_SETTINGS_NAMESPACE = 'githubIssues';
4445
export const ASSIGN_WHEN_WORKING = 'assignWhenWorking';

src/view/reviewManager.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,15 @@ export class ReviewManager extends Disposable {
11701170
}
11711171

11721172
public async createPullRequest(compareBranch?: string): Promise<void> {
1173+
// Check if user wants to create PR in browser
1174+
const createInBrowser = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>('createInBrowser', false);
1175+
1176+
if (createInBrowser) {
1177+
// Open browser to create PR instead of showing the create view
1178+
await this.openCreatePullRequestInBrowser(compareBranch);
1179+
return;
1180+
}
1181+
11731182
const postCreate = async (createdPR: PullRequestModel | undefined) => {
11741183
if (!createdPR) {
11751184
return;
@@ -1208,6 +1217,46 @@ export class ReviewManager extends Disposable {
12081217
return this._createPullRequestHelper.create(this._telemetry, this._context.extensionUri, this._folderRepoManager, compareBranch, postCreate);
12091218
}
12101219

1220+
private async openCreatePullRequestInBrowser(compareBranch?: string): Promise<void> {
1221+
try {
1222+
// Get the current branch
1223+
const branch = compareBranch
1224+
? await this._folderRepoManager.repository.getBranch(compareBranch)
1225+
: this._folderRepoManager.repository.state.HEAD;
1226+
1227+
if (!branch?.name) {
1228+
vscode.window.showErrorMessage(vscode.l10n.t('Unable to determine the current branch.'));
1229+
return;
1230+
}
1231+
1232+
// Get pull request defaults which includes the base branch
1233+
const pullRequestDefaults = await this._folderRepoManager.getPullRequestDefaults(branch);
1234+
1235+
// Get the origin to determine the repository
1236+
const compareOrigin = await this._folderRepoManager.getOrigin(branch);
1237+
1238+
// Find the GitHub repository for the base
1239+
const baseRepo = this._folderRepoManager.gitHubRepositories.find(
1240+
repo => repo.remote.owner === pullRequestDefaults.owner &&
1241+
repo.remote.repositoryName === compareOrigin.remote.repositoryName
1242+
);
1243+
1244+
if (!baseRepo) {
1245+
vscode.window.showErrorMessage(vscode.l10n.t('Unable to find repository to create pull request in.'));
1246+
return;
1247+
}
1248+
1249+
// Construct the GitHub URL
1250+
// Format: https://github.com/{owner}/{repo}/compare/{base}...{head}
1251+
const url = `${baseRepo.remote.normalizedHost}/${pullRequestDefaults.owner}/${compareOrigin.remote.repositoryName}/compare/${pullRequestDefaults.base}...${encodeURIComponent(branch.name)}`;
1252+
1253+
await vscode.env.openExternal(vscode.Uri.parse(url));
1254+
} catch (error) {
1255+
Logger.error(`Failed to open create pull request in browser: ${error}`, 'ReviewManager');
1256+
vscode.window.showErrorMessage(vscode.l10n.t('Failed to open create pull request in browser: {0}', formatError(error)));
1257+
}
1258+
}
1259+
12111260
public async openDescription(): Promise<void> {
12121261
const pullRequest = this._folderRepoManager.activePullRequest;
12131262
if (!pullRequest) {

0 commit comments

Comments
 (0)