mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-23 19:27:15 +00:00
GitHub - add "Open on GitHub" action to the SCM graph (#237635)
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
import { API as GitAPI } from './typings/git';
|
||||
import { API as GitAPI, RefType } from './typings/git';
|
||||
import { publishRepository } from './publish';
|
||||
import { DisposableStore } from './util';
|
||||
import { DisposableStore, getRepositoryFromUrl } from './util';
|
||||
import { LinkContext, getCommitLink, getLink, getVscodeDevHost } from './links';
|
||||
|
||||
async function copyVscodeDevLink(gitAPI: GitAPI, useSelection: boolean, context: LinkContext, includeRange = true) {
|
||||
@@ -62,6 +62,36 @@ export function registerCommands(gitAPI: GitAPI): vscode.Disposable {
|
||||
vscode.env.openExternal(vscode.Uri.parse(link));
|
||||
}));
|
||||
|
||||
disposables.add(vscode.commands.registerCommand('github.openOnGitHub2', async (repository: vscode.SourceControl, historyItem: vscode.SourceControlHistoryItem) => {
|
||||
if (!repository || !historyItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
const apiRepository = gitAPI.repositories.find(r => r.rootUri.fsPath === repository.rootUri?.fsPath);
|
||||
if (!apiRepository) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the unique remotes that contain the commit
|
||||
const branches = await apiRepository.getBranches({ contains: historyItem.id });
|
||||
const remoteNames = new Set(branches.filter(b => b.type === RefType.RemoteHead && b.remote).map(b => b.remote!));
|
||||
|
||||
// GitHub remotes that contain the commit
|
||||
const remotes = apiRepository.state.remotes
|
||||
.filter(r => remoteNames.has(r.name) && r.fetchUrl && getRepositoryFromUrl(r.fetchUrl));
|
||||
|
||||
if (remotes.length === 0) {
|
||||
vscode.window.showInformationMessage(vscode.l10n.t('No GitHub remotes found that contain this commit.'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Default remote (origin, or the first remote)
|
||||
const defaultRemote = remotes.find(r => r.name === 'origin') ?? remotes[0];
|
||||
|
||||
const link = getCommitLink(defaultRemote.fetchUrl!, historyItem.id);
|
||||
vscode.env.openExternal(vscode.Uri.parse(link));
|
||||
}));
|
||||
|
||||
disposables.add(vscode.commands.registerCommand('github.openOnVscodeDev', async () => {
|
||||
return openVscodeDevLink(gitAPI);
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user