Skip to content

Commit 262dff9

Browse files
FrankLiu4138claude
andcommitted
fix(notification): distinguish "update" vs "install" in message body
Change buildNotificationMessage/buildCVENotificationMessage to accept ExtensionState instead of boolean. Outdated extension now shows "update extension and upgrade/fix" while not-installed shows "install extension and upgrade/fix" in both button and message. Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
1 parent f666dc6 commit 262dff9

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

src/upgrade/display/notificationManager.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { commands, ExtensionContext, extensions, window } from "vscode";
55
import * as semver from "semver";
66
import { UpgradeReason, type IUpgradeIssuesRenderer, type UpgradeIssue } from "../type";
7-
import { buildCVENotificationMessage, buildFixPrompt, buildNotificationMessage } from "../utility";
7+
import { buildCVENotificationMessage, buildFixPrompt, buildNotificationMessage, type ExtensionState } from "../utility";
88
import { Commands } from "../../commands";
99
import { Settings } from "../../settings";
1010
import { instrumentOperation, sendInfo } from "vscode-extension-telemetry-wrapper";
@@ -29,7 +29,7 @@ function getNowTs() {
2929
return Number(new Date()) / 1000;
3030
}
3131

32-
export type ExtensionState = "up-to-date" | "outdated" | "not-installed";
32+
export type { ExtensionState } from "../utility";
3333

3434
export interface NotificationContent {
3535
message: string;
@@ -58,11 +58,10 @@ export function buildNotificationContent(
5858
(i) => i.reason !== UpgradeReason.CVE
5959
);
6060
const hasCVEIssue = cveIssues.length > 0;
61-
const isReady = extensionState === "up-to-date";
6261

6362
const message = hasCVEIssue
64-
? buildCVENotificationMessage(cveIssues, isReady)
65-
: buildNotificationMessage(nonCVEIssues[0], isReady);
63+
? buildCVENotificationMessage(cveIssues, extensionState)
64+
: buildNotificationMessage(nonCVEIssues[0], extensionState);
6665

6766
let upgradeButtonText: string;
6867
let fixCVEButtonText: string;

src/upgrade/utility.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,20 @@ function findEolDate(currentVersion: string, eolDate: Record<string, string>): s
2222
return null;
2323
}
2424

25-
export function buildNotificationMessage(issue: UpgradeIssue, hasExtension: boolean): string {
25+
export type ExtensionState = "up-to-date" | "outdated" | "not-installed";
26+
27+
function getActionWord(extensionState: ExtensionState, verb: string): string {
28+
switch (extensionState) {
29+
case "up-to-date":
30+
return verb;
31+
case "outdated":
32+
return `update ${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension and ${verb}`;
33+
case "not-installed":
34+
return `install ${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension and ${verb}`;
35+
}
36+
}
37+
38+
export function buildNotificationMessage(issue: UpgradeIssue, extensionState: ExtensionState): string {
2639
const {
2740
packageId,
2841
currentVersion,
@@ -31,7 +44,7 @@ export function buildNotificationMessage(issue: UpgradeIssue, hasExtension: bool
3144
packageDisplayName
3245
} = issue;
3346

34-
const upgradeWord = hasExtension ? "upgrade" : `install ${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension and upgrade`;
47+
const upgradeWord = getActionWord(extensionState, "upgrade");
3548

3649
if (packageId === Upgrade.PACKAGE_ID_FOR_JAVA_RUNTIME) {
3750
return `This project is using an older Java runtime (${currentVersion}). Would you like to ${upgradeWord} it to the latest LTS version?`;
@@ -51,7 +64,7 @@ export function buildNotificationMessage(issue: UpgradeIssue, hasExtension: bool
5164
}
5265
}
5366

54-
export function buildCVENotificationMessage(issues: CveUpgradeIssue[], hasExtension: boolean): string {
67+
export function buildCVENotificationMessage(issues: CveUpgradeIssue[], extensionState: ExtensionState): string {
5568

5669
if (issues.length === 0) {
5770
return "No CVE issues found.";
@@ -81,7 +94,7 @@ export function buildCVENotificationMessage(issues: CveUpgradeIssue[], hasExtens
8194
CVESeverityDistribution: severityText,
8295
});
8396

84-
const fixWord = hasExtension ? "fix" : `install ${ExtensionName.APP_MODERNIZATION_EXTENSION_NAME} extension and fix`;
97+
const fixWord = getActionWord(extensionState, "fix");
8598

8699
if (issues.length === 1) {
87100
return `${severityText} CVE vulnerability is detected in this project. Would you like to ${fixWord} it now?`;
@@ -102,7 +115,7 @@ export function buildFixPrompt(issue: UpgradeIssue): string {
102115
return `upgrade ${packageDisplayName} to ${suggestedVersionName}`;
103116
}
104117
case UpgradeReason.CVE: {
105-
return `fix all critical and high-severity CVE vulnerabilities in this project by invoking #appmod-validate-cves-for-java`;
118+
return `fix all CVE vulnerabilities in this project`;
106119
}
107120
}
108121
}

0 commit comments

Comments
 (0)