Skip to content

Commit ec581ef

Browse files
committed
Standardizes source type handling across commands
Removes unnecessary markdown command link helpers Replaces command enum usage with type-safe strings
1 parent 2d58554 commit ec581ef

24 files changed

+190
-179
lines changed

src/commands/cloudIntegrations.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,39 @@
1-
import { GlCommand } from '../constants.commands';
21
import type { SupportedCloudIntegrationIds } from '../constants.integrations';
32
import type { Source } from '../constants.telemetry';
43
import type { Container } from '../container';
54
import { command } from '../system/-webview/command';
6-
import { createMarkdownCommandLink } from '../system/commands';
75
import { GlCommandBase } from './commandBase';
86

9-
export interface ManageCloudIntegrationsCommandArgs extends Source {}
7+
export interface ManageCloudIntegrationsCommandArgs {
8+
source?: Source;
9+
}
1010

11-
export interface ConnectCloudIntegrationsCommandArgs extends Source {
11+
export interface ConnectCloudIntegrationsCommandArgs {
1212
integrationIds?: SupportedCloudIntegrationIds[];
13+
source?: Source;
1314
}
1415

1516
@command()
1617
export class ManageCloudIntegrationsCommand extends GlCommandBase {
1718
constructor(private readonly container: Container) {
18-
super(GlCommand.PlusManageCloudIntegrations);
19+
super('gitlens.plus.cloudIntegrations.manage');
1920
}
2021

2122
async execute(args?: ManageCloudIntegrationsCommandArgs): Promise<void> {
22-
await this.container.integrations.manageCloudIntegrations(
23-
args?.source ? { source: args.source, detail: args?.detail } : undefined,
24-
);
23+
await this.container.integrations.manageCloudIntegrations(args?.source);
2524
}
2625
}
2726

2827
@command()
2928
export class ConnectCloudIntegrationsCommand extends GlCommandBase {
30-
static createMarkdownCommandLink(args: ConnectCloudIntegrationsCommandArgs): string {
31-
return createMarkdownCommandLink<ConnectCloudIntegrationsCommandArgs>(
32-
GlCommand.PlusConnectCloudIntegrations,
33-
args,
34-
);
35-
}
36-
3729
constructor(private readonly container: Container) {
38-
super(GlCommand.PlusConnectCloudIntegrations);
30+
super('gitlens.plus.cloudIntegrations.connect');
3931
}
4032

4133
async execute(args?: ConnectCloudIntegrationsCommandArgs): Promise<void> {
4234
await this.container.integrations.connectCloudIntegrations(
4335
args?.integrationIds ? { integrationIds: args.integrationIds } : undefined,
44-
args?.source ? { source: args.source, detail: args?.detail } : undefined,
36+
args?.source,
4537
);
4638
}
4739
}

src/commands/showView.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { CommandContext } from './commandContext';
1111
export class ShowViewCommand extends GlCommandBase {
1212
constructor(private readonly container: Container) {
1313
super([
14-
GlCommand.ShowAccountView,
14+
'gitlens.showAccountView',
1515
GlCommand.ShowBranchesView,
1616
GlCommand.ShowCommitDetailsView,
1717
GlCommand.ShowCommitsView,
@@ -56,7 +56,7 @@ export class ShowViewCommand extends GlCommandBase {
5656
async execute(context: CommandContext, ...args: unknown[]): Promise<void> {
5757
const command = context.command;
5858
switch (command) {
59-
case GlCommand.ShowAccountView:
59+
case 'gitlens.showAccountView':
6060
return this.container.views.home.show(
6161
undefined,
6262
...([{ focusAccount: true }, ...args] as HomeWebviewShowingArgs),

src/commands/walkthroughs.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { Source, Sources } from '../constants.telemetry';
66
import type { Container } from '../container';
77
import { command, executeCommand } from '../system/-webview/command';
88
import { openUrl, openWalkthrough as openWalkthroughCore } from '../system/-webview/vscode';
9+
import type { ConnectCloudIntegrationsCommandArgs } from './cloudIntegrations';
910
import { GlCommandBase } from './commandBase';
1011

1112
@command()
@@ -72,7 +73,7 @@ export class WalkthroughPlusUpgradeCommand extends GlCommandBase {
7273
}
7374

7475
execute(): void {
75-
const command = GlCommand.PlusUpgrade;
76+
const command: GlCommands = 'gitlens.plus.upgrade';
7677
this.container.telemetry.sendEvent('walkthrough/action', {
7778
type: 'command',
7879
name: 'plus/upgrade',
@@ -108,7 +109,7 @@ export class WalkthroughPlusSignUpCommand extends GlCommandBase {
108109
}
109110

110111
execute(): void {
111-
const command = GlCommand.PlusSignUp;
112+
const command: GlCommands = 'gitlens.plus.signUp';
112113
this.container.telemetry.sendEvent('walkthrough/action', {
113114
type: 'command',
114115
name: 'plus/sign-up',
@@ -125,7 +126,7 @@ export class WalkthroughPlusReactivateCommand extends GlCommandBase {
125126
}
126127

127128
execute(): void {
128-
const command = GlCommand.PlusReactivateProTrial;
129+
const command: GlCommands = 'gitlens.plus.reactivateProTrial';
129130
this.container.telemetry.sendEvent('walkthrough/action', {
130131
type: 'command',
131132
name: 'plus/reactivate',
@@ -322,13 +323,15 @@ export class WalkthroughConnectIntegrationsCommand extends GlCommandBase {
322323
}
323324

324325
execute(): void {
325-
const command = GlCommand.PlusConnectCloudIntegrations;
326+
const command: GlCommands = 'gitlens.plus.cloudIntegrations.connect';
326327
this.container.telemetry.sendEvent('walkthrough/action', {
327328
type: 'command',
328329
name: 'connect/integrations',
329330
command: command,
330331
});
331-
executeCommand(command);
332+
executeCommand<ConnectCloudIntegrationsCommandArgs>(command, {
333+
source: { source: 'walkthrough' },
334+
});
332335
}
333336
}
334337

src/constants.commands.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ export const enum GlCommand {
8383
GenerateCommitMessage = 'gitlens.generateCommitMessage',
8484
GenerateCommitMessageScm = 'gitlens.scm.generateCommitMessage',
8585
GetStarted = 'gitlens.getStarted',
86-
GKSwitchOrganization = 'gitlens.gk.switchOrganization',
8786
InviteToLiveShare = 'gitlens.inviteToLiveShare',
8887
OpenBlamePriorToChange = 'gitlens.openBlamePriorToChange',
8988
OpenBranchesOnRemote = 'gitlens.openBranchesOnRemote',
@@ -147,25 +146,7 @@ export const enum GlCommand {
147146
GitCommandsWorktreeDelete = 'gitlens.gitCommands.worktree.delete',
148147
GitCommandsWorktreeOpen = 'gitlens.gitCommands.worktree.open',
149148
OpenOrCreateWorktreeForGHPR = 'gitlens.ghpr.views.openOrCreateWorktree',
150-
PlusConnectCloudIntegrations = 'gitlens.plus.cloudIntegrations.connect',
151-
PlusHide = 'gitlens.plus.hide',
152-
PlusLogin = 'gitlens.plus.login',
153-
PlusLogout = 'gitlens.plus.logout',
154-
PlusManage = 'gitlens.plus.manage',
155-
PlusManageCloudIntegrations = 'gitlens.plus.cloudIntegrations.manage',
156-
PlusReactivateProTrial = 'gitlens.plus.reactivateProTrial',
157-
PlusResendVerification = 'gitlens.plus.resendVerification',
158-
PlusRestore = 'gitlens.plus.restore',
159-
PlusShowPlans = 'gitlens.plus.showPlans',
160-
PlusSignUp = 'gitlens.plus.signUp',
161-
PlusStartPreviewTrial = 'gitlens.plus.startPreviewTrial',
162-
PlusContinueFeaturePreview = 'gitlens.plus.continueFeaturePreview',
163-
PlusUpgrade = 'gitlens.plus.upgrade',
164-
PlusValidate = 'gitlens.plus.validate',
165-
PlusSimulateSubscription = 'gitlens.plus.simulateSubscription',
166149
QuickOpenFileHistory = 'gitlens.quickOpenFileHistory',
167-
RefreshLaunchpad = 'gitlens.launchpad.refresh',
168-
RefreshGraph = 'gitlens.graph.refresh',
169150
RefreshHover = 'gitlens.refreshHover',
170151
Reset = 'gitlens.reset',
171152
ResetAIKey = 'gitlens.resetAIKey',
@@ -186,7 +167,6 @@ export const enum GlCommand {
186167
ShowGraphPage = 'gitlens.showGraphPage',
187168
ShowGraphView = 'gitlens.showGraphView',
188169
ShowHomeView = 'gitlens.showHomeView',
189-
ShowAccountView = 'gitlens.showAccountView',
190170
ShowInCommitGraph = 'gitlens.showInCommitGraph',
191171
ShowInCommitGraphView = 'gitlens.showInCommitGraphView',
192172
ShowInDetailsView = 'gitlens.showInDetailsView',

src/constants.telemetry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Config, GraphBranchesVisibility, GraphConfig } from './config';
22
import type { WalkthroughSteps } from './constants';
33
import type { AIProviders } from './constants.ai';
4-
import type { GlCommand } from './constants.commands';
4+
import type { GlCommands } from './constants.commands';
55
import type { IntegrationId, SupportedCloudIntegrationIds } from './constants.integrations';
66
import type { SubscriptionState, SubscriptionStateString } from './constants.subscription';
77
import type { CustomEditorTypes, TreeViewTypes, WebviewTypes, WebviewViewTypes } from './constants.views';
@@ -440,7 +440,7 @@ interface CommandEventData {
440440
}
441441

442442
interface GitCommandEventData {
443-
command: GlCommand.GitCommands;
443+
command: Extract<GlCommands, 'gitlens.gitCommands'>;
444444
'context.mode'?: string;
445445
'context.submode'?: string;
446446
webview?: string;

src/plus/gk/__debug__accountDebug.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { Disposable } from 'vscode';
22
import { ThemeIcon, window } from 'vscode';
3-
import { GlCommand } from '../../constants.commands';
43
import {
54
proFeaturePreviewUsages,
65
proTrialLengthInDays,
@@ -77,7 +76,7 @@ class AccountDebug {
7776
private readonly service: SubscriptionServiceFacade,
7877
) {
7978
this.container.context.subscriptions.push(
80-
registerCommand(GlCommand.PlusSimulateSubscription, () => this.showSimulator()),
79+
registerCommand('gitlens.plus.simulateSubscription', () => this.showSimulator()),
8180
);
8281
}
8382

src/plus/gk/models/promo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { GlCommands } from '../../../constants.commands';
12
import type { SubscriptionState } from '../../../constants.subscription';
23

34
export type PromoLocation = 'account' | 'badge' | 'gate' | 'home';
@@ -20,7 +21,7 @@ export interface Promo {
2021
readonly link?: {
2122
readonly html: string;
2223
readonly title: string;
23-
readonly command?: `command:${string}`;
24+
readonly command?: GlCommands;
2425
};
2526
};
2627
};

src/plus/gk/productConfigProvider.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { GlCommands } from '../../constants.commands';
12
import { SubscriptionState } from '../../constants.subscription';
23
import type { Container } from '../../container';
34
import { deviceCohortGroup } from '../../system/-webview/vscode';
@@ -152,13 +153,13 @@ function createConfigValidator(): Validator<ConfigJson> {
152153
html: Is.Optional(Is.String),
153154
});
154155

155-
const isCommandPattern = (value: unknown): value is `command:${string}` =>
156-
typeof value === 'string' && value.startsWith('command:');
156+
const isCommandPattern = (value: unknown): value is GlCommands =>
157+
typeof value === 'string' && value.startsWith('gitlens.');
157158

158159
const isWebviewLink = createValidator({
159160
html: Is.String,
160161
title: Is.String,
161-
command: Is.Optional((value): value is `command:${string}` => isCommandPattern(value)),
162+
command: Is.Optional((value): value is GlCommands => isCommandPattern(value)),
162163
});
163164

164165
const isWebview = createValidator({

src/plus/gk/subscriptionService.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { getPlatform } from '@env/platform';
2323
import type { OpenWalkthroughCommandArgs } from '../../commands/walkthroughs';
2424
import { urls } from '../../constants';
2525
import type { CoreColors } from '../../constants.colors';
26-
import { GlCommand } from '../../constants.commands';
26+
import type { GlCommands } from '../../constants.commands';
2727
import type { StoredFeaturePreviewUsagePeriod } from '../../constants.storage';
2828
import {
2929
proFeaturePreviewUsageDurationInDays,
@@ -51,6 +51,7 @@ import { executeCommand, registerCommand } from '../../system/-webview/command';
5151
import { configuration } from '../../system/-webview/configuration';
5252
import { setContext } from '../../system/-webview/context';
5353
import { openUrl } from '../../system/-webview/vscode';
54+
import { createCommandLink } from '../../system/commands';
5455
import { createFromDateDelta, fromNow } from '../../system/date';
5556
import { gate } from '../../system/decorators/-webview/gate';
5657
import { debug, log } from '../../system/decorators/log';
@@ -339,24 +340,24 @@ export class SubscriptionService implements Disposable {
339340

340341
private registerCommands(): Disposable[] {
341342
return [
342-
registerCommand(GlCommand.PlusLogin, (src?: Source) => this.loginOrSignUp(false, src)),
343-
registerCommand(GlCommand.PlusSignUp, (src?: Source) => this.loginOrSignUp(true, src)),
344-
registerCommand(GlCommand.PlusLogout, (src?: Source) => this.logout(src)),
345-
registerCommand(GlCommand.GKSwitchOrganization, (src?: Source) => this.switchOrganization(src)),
343+
registerCommand('gitlens.plus.login', (src?: Source) => this.loginOrSignUp(false, src)),
344+
registerCommand('gitlens.plus.signUp', (src?: Source) => this.loginOrSignUp(true, src)),
345+
registerCommand('gitlens.plus.logout', (src?: Source) => this.logout(src)),
346+
registerCommand('gitlens.gk.switchOrganization', (src?: Source) => this.switchOrganization(src)),
346347

347-
registerCommand(GlCommand.PlusManage, (src?: Source) => this.manage(src)),
348-
registerCommand(GlCommand.PlusShowPlans, (src?: Source) => this.showPlans(src)),
349-
registerCommand(GlCommand.PlusStartPreviewTrial, (src?: Source) => this.startPreviewTrial(src)),
350-
registerCommand(GlCommand.PlusReactivateProTrial, (src?: Source) => this.reactivateProTrial(src)),
351-
registerCommand(GlCommand.PlusResendVerification, (src?: Source) => this.resendVerification(src)),
352-
registerCommand(GlCommand.PlusUpgrade, (src?: Source) => this.upgrade(src)),
348+
registerCommand('gitlens.plus.manage', (src?: Source) => this.manage(src)),
349+
registerCommand('gitlens.plus.showPlans', (src?: Source) => this.showPlans(src)),
350+
registerCommand('gitlens.plus.startPreviewTrial', (src?: Source) => this.startPreviewTrial(src)),
351+
registerCommand('gitlens.plus.reactivateProTrial', (src?: Source) => this.reactivateProTrial(src)),
352+
registerCommand('gitlens.plus.resendVerification', (src?: Source) => this.resendVerification(src)),
353+
registerCommand('gitlens.plus.upgrade', (src?: Source) => this.upgrade(src)),
353354

354-
registerCommand(GlCommand.PlusHide, (src?: Source) => this.setProFeaturesVisibility(false, src)),
355-
registerCommand(GlCommand.PlusRestore, (src?: Source) => this.setProFeaturesVisibility(true, src)),
355+
registerCommand('gitlens.plus.hide', (src?: Source) => this.setProFeaturesVisibility(false, src)),
356+
registerCommand('gitlens.plus.restore', (src?: Source) => this.setProFeaturesVisibility(true, src)),
356357

357-
registerCommand(GlCommand.PlusValidate, (src?: Source) => this.validate({ force: true }, src)),
358+
registerCommand('gitlens.plus.validate', (src?: Source) => this.validate({ force: true }, src)),
358359

359-
registerCommand(GlCommand.PlusContinueFeaturePreview, ({ feature }: { feature: FeaturePreviews }) =>
360+
registerCommand('gitlens.plus.continueFeaturePreview', ({ feature }: { feature: FeaturePreviews }) =>
360361
this.continueFeaturePreview(feature),
361362
),
362363
];
@@ -797,7 +798,7 @@ export class SubscriptionService implements Disposable {
797798
if (silent && !configuration.get('plusFeatures.enabled', undefined, true)) return;
798799

799800
if (!this.container.views.home.visible) {
800-
await executeCommand(GlCommand.ShowAccountView);
801+
await executeCommand('gitlens.showAccountView');
801802
}
802803
}
803804

@@ -855,7 +856,10 @@ export class SubscriptionService implements Disposable {
855856
const result = await window.showInformationMessage(
856857
`You can now preview local Pro features for ${
857858
days < 1 ? '1 day' : pluralize('day', days)
858-
}, or for full access to all GitLens Pro features, [start your free ${proTrialLengthInDays}-day Pro trial](command:gitlens.plus.signUp "Try GitLens Pro") — no credit card required.`,
859+
}, or for full access to all GitLens Pro features, [start your free ${proTrialLengthInDays}-day Pro trial](${createCommandLink<Source>(
860+
'gitlens.plus.signUp',
861+
source,
862+
)} "Try GitLens Pro") — no credit card required.`,
859863
confirm,
860864
learn,
861865
);
@@ -1587,7 +1591,7 @@ export class SubscriptionService implements Disposable {
15871591

15881592
this._statusBarSubscription.name = 'GitLens Pro';
15891593
this._statusBarSubscription.text = '$(gitlens-gitlens)';
1590-
this._statusBarSubscription.command = GlCommand.ShowAccountView;
1594+
this._statusBarSubscription.command = 'gitlens.showAccountView' satisfies GlCommands;
15911595
this._statusBarSubscription.backgroundColor = undefined;
15921596

15931597
if (account?.verified === false) {

src/plus/startWork/startWork.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import slug from 'slug';
22
import type { QuickInputButton, QuickPick, QuickPickItem } from 'vscode';
33
import { Uri } from 'vscode';
44
import { md5 } from '@env/crypto';
5+
import type { ManageCloudIntegrationsCommandArgs } from '../../commands/cloudIntegrations';
56
import type {
67
AsyncStepResultGenerator,
78
PartialStepState,
@@ -26,7 +27,6 @@ import {
2627
} from '../../commands/quickCommand.buttons';
2728
import { getSteps } from '../../commands/quickWizard.utils';
2829
import { proBadge } from '../../constants';
29-
import { GlCommand } from '../../constants.commands';
3030
import type { IntegrationId } from '../../constants.integrations';
3131
import { HostingIntegrationId, IssueIntegrationId, SelfHostedIntegrationId } from '../../constants.integrations';
3232
import type { Source, Sources, StartWorkTelemetryContext, TelemetryEvents } from '../../constants.telemetry';
@@ -514,7 +514,9 @@ export abstract class StartWorkBaseCommand extends QuickCommand<State> {
514514
return StepResultBreak;
515515
} else if (isManageIntegrationsItem(element)) {
516516
this.sendActionTelemetry('manage', context);
517-
executeCommand(GlCommand.PlusManageCloudIntegrations, { source: this.overrides?.ownSource ?? 'startWork' });
517+
executeCommand<ManageCloudIntegrationsCommandArgs>('gitlens.plus.cloudIntegrations.manage', {
518+
source: { source: this.overrides?.ownSource ?? 'startWork' },
519+
});
518520
endSteps(state);
519521
return StepResultBreak;
520522
}

0 commit comments

Comments
 (0)