Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
3 changes: 2 additions & 1 deletion src/common/externalUri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/common/settingKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
14 changes: 12 additions & 2 deletions src/github/externalUriOpener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<void> {
if (!this.isOpenPullLinksEnabled()) {
await openWithDefaultExternalOpener(openContext.sourceUri);
return;
}
Comment thread
alexr00 marked this conversation as resolved.

const identity = parseGitHubIssueOrPullRequestUri(openContext.sourceUri);
if (!identity || token.isCancellationRequested) {
return;
Expand Down Expand Up @@ -81,6 +87,10 @@ class GitHubIssueOrPullRequestExternalUriOpener extends Disposable implements vs
}
}

private isOpenPullLinksEnabled(): boolean {
return vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<boolean>(OPEN_PULL_LINKS, true);
}

private getFolderRepositoryManager(owner: string, repo: string): FolderRepositoryManager {
const existingManager = this._repositoriesManager.getManagerForRepository(owner, repo)
?? this._repositoriesManager.folderManagers[0];
Expand Down
11 changes: 9 additions & 2 deletions src/test/common/externalUri.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
});
Expand Down