/
remotehub.ts
88 lines (74 loc) · 2.73 KB
/
remotehub.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { extensions, Uri } from 'vscode';
import { ExtensionNotFoundError } from '../errors';
import { Logger } from '../logger';
export async function getRemoteHubApi(): Promise<RemoteHubApi>;
export async function getRemoteHubApi(silent: false): Promise<RemoteHubApi>;
export async function getRemoteHubApi(silent: boolean): Promise<RemoteHubApi | undefined>;
export async function getRemoteHubApi(silent?: boolean): Promise<RemoteHubApi | undefined> {
try {
const extension = extensions.getExtension<RemoteHubApi>('GitHub.remotehub');
if (extension == null) {
Logger.log('GitHub Repositories extension is not installed or enabled');
throw new ExtensionNotFoundError('GitHub Repositories', 'GitHub.remotehub');
}
const api = extension.isActive ? extension.exports : await extension.activate();
return api;
} catch (ex) {
Logger.error(ex, 'Unable to get required api from the GitHub Repositories extension');
if (!(ex instanceof ExtensionNotFoundError)) {
debugger;
}
if (silent) return undefined;
throw ex;
}
}
export interface Provider {
readonly id: 'github' | 'azdo';
readonly name: string;
}
export enum HeadType {
Branch = 0,
RemoteBranch = 1,
Tag = 2,
Commit = 3,
}
export interface Metadata {
readonly provider: Provider;
readonly repo: { owner: string; name: string } & Record<string, unknown>;
getRevision(): Promise<{ type: HeadType; name: string; revision: string }>;
}
// export type CreateUriOptions = Omit<Metadata, 'provider' | 'branch'>;
export interface RemoteHubApi {
getMetadata(uri: Uri): Promise<Metadata | undefined>;
// createProviderUri(provider: string, options: CreateUriOptions, path: string): Uri | undefined;
getProvider(uri: Uri): Provider | undefined;
getProviderUri(uri: Uri): Uri;
getProviderRootUri(uri: Uri): Uri;
isProviderUri(uri: Uri, provider?: string): boolean;
// createVirtualUri(provider: string, options: CreateUriOptions, path: string): Uri | undefined;
getVirtualUri(uri: Uri): Uri;
getVirtualWorkspaceUri(uri: Uri): Uri | undefined;
/**
* Returns whether RemoteHub has the full workspace contents for a vscode-vfs:// URI.
* This will download workspace contents if fetching full workspace contents is enabled
* for the requested URI and the contents are not already available locally.
* @param workspaceUri A vscode-vfs:// URI for a RemoteHub workspace folder.
* @returns boolean indicating whether the workspace contents were successfully loaded.
*/
loadWorkspaceContents(workspaceUri: Uri): Promise<boolean>;
}
export interface RepositoryRef {
type: RepositoryRefType;
id: string;
}
export const enum RepositoryRefType {
Branch = 0,
Tag = 1,
Commit = 2,
PullRequest = 3,
Tree = 4,
}
export interface GitHubAuthorityMetadata {
v: 1;
ref?: RepositoryRef;
}