mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
GitHub - link provider for various hovers (#237961)
* Initial implementation * Refactor code, add link to blame decoration * Add links to timeline hover * Saving my work * Update remote order for "Open on GitHub" action * Bug fixes * Add link provider for graph hover * Rename method
This commit is contained in:
@@ -85,10 +85,12 @@ export function registerCommands(gitAPI: GitAPI): vscode.Disposable {
|
||||
return;
|
||||
}
|
||||
|
||||
// Default remote (origin, or the first remote)
|
||||
const defaultRemote = remotes.find(r => r.name === 'origin') ?? remotes[0];
|
||||
// Default remote (upstream -> origin -> first)
|
||||
const remote = remotes.find(r => r.name === 'upstream')
|
||||
?? remotes.find(r => r.name === 'origin')
|
||||
?? remotes[0];
|
||||
|
||||
const link = getCommitLink(defaultRemote.fetchUrl!, historyItem.id);
|
||||
const link = getCommitLink(remote.fetchUrl!, historyItem.id);
|
||||
vscode.env.openExternal(vscode.Uri.parse(link));
|
||||
}));
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Command, Uri, env, l10n, workspace } from 'vscode';
|
||||
import { RemoteSourceProvider, RemoteSource, RemoteSourceAction } from './typings/git-base';
|
||||
import { getOctokit } from './auth';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { getRepositoryFromQuery, getRepositoryFromUrl } from './util';
|
||||
import { getRepositoryFromQuery, getRepositoryFromUrl, ISSUE_EXPRESSION } from './util';
|
||||
import { getBranchLink, getVscodeDevHost } from './links';
|
||||
|
||||
function asRemoteSource(raw: any): RemoteSource {
|
||||
@@ -137,10 +137,10 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
|
||||
}];
|
||||
}
|
||||
|
||||
async getRemoteSourceControlHistoryItemCommands(url: string): Promise<Command[]> {
|
||||
async getRemoteSourceControlHistoryItemCommands(url: string): Promise<Command[] | undefined> {
|
||||
const repository = getRepositoryFromUrl(url);
|
||||
if (!repository) {
|
||||
return [];
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return [{
|
||||
@@ -150,4 +150,28 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
|
||||
arguments: [url]
|
||||
}];
|
||||
}
|
||||
|
||||
provideRemoteSourceLinks(url: string, content: string): string | undefined {
|
||||
const repository = getRepositoryFromUrl(url);
|
||||
if (!repository) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return content.replace(
|
||||
ISSUE_EXPRESSION,
|
||||
(match, _group1, owner: string | undefined, repo: string | undefined, _group2, number: string | undefined) => {
|
||||
if (!number || Number.isNaN(parseInt(number))) {
|
||||
return match;
|
||||
}
|
||||
|
||||
const label = owner && repo
|
||||
? `${owner}/${repo}#${number}`
|
||||
: `#${number}`;
|
||||
|
||||
owner = owner ?? repository.owner;
|
||||
repo = repo ?? repository.repo;
|
||||
|
||||
return `[${label}](https://github.com/${owner}/${repo}/issues/${number})`;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
4
extensions/github/src/typings/git-base.d.ts
vendored
4
extensions/github/src/typings/git-base.d.ts
vendored
@@ -9,8 +9,9 @@ export { ProviderResult } from 'vscode';
|
||||
export interface API {
|
||||
registerRemoteSourceProvider(provider: RemoteSourceProvider): Disposable;
|
||||
getRemoteSourceActions(url: string): Promise<RemoteSourceAction[]>;
|
||||
getRemoteSourceControlHistoryItemCommands(url: string): Promise<Command[]>;
|
||||
getRemoteSourceControlHistoryItemCommands(url: string): Promise<Command[] | undefined>;
|
||||
pickRemoteSource(options: PickRemoteSourceOptions): Promise<string | PickRemoteSourceResult | undefined>;
|
||||
provideRemoteSourceLinks(url: string, content: string): ProviderResult<string>;
|
||||
}
|
||||
|
||||
export interface GitBaseExtension {
|
||||
@@ -85,4 +86,5 @@ export interface RemoteSourceProvider {
|
||||
getRemoteSourceControlHistoryItemCommands?(url: string): ProviderResult<Command[]>;
|
||||
getRecentRemoteSources?(query?: string): ProviderResult<RecentRemoteSource[]>;
|
||||
getRemoteSources(query?: string): ProviderResult<RemoteSource[]>;
|
||||
provideRemoteSourceLinks?(url: string, content: string): ProviderResult<string>;
|
||||
}
|
||||
|
||||
@@ -37,3 +37,5 @@ export function getRepositoryFromQuery(query: string): { owner: string; repo: st
|
||||
export function repositoryHasGitHubRemote(repository: Repository) {
|
||||
return !!repository.state.remotes.find(remote => remote.fetchUrl ? getRepositoryFromUrl(remote.fetchUrl) : undefined);
|
||||
}
|
||||
|
||||
export const ISSUE_EXPRESSION = /(([A-Za-z0-9_.\-]+)\/([A-Za-z0-9_.\-]+))?(#|GH-)([1-9][0-9]*)($|\b)/g;
|
||||
|
||||
Reference in New Issue
Block a user