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:
Ladislau Szomoru
2025-01-15 16:30:43 +01:00
committed by GitHub
parent 96e03e0d94
commit 57e8c28877
15 changed files with 142 additions and 46 deletions

View File

@@ -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})`;
});
}
}