Skip to content

Commit eabc137

Browse files
eamodioaxosoft-ramint
authored andcommitted
Tweaks messaging from review
1 parent bd0bf62 commit eabc137

File tree

4 files changed

+42
-71
lines changed

4 files changed

+42
-71
lines changed

src/features.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,31 @@ export type RepoFeatureAccess =
3030
visibility?: RepositoryVisibility;
3131
};
3232

33-
export type PlusFeatures =
33+
export type PlusFeatures = ProFeatures | AdvancedFeatures;
34+
35+
export type ProFeatures =
3436
| 'timeline'
3537
| 'worktrees'
3638
| 'graph'
3739
| 'launchpad'
3840
| 'startWork'
3941
| 'associateIssueWithBranch'
40-
| 'generateStashMessage'
41-
| 'explainCommit'
42-
| 'cloudPatchGenerateTitleAndDescription';
43-
export type AdvancedFeatures = 'generateChangelog';
42+
| ProAIFeatures;
43+
export type ProAIFeatures = 'generateStashMessage' | 'explainCommit' | 'cloudPatchGenerateTitleAndDescription';
44+
45+
export type AdvancedFeatures = AdvancedAIFeatures;
46+
export type AdvancedAIFeatures = 'generateChangelog';
47+
48+
export type AIFeatures = ProAIFeatures | AdvancedAIFeatures;
49+
50+
export function isAdvancedFeature(feature: PlusFeatures): feature is AdvancedFeatures {
51+
switch (feature) {
52+
case 'generateChangelog':
53+
return true;
54+
default:
55+
return false;
56+
}
57+
}
4458

4559
export type FeaturePreviews = 'graph';
4660
export const featurePreviews: FeaturePreviews[] = ['graph'];

src/git/gitProviderService.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { GlyphChars, Schemes } from '../constants';
1616
import { SubscriptionPlanId } from '../constants.subscription';
1717
import type { Container } from '../container';
1818
import { AccessDeniedError, ProviderNotFoundError, ProviderNotSupportedError } from '../errors';
19-
import type { AdvancedFeatures, FeatureAccess, Features, PlusFeatures, RepoFeatureAccess } from '../features';
19+
import type { FeatureAccess, Features, PlusFeatures, RepoFeatureAccess } from '../features';
2020
import type { Subscription } from '../plus/gk/models/subscription';
2121
import type { SubscriptionChangeEvent } from '../plus/gk/subscriptionService';
2222
import { isSubscriptionPaidPlan } from '../plus/gk/utils/subscription.utils';
@@ -722,26 +722,17 @@ export class GitProviderService implements Disposable {
722722
return this._subscription ?? (this._subscription = await this.container.subscription.getSubscription());
723723
}
724724

725-
private _accessCache = new Map<PlusFeatures | AdvancedFeatures | undefined, Promise<FeatureAccess>>();
725+
private _accessCache = new Map<PlusFeatures | undefined, Promise<FeatureAccess>>();
726726
private _accessCacheByRepo = new Map<string /* path */, Promise<RepoFeatureAccess>>();
727727
private clearAccessCache(): void {
728728
this._accessCache.clear();
729729
this._accessCacheByRepo.clear();
730730
}
731731

732-
async access(
733-
feature: PlusFeatures | AdvancedFeatures | undefined,
734-
repoPath: string | Uri,
735-
): Promise<RepoFeatureAccess>;
736-
async access(
737-
feature?: PlusFeatures | AdvancedFeatures,
738-
repoPath?: string | Uri,
739-
): Promise<FeatureAccess | RepoFeatureAccess>;
732+
async access(feature: PlusFeatures | undefined, repoPath: string | Uri): Promise<RepoFeatureAccess>;
733+
async access(feature?: PlusFeatures, repoPath?: string | Uri): Promise<FeatureAccess | RepoFeatureAccess>;
740734
@debug({ exit: true })
741-
async access(
742-
feature?: PlusFeatures | AdvancedFeatures,
743-
repoPath?: string | Uri,
744-
): Promise<FeatureAccess | RepoFeatureAccess> {
735+
async access(feature?: PlusFeatures, repoPath?: string | Uri): Promise<FeatureAccess | RepoFeatureAccess> {
745736
if (repoPath == null) {
746737
let access = this._accessCache.get(feature);
747738
if (access == null) {
@@ -763,17 +754,14 @@ export class GitProviderService implements Disposable {
763754
return access;
764755
}
765756

757+
private async accessCore(feature: PlusFeatures | undefined, repoPath: string | Uri): Promise<RepoFeatureAccess>;
766758
private async accessCore(
767-
feature: PlusFeatures | AdvancedFeatures | undefined,
768-
repoPath: string | Uri,
769-
): Promise<RepoFeatureAccess>;
770-
private async accessCore(
771-
feature?: PlusFeatures | AdvancedFeatures,
759+
feature?: PlusFeatures,
772760
repoPath?: string | Uri,
773761
): Promise<FeatureAccess | RepoFeatureAccess>;
774762
@debug({ exit: true })
775763
private async accessCore(
776-
feature?: PlusFeatures | AdvancedFeatures,
764+
feature?: PlusFeatures,
777765
repoPath?: string | Uri,
778766
): Promise<FeatureAccess | RepoFeatureAccess> {
779767
const subscription = await this.getSubscription();
@@ -870,7 +858,7 @@ export class GitProviderService implements Disposable {
870858
return getRepoAccess.call(this, repoPath, true);
871859
}
872860

873-
async ensureAccess(feature: PlusFeatures | AdvancedFeatures, repoPath?: string): Promise<void> {
861+
async ensureAccess(feature: PlusFeatures, repoPath?: string): Promise<void> {
874862
const { allowed, subscription } = await this.access(feature, repoPath);
875863
if (allowed === false) throw new AccessDeniedError(subscription.current, subscription.required);
876864
}

src/plus/ai/aiProviderService.ts

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { primaryAIProviders } from '../../constants.ai';
55
import type { AIGenerateDraftEventData, Source, TelemetryEvents } from '../../constants.telemetry';
66
import type { Container } from '../../container';
77
import { CancellationError } from '../../errors';
8-
import type { AdvancedFeatures, PlusFeatures } from '../../features';
8+
import type { AIFeatures } from '../../features';
9+
import { isAdvancedFeature } from '../../features';
910
import type { GitCommit } from '../../git/models/commit';
1011
import { isCommit } from '../../git/models/commit';
1112
import type { GitRevisionReference } from '../../git/models/reference';
@@ -297,22 +298,16 @@ export class AIProviderService implements Disposable {
297298
return true;
298299
}
299300

300-
private async ensureFeatureAccess(
301-
feature:
302-
| 'generateStashMessage'
303-
| 'explainCommit'
304-
| 'cloudPatchGenerateTitleAndDescription'
305-
| 'generateChangelog',
306-
title: string,
307-
source: Source,
308-
): Promise<boolean> {
301+
private async ensureFeatureAccess(feature: AIFeatures, source: Source): Promise<boolean> {
309302
if (!(await this.ensureOrgAccess())) return false;
310303

311304
if (
312305
!(await ensureFeatureAccess(
313306
this.container,
314-
title,
315-
feature satisfies PlusFeatures | AdvancedFeatures,
307+
isAdvancedFeature(feature)
308+
? `Advanced AI features require a trial or GitLens Advanced.`
309+
: `Pro AI features require a trial or GitLens Pro.`,
310+
feature,
316311
source,
317312
))
318313
) {
@@ -327,13 +322,7 @@ export class AIProviderService implements Disposable {
327322
sourceContext: Source & { type: TelemetryEvents['ai/explain']['changeType'] },
328323
options?: { cancellation?: CancellationToken; progress?: ProgressOptions },
329324
): Promise<AISummarizeResult | undefined> {
330-
if (
331-
!(await this.ensureFeatureAccess(
332-
'explainCommit' satisfies PlusFeatures,
333-
'Explaining commits requires an account with Pro access.',
334-
sourceContext,
335-
))
336-
) {
325+
if (!(await this.ensureFeatureAccess('explainCommit', sourceContext))) {
337326
return undefined;
338327
}
339328

@@ -427,15 +416,7 @@ export class AIProviderService implements Disposable {
427416
codeSuggestion?: boolean;
428417
},
429418
): Promise<AISummarizeResult | undefined> {
430-
if (
431-
!(await this.ensureFeatureAccess(
432-
'cloudPatchGenerateTitleAndDescription' satisfies PlusFeatures,
433-
`Generating ${
434-
options?.codeSuggestion ? 'code suggestion' : 'cloud patch'
435-
} descriptions requires an account with Pro access.`,
436-
sourceContext,
437-
))
438-
) {
419+
if (!(await this.ensureFeatureAccess('cloudPatchGenerateTitleAndDescription', sourceContext))) {
439420
return undefined;
440421
}
441422

@@ -485,13 +466,7 @@ export class AIProviderService implements Disposable {
485466
progress?: ProgressOptions;
486467
},
487468
): Promise<AISummarizeResult | undefined> {
488-
if (
489-
!(await this.ensureFeatureAccess(
490-
'generateStashMessage' satisfies PlusFeatures,
491-
'Generating stash messages requires an account with Pro access.',
492-
source,
493-
))
494-
) {
469+
if (!(await this.ensureFeatureAccess('generateStashMessage', source))) {
495470
return undefined;
496471
}
497472

@@ -530,13 +505,7 @@ export class AIProviderService implements Disposable {
530505
source: Source,
531506
options?: { cancellation?: CancellationToken; progress?: ProgressOptions },
532507
): Promise<AIResult | undefined> {
533-
if (
534-
!(await this.ensureFeatureAccess(
535-
'generateChangelog' satisfies AdvancedFeatures,
536-
'Generating changelogs requires an account with Pro access.',
537-
source,
538-
))
539-
) {
508+
if (!(await this.ensureFeatureAccess('generateChangelog', source))) {
540509
return undefined;
541510
}
542511

src/plus/gk/utils/-webview/acount.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Uri } from 'vscode';
22
import { window } from 'vscode';
33
import type { Source } from '../../../../constants.telemetry';
44
import type { Container } from '../../../../container';
5-
import type { AdvancedFeatures, PlusFeatures } from '../../../../features';
5+
import type { PlusFeatures } from '../../../../features';
66

77
export async function ensureAccount(container: Container, title: string, source: Source): Promise<boolean> {
88
while (true) {
@@ -58,7 +58,7 @@ export async function ensureAccount(container: Container, title: string, source:
5858
export async function ensureFeatureAccess(
5959
container: Container,
6060
title: string,
61-
feature: PlusFeatures | AdvancedFeatures,
61+
feature: PlusFeatures,
6262
source: Source,
6363
repoPath?: string | Uri,
6464
): Promise<boolean> {
@@ -71,7 +71,7 @@ export async function ensureFeatureAccess(
7171
const upgrade = { title: 'Upgrade to Pro' };
7272
const cancel = { title: 'Cancel', isCloseAffordance: true };
7373
const result = await window.showWarningMessage(
74-
`${title}\n\nUpgrade to Pro to access this feature.`,
74+
`${title}\n\nPlease upgrade to GitLens Pro to continue.`,
7575
{ modal: true },
7676
upgrade,
7777
cancel,

0 commit comments

Comments
 (0)