forked from gitkraken/vscode-gitlens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenRepoOnRemote.ts
67 lines (58 loc) · 2.19 KB
/
openRepoOnRemote.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
import type { TextEditor, Uri } from 'vscode';
import { Commands } from '../constants';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { RemoteResourceType } from '../git/models/remoteResource';
import { showGenericErrorMessage } from '../messages';
import { getBestRepositoryOrShowPicker } from '../quickpicks/repositoryPicker';
import { command, executeCommand } from '../system/command';
import { Logger } from '../system/logger';
import type { CommandContext } from './base';
import { ActiveEditorCommand, getCommandUri, isCommandContextViewNodeHasRemote } from './base';
import type { OpenOnRemoteCommandArgs } from './openOnRemote';
export interface OpenRepoOnRemoteCommandArgs {
clipboard?: boolean;
remote?: string;
}
@command()
export class OpenRepoOnRemoteCommand extends ActiveEditorCommand {
constructor(private readonly container: Container) {
super([Commands.OpenRepoOnRemote, Commands.Deprecated_OpenRepoInRemote, Commands.CopyRemoteRepositoryUrl]);
}
protected override preExecute(context: CommandContext, args?: OpenRepoOnRemoteCommandArgs) {
if (isCommandContextViewNodeHasRemote(context)) {
args = { ...args, remote: context.node.remote.name };
}
if (context.command === Commands.CopyRemoteRepositoryUrl) {
args = { ...args, clipboard: true };
}
return this.execute(context.editor, context.uri, args);
}
async execute(editor?: TextEditor, uri?: Uri, args?: OpenRepoOnRemoteCommandArgs) {
uri = getCommandUri(uri, editor);
const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined;
const repoPath = (
await getBestRepositoryOrShowPicker(
gitUri,
editor,
args?.clipboard
? 'Choose which repository to copy the url from'
: 'Choose which repository to open on remote',
)
)?.path;
if (!repoPath) return;
try {
void (await executeCommand<OpenOnRemoteCommandArgs>(Commands.OpenOnRemote, {
resource: {
type: RemoteResourceType.Repo,
},
repoPath: repoPath,
remote: args?.remote,
clipboard: args?.clipboard,
}));
} catch (ex) {
Logger.error(ex, 'OpenRepoOnRemoteCommand');
void showGenericErrorMessage('Unable to open repository on remote provider');
}
}
}