Skip to content

Commit 534c04f

Browse files
Copilotalexr00
andcommitted
Add "Create in Browser" button to PR creation view
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 7454f19 commit 534c04f

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/github/createPRViewProvider.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,29 @@ export abstract class BaseCreatePullRequestViewProvider<T extends BasePullReques
505505
return this._replyMessage(message, undefined);
506506
}
507507

508+
private async openCreateInBrowser(): Promise<void> {
509+
// Get the base repository info
510+
const baseRepo = this.getBaseGitHubRepo();
511+
if (!baseRepo) {
512+
vscode.window.showErrorMessage(vscode.l10n.t('Unable to find repository to create pull request in.'));
513+
return;
514+
}
515+
516+
// Get the compare branch name - this is the branch we want to create a PR from
517+
const compareBranch = this._defaultCompareBranch;
518+
if (!compareBranch) {
519+
vscode.window.showErrorMessage(vscode.l10n.t('Unable to determine branch to create pull request from.'));
520+
return;
521+
}
522+
523+
// Construct the GitHub URL for creating a PR
524+
// Format: https://github.com/{owner}/{repo}/pull/new/{branch}
525+
// or https://github.com/{owner}/{repo}/compare/{base}...{head} for cross-repo PRs
526+
const url = `${baseRepo.remote.url}/pull/new/${compareBranch}`;
527+
528+
await vscode.env.openExternal(vscode.Uri.parse(url));
529+
}
530+
508531
protected override async _onDidReceiveMessage(message: IRequestMessage<any>) {
509532
const result = await super._onDidReceiveMessage(message);
510533
if (result !== this.MESSAGE_UNHANDLED) {
@@ -539,6 +562,9 @@ export abstract class BaseCreatePullRequestViewProvider<T extends BasePullReques
539562
case 'pr.removeLabel':
540563
return this.removeLabel(message);
541564

565+
case 'pr.openCreateInBrowser':
566+
return this.openCreateInBrowser();
567+
542568
default:
543569
return this.MESSAGE_UNHANDLED;
544570
}
@@ -1342,4 +1368,4 @@ export class CreatePullRequestViewProvider extends BaseCreatePullRequestViewProv
13421368
vscode.window.showErrorMessage('Unsupported webview message');
13431369
}
13441370
}
1345-
}
1371+
}

webviews/common/createContextNew.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ export class CreatePRContextNew {
9797
return this.postMessage({ command: 'pr.cancelCreate', args });
9898
};
9999

100+
public openCreateInBrowser = (): Promise<void> => {
101+
return this.postMessage({ command: 'pr.openCreateInBrowser' });
102+
};
103+
100104
public updateState = (params: Partial<CreateParamsNew>, reset: boolean = false): void => {
101105
this.createParams = reset ? { ...defaultCreateParams, ...params } : { ...this.createParams, ...params };
102106
vscode.setState(this.createParams);

webviews/createPullRequestViewNew/app.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ export function main() {
354354
Cancel
355355
</button>
356356

357+
<button disabled={isBusy || !ctx.initialized} className='secondary' onClick={() => ctx.openCreateInBrowser()} title='Create pull request on GitHub.com'>
358+
Create in Browser
359+
</button>
360+
357361
<ContextDropdown optionsContext={() => makeCreateMenuContext(params)}
358362
defaultAction={onCreateButton}
359363
defaultOptionLabel={() => createMethodLabel(ctx.createParams.isDraft, ctx.createParams.autoMerge, ctx.createParams.autoMergeMethod, ctx.createParams.baseHasMergeQueue).label}

0 commit comments

Comments
 (0)