Skip to content

Commit 26b754c

Browse files
committed
Consolidates runCLICommand
1 parent 64a3304 commit 26b754c

File tree

4 files changed

+37
-57
lines changed

4 files changed

+37
-57
lines changed

src/env/node/gk/cli/integration.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import { getLogScope } from '../../../../system/logger.scope';
1515
import { compare } from '../../../../system/version';
1616
import { run } from '../../git/shell';
1717
import { getPlatform, isWeb } from '../../platform';
18-
import { toMcpInstallProvider } from '../mcp/utils';
1918
import { CliCommandHandlers } from './commands';
2019
import type { IpcServer } from './ipcServer';
2120
import { createIpcServer } from './ipcServer';
21+
import { runCLICommand, toMcpInstallProvider } from './utils';
2222

2323
const enum CLIInstallErrorReason {
2424
UnsupportedPlatform,
@@ -42,7 +42,7 @@ const CLIProxyMCPInstallOutputs = {
4242
checkingForUpdates: /checking for updates.../i,
4343
notASupportedClient: /is not a supported MCP client/i,
4444
installedSuccessfully: /GitKraken MCP Server Successfully Installed!/i,
45-
};
45+
} as const;
4646

4747
export class GkCliIntegrationProvider implements Disposable {
4848
private readonly _disposable: Disposable;
@@ -238,7 +238,7 @@ export class GkCliIntegrationProvider implements Disposable {
238238
}
239239
}
240240

241-
let output = await this.runCLICommand(
241+
let output = await runCLICommand(
242242
['mcp', 'install', appName, '--source=gitlens', `--scheme=${env.uriScheme}`],
243243
{
244244
cwd: cliPath,
@@ -555,7 +555,7 @@ export class GkCliIntegrationProvider implements Disposable {
555555

556556
// Set up the local MCP server files
557557
try {
558-
const coreInstallOutput = await this.runCLICommand(['install'], {
558+
const coreInstallOutput = await runCLICommand(['install'], {
559559
cwd: globalStoragePath.fsPath,
560560
});
561561
const directory = coreInstallOutput.match(/Directory: (.*)/);
@@ -632,21 +632,6 @@ export class GkCliIntegrationProvider implements Disposable {
632632
return { cliVersion: cliVersion, cliPath: cliPath, status: cliInstallStatus };
633633
}
634634

635-
private async runCLICommand(
636-
args: string[],
637-
options?: {
638-
cwd?: string;
639-
},
640-
): Promise<string> {
641-
const platform = getPlatform();
642-
const cwd = options?.cwd ?? this.container.storage.get('gk:cli:path');
643-
if (cwd == null) {
644-
throw new Error('CLI is not installed');
645-
}
646-
647-
return run(platform === 'windows' ? 'gk.exe' : './gk', args, 'utf8', { cwd: cwd });
648-
}
649-
650635
private async authCLI(): Promise<void> {
651636
const cliInstall = this.container.storage.get('gk:cli:install');
652637
const cliPath = this.container.storage.get('gk:cli:path');
@@ -660,7 +645,7 @@ export class GkCliIntegrationProvider implements Disposable {
660645
}
661646

662647
try {
663-
await this.runCLICommand(['auth', 'login', '-t', currentSessionToken]);
648+
await runCLICommand(['auth', 'login', '-t', currentSessionToken]);
664649
} catch (ex) {
665650
Logger.error(`Failed to auth CLI: ${ex instanceof Error ? ex.message : String(ex)}`);
666651
}

src/env/node/gk/cli/utils.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Container } from '../../../../container';
2+
import { run } from '../../git/shell';
3+
import { getPlatform } from '../../platform';
4+
5+
export function toMcpInstallProvider(appHostName: string | undefined): string | undefined {
6+
switch (appHostName) {
7+
case 'code':
8+
return 'vscode';
9+
case 'code-insiders':
10+
return 'vscode-insiders';
11+
case 'code-exploration':
12+
return 'vscode-exploration';
13+
default:
14+
return appHostName;
15+
}
16+
}
17+
18+
export async function runCLICommand(args: string[], options?: { cwd?: string }): Promise<string> {
19+
const cwd = options?.cwd ?? Container.instance.storage.get('gk:cli:path');
20+
if (cwd == null) {
21+
throw new Error('CLI is not installed');
22+
}
23+
24+
const platform = getPlatform();
25+
26+
return run(platform === 'windows' ? 'gk.exe' : './gk', args, 'utf8', { cwd: cwd });
27+
}

src/env/node/gk/mcp/integration.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import type { StorageChangeEvent } from '../../../../system/-webview/storage';
55
import { getHostAppName } from '../../../../system/-webview/vscode';
66
import { debounce } from '../../../../system/function/debounce';
77
import { Logger } from '../../../../system/logger';
8-
import { run } from '../../git/shell';
9-
import { getPlatform } from '../../platform';
10-
import { toMcpInstallProvider } from './utils';
8+
import { runCLICommand, toMcpInstallProvider } from '../cli/utils';
119

1210
const CLIProxyMCPConfigOutputs = {
1311
checkingForUpdates: /checking for updates.../i,
14-
};
12+
} as const;
1513

1614
export class McpProvider implements Disposable {
1715
private readonly _disposable: Disposable;
@@ -96,12 +94,9 @@ export class McpProvider implements Disposable {
9694
return undefined;
9795
}
9896

99-
let output = await this.runCLICommand(
100-
['mcp', 'config', appName, '--source=gitlens', `--scheme=${env.uriScheme}`],
101-
{
102-
cwd: cliPath,
103-
},
104-
);
97+
let output = await runCLICommand(['mcp', 'config', appName, '--source=gitlens', `--scheme=${env.uriScheme}`], {
98+
cwd: cliPath,
99+
});
105100
output = output.replace(CLIProxyMCPConfigOutputs.checkingForUpdates, '').trim();
106101
console.log(output);
107102

@@ -122,21 +117,6 @@ export class McpProvider implements Disposable {
122117
return undefined;
123118
}
124119

125-
private async runCLICommand(
126-
args: string[],
127-
options?: {
128-
cwd?: string;
129-
},
130-
): Promise<string> {
131-
const platform = getPlatform();
132-
const cwd = options?.cwd ?? this.container.storage.get('gk:cli:path');
133-
if (cwd == null) {
134-
throw new Error('CLI is not installed');
135-
}
136-
137-
return run(platform === 'windows' ? 'gk.exe' : './gk', args, 'utf8', { cwd: cwd });
138-
}
139-
140120
dispose(): void {
141121
this._disposable.dispose();
142122
this._onDidChangeMcpServerDefinitions.dispose();

src/env/node/gk/mcp/utils.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)