diff --git a/package.json b/package.json index f2511228fd..ab02d7f1d6 100644 --- a/package.json +++ b/package.json @@ -356,6 +356,16 @@ "default": "ask", "description": "%githubPullRequests.terminalLinksHandler.description%" }, + "githubPullRequests.openPullLinks": { + "type": "boolean", + "default": true, + "scope": "application", + "markdownDescription": "%githubPullRequests.openPullLinks.description%", + "tags": [ + "experimental", + "onExP" + ] + }, "githubPullRequests.createOnPublishBranch": { "type": "string", "enum": [ diff --git a/package.nls.json b/package.nls.json index 1aaa2cf34c..b1942119d2 100644 --- a/package.nls.json +++ b/package.nls.json @@ -52,6 +52,7 @@ "githubPullRequests.terminalLinksHandler.github": "Create the pull request on GitHub.", "githubPullRequests.terminalLinksHandler.vscode": "Create the pull request in VS Code.", "githubPullRequests.terminalLinksHandler.ask": "Ask which method to use.", + "githubPullRequests.openPullLinks.description": "Controls whether GitHub issue and pull request links open in VS Code.", "githubPullRequests.createOnPublishBranch.description": "Create a pull request when a branch is published.", "githubPullRequests.createOnPublishBranch.never": "Never create a pull request when a branch is published.", "githubPullRequests.createOnPublishBranch.ask": "Ask if you want to create a pull request when a branch is published.", diff --git a/src/common/externalUri.ts b/src/common/externalUri.ts index daa51d425e..6376918512 100644 --- a/src/common/externalUri.ts +++ b/src/common/externalUri.ts @@ -48,8 +48,9 @@ export function parseGitHubIssueOrPullRequestUri(uri: vscode.Uri): GitHubIssueOr export function getGitHubIssueOrPullRequestUriOpenerPriority( uri: vscode.Uri, + enabled: boolean, ): vscode.ExternalUriOpenerPriority { - return parseGitHubIssueOrPullRequestUri(uri) + return enabled && parseGitHubIssueOrPullRequestUri(uri) ? vscode.ExternalUriOpenerPriority.Preferred : vscode.ExternalUriOpenerPriority.None; } diff --git a/src/common/settingKeys.ts b/src/common/settingKeys.ts index 895378c9c3..98da176222 100644 --- a/src/common/settingKeys.ts +++ b/src/common/settingKeys.ts @@ -5,6 +5,7 @@ export const PR_SETTINGS_NAMESPACE = 'githubPullRequests'; export const TERMINAL_LINK_HANDLER = 'terminalLinksHandler'; +export const OPEN_PULL_LINKS = 'openPullLinks'; export const BRANCH_PUBLISH = 'createOnPublishBranch'; export const BRANCH_LIST_TIMEOUT = 'branchListTimeout'; export const USE_REVIEW_MODE = 'useReviewMode'; diff --git a/src/github/externalUriOpener.ts b/src/github/externalUriOpener.ts index a04fb38c69..14d5d56d73 100644 --- a/src/github/externalUriOpener.ts +++ b/src/github/externalUriOpener.ts @@ -13,7 +13,8 @@ import { IssueOverviewPanel } from './issueOverview'; import { PullRequestOverviewPanel } from './pullRequestOverview'; import { RepositoriesManager } from './repositoriesManager'; import { GitApiImpl } from '../api/api1'; -import { getGitHubIssueOrPullRequestUriOpenerPriority, parseGitHubIssueOrPullRequestUri } from '../common/externalUri'; +import { getGitHubIssueOrPullRequestUriOpenerPriority, openWithDefaultExternalOpener, parseGitHubIssueOrPullRequestUri } from '../common/externalUri'; +import { OPEN_PULL_LINKS, PR_SETTINGS_NAMESPACE } from '../common/settingKeys'; import { ITelemetry } from '../common/telemetry'; import { EXTENSION_ID } from '../constants'; import { CreatePullRequestHelper } from '../view/createPullRequestHelper'; @@ -36,10 +37,15 @@ class GitHubIssueOrPullRequestExternalUriOpener extends Disposable implements vs } canOpenExternalUri(uri: vscode.Uri): vscode.ExternalUriOpenerPriority { - return getGitHubIssueOrPullRequestUriOpenerPriority(uri); + return getGitHubIssueOrPullRequestUriOpenerPriority(uri, this.isOpenPullLinksEnabled()); } async openExternalUri(_resolvedUri: vscode.Uri, openContext: vscode.OpenExternalUriContext, token: vscode.CancellationToken): Promise { + if (!this.isOpenPullLinksEnabled()) { + await openWithDefaultExternalOpener(openContext.sourceUri); + return; + } + const identity = parseGitHubIssueOrPullRequestUri(openContext.sourceUri); if (!identity || token.isCancellationRequested) { return; @@ -81,6 +87,10 @@ class GitHubIssueOrPullRequestExternalUriOpener extends Disposable implements vs } } + private isOpenPullLinksEnabled(): boolean { + return vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get(OPEN_PULL_LINKS, true); + } + private getFolderRepositoryManager(owner: string, repo: string): FolderRepositoryManager { const existingManager = this._repositoriesManager.getManagerForRepository(owner, repo) ?? this._repositoriesManager.folderManagers[0]; diff --git a/src/test/common/externalUri.test.ts b/src/test/common/externalUri.test.ts index fe7c01d742..165a25accc 100644 --- a/src/test/common/externalUri.test.ts +++ b/src/test/common/externalUri.test.ts @@ -75,14 +75,21 @@ describe('externalUri', () => { it('is preferred for supported URLs', () => { assert.strictEqual( - getGitHubIssueOrPullRequestUriOpenerPriority(pullRequestUri), + getGitHubIssueOrPullRequestUriOpenerPriority(pullRequestUri, true), vscode.ExternalUriOpenerPriority.Preferred, ); }); + it('is disabled when the external URI handler is disabled', () => { + assert.strictEqual( + getGitHubIssueOrPullRequestUriOpenerPriority(pullRequestUri, false), + vscode.ExternalUriOpenerPriority.None, + ); + }); + it('is disabled for unsupported URLs', () => { assert.strictEqual( - getGitHubIssueOrPullRequestUriOpenerPriority(vscode.Uri.parse('https://github.com/microsoft/vscode')), + getGitHubIssueOrPullRequestUriOpenerPriority(vscode.Uri.parse('https://github.com/microsoft/vscode'), true), vscode.ExternalUriOpenerPriority.None, ); });