mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-18 15:55:59 +01:00
add openPullRequest command and update related logic in GitHub extension
This commit is contained in:
@@ -8,6 +8,7 @@ import { API as GitAPI, RefType, Repository } from './typings/git.js';
|
||||
import { publishRepository } from './publish.js';
|
||||
import { DisposableStore, getRepositoryFromUrl } from './util.js';
|
||||
import { LinkContext, getCommitLink, getLink, getVscodeDevHost } from './links.js';
|
||||
import { getOctokit } from './auth.js';
|
||||
|
||||
async function copyVscodeDevLink(gitAPI: GitAPI, useSelection: boolean, context: LinkContext, includeRange = true) {
|
||||
try {
|
||||
@@ -89,6 +90,27 @@ async function createPullRequest(gitAPI: GitAPI, sessionResource: vscode.Uri | u
|
||||
}
|
||||
}
|
||||
|
||||
// Check if a PR already exists for this branch
|
||||
try {
|
||||
const octokit = await getOctokit();
|
||||
const { data: pullRequests } = await octokit.pulls.list({
|
||||
owner: remoteInfo.owner,
|
||||
repo: remoteInfo.repo,
|
||||
head: `${remoteInfo.owner}:${head.name}`,
|
||||
state: 'open',
|
||||
});
|
||||
|
||||
if (pullRequests.length > 0) {
|
||||
vscode.commands.executeCommand('setContext', 'github.hasOpenPullRequest', true);
|
||||
vscode.env.openExternal(vscode.Uri.parse(pullRequests[0].html_url));
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// If the API call fails, fall through to open the creation URL
|
||||
}
|
||||
|
||||
vscode.commands.executeCommand('setContext', 'github.hasOpenPullRequest', false);
|
||||
|
||||
// Build the GitHub PR creation URL
|
||||
// Format: https://github.com/owner/repo/compare/base...head
|
||||
const prUrl = `https://github.com/${remoteInfo.owner}/${remoteInfo.repo}/compare/${head.name}?expand=1`;
|
||||
@@ -181,5 +203,9 @@ export function registerCommands(gitAPI: GitAPI): vscode.Disposable {
|
||||
return createPullRequest(gitAPI, sessionResource, sessionMetadata);
|
||||
}));
|
||||
|
||||
disposables.add(vscode.commands.registerCommand('github.openPullRequest', async (sessionResource: vscode.Uri | undefined, sessionMetadata: { worktreePath?: string } | undefined) => {
|
||||
return createPullRequest(gitAPI, sessionResource, sessionMetadata);
|
||||
}));
|
||||
|
||||
return disposables;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user