diff --git a/package-lock.json b/package-lock.json index 408e69e8..0c957113 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,9 @@ "version": "0.9.4", "license": "Apache-2.0", "dependencies": { - "@fabric8-analytics/fabric8-analytics-lsp-server": "^0.9.4-ea.6", + "@fabric8-analytics/fabric8-analytics-lsp-server": "^0.9.4-ea.8", "@redhat-developer/vscode-redhat-telemetry": "^0.7.0", - "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.26", + "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.27", "fs": "^0.0.1-security", "path": "^0.12.7", "vscode-languageclient": "^8.1.0" @@ -568,12 +568,12 @@ } }, "node_modules/@fabric8-analytics/fabric8-analytics-lsp-server": { - "version": "0.9.4-ea.6", - "resolved": "https://npm.pkg.github.com/download/@fabric8-analytics/fabric8-analytics-lsp-server/0.9.4-ea.6/f43cb1fae9d5c3498d9825390d0f1009a23cfc12", - "integrity": "sha512-0syQBZtmhctHal8mlRdwonidfF54jstKWSl6C1GDSp7yqEUVm6Zgw3FO6VYZB0FZhTnscXLc3A4JOzN51+cM9w==", + "version": "0.9.4-ea.8", + "resolved": "https://npm.pkg.github.com/download/@fabric8-analytics/fabric8-analytics-lsp-server/0.9.4-ea.8/12728669037376afa88fe88dce0c6f77befc75d9", + "integrity": "sha512-NOmDbSNWyhCcWSS8hyKIM6t09cIYUmC8iDEUIJrOR9KwZ+LBiOuNeOEKfAlEcDnBn2l5Vrpr+WmmF6HuOCjipg==", "license": "Apache-2.0", "dependencies": { - "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.26", + "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.27", "@xml-tools/ast": "^5.0.5", "@xml-tools/parser": "^1.0.11", "json-to-ast": "^2.1.0", @@ -950,9 +950,9 @@ } }, "node_modules/@RHEcosystemAppEng/exhort-javascript-api": { - "version": "0.1.1-ea.26", - "resolved": "https://npm.pkg.github.com/download/@RHEcosystemAppEng/exhort-javascript-api/0.1.1-ea.26/883fb514fb41a6e1f52e426e1ed1d9c8fae26eed", - "integrity": "sha512-2QORNJ4vrYWyIgKai09HQs+AM9s9JCuJffrGB6CT9OnY7L+I4LT+YN6iHIo0rvoaQR4MfQl4OmXfHij1HuQ8VQ==", + "version": "0.1.1-ea.27", + "resolved": "https://npm.pkg.github.com/download/@RHEcosystemAppEng/exhort-javascript-api/0.1.1-ea.27/59951c3d4dd9e28d8d3d445699ace4b6723a932f", + "integrity": "sha512-7to/lt4KNcTq8ZFASK2Cn6ElsbLrKZHmrPIHuKPkGod8TutwoFhrWv5sMXvsIvd6wvxdKF0PZUZn/PbOg7HYVw==", "license": "Apache-2.0", "dependencies": { "@babel/core": "^7.23.2", diff --git a/package.json b/package.json index 20c7c1a4..ed170862 100644 --- a/package.json +++ b/package.json @@ -297,9 +297,9 @@ "webpack-cli": "^5.1.4" }, "dependencies": { - "@fabric8-analytics/fabric8-analytics-lsp-server": "^0.9.4-ea.6", + "@fabric8-analytics/fabric8-analytics-lsp-server": "^0.9.4-ea.8", "@redhat-developer/vscode-redhat-telemetry": "^0.7.0", - "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.26", + "@RHEcosystemAppEng/exhort-javascript-api": "^0.1.1-ea.27", "fs": "^0.0.1-security", "path": "^0.12.7", "vscode-languageclient": "^8.1.0" diff --git a/src/commands.ts b/src/commands.ts index 1ab8c88b..f8617bdd 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -9,5 +9,5 @@ export const STACK_ANALYSIS_FROM_EXPLORER_COMMAND = 'rhda.stackAnalysisFromExplo export const STACK_ANALYSIS_FROM_PIE_BTN_COMMAND = 'rhda.stackAnalysisFromPieBtn'; export const STACK_ANALYSIS_FROM_EDITOR_COMMAND = 'rhda.stackAnalysisFromEditor'; export const STACK_LOGS_COMMAND = 'rhda.stackLogs'; -export const REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION_COMMAND = 'rhda.rhRepositoryRecommendationNotification'; -export const SET_SNYK_TOKEN_COMMAND = 'rhda.setSnykToken'; \ No newline at end of file +export const SET_SNYK_TOKEN_COMMAND = 'rhda.setSnykToken'; +export const TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND = 'rhda.trackRecommendationAcceptance'; \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index 8f7e5247..ff29fca3 100644 --- a/src/config.ts +++ b/src/config.ts @@ -12,7 +12,7 @@ import { getTelemetryId } from './redhatTelemetry'; class Config { telemetryId: string; stackAnalysisCommand: string; - rhRepositoryRecommendationNotificationCommand: string; + trackRecommendationAcceptanceCommand: string; utmSource: string; matchManifestVersions: string; usePythonVirtualEnvironment: string; @@ -62,7 +62,7 @@ class Config { const rhdaConfig = this.getRhdaConfig(); this.stackAnalysisCommand = commands.STACK_ANALYSIS_COMMAND; - this.rhRepositoryRecommendationNotificationCommand = commands.REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION_COMMAND; + this.trackRecommendationAcceptanceCommand = commands.TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND; this.utmSource = GlobalState.UTM_SOURCE; /* istanbul ignore next */ this.matchManifestVersions = rhdaConfig.matchManifestVersions ? 'true' : 'false'; @@ -92,7 +92,7 @@ class Config { */ private async setProcessEnv(): Promise { process.env['VSCEXT_STACK_ANALYSIS_COMMAND'] = this.stackAnalysisCommand; - process.env['VSCEXT_REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION_COMMAND'] = this.rhRepositoryRecommendationNotificationCommand; + process.env['VSCEXT_TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND'] = this.trackRecommendationAcceptanceCommand; process.env['VSCEXT_UTM_SOURCE'] = this.utmSource; process.env['VSCEXT_MATCH_MANIFEST_VERSIONS'] = this.matchManifestVersions; process.env['VSCEXT_USE_PYTHON_VIRTUAL_ENVIRONMENT'] = this.usePythonVirtualEnvironment; diff --git a/src/extension.ts b/src/extension.ts index 48cb6820..a4525a83 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -64,14 +64,14 @@ export function activate(context: vscode.ExtensionContext) { } ); - const rhRepositoryRecommendationNotification = vscode.commands.registerCommand( - commands.REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION_COMMAND, - () => { - const msg = `Important: If you apply Red Hat Dependency Analytics recommendations, - make sure the Red Hat GA Repository (${REDHAT_MAVEN_REPOSITORY}) has been added to your project configuration. - This ensures that the applied dependencies work correctly. - Learn how to add the repository: [Click here](${REDHAT_MAVEN_REPOSITORY_DOCUMENTATION_URL})`; - vscode.window.showWarningMessage(msg); + const disposableTrackRecommendationAcceptance = vscode.commands.registerCommand( + commands.TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND, + (dependency, fileName) => { + record(context, TelemetryActions.componentAnalysisRecommendationAccepted, { manifest: fileName, fileName: fileName, package: dependency.split('@')[0], version: dependency.split('@')[1] }); + + if (fileName === 'pom.xml') { + showRHRepositoryRecommendationNotification(); + } } ); @@ -177,7 +177,7 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push( disposableStackAnalysisCommand, disposableStackLogsCommand, - rhRepositoryRecommendationNotification, + disposableTrackRecommendationAcceptance, // disposableSetSnykToken, caStatusBarProvider, ); @@ -242,6 +242,17 @@ async function showUpdateNotification(context: vscode.ExtensionContext) { } } +/** + * Shows a notification regarding Red Hat Dependency Analytics recommendations. + */ +function showRHRepositoryRecommendationNotification() { + const msg = `Important: If you apply Red Hat Dependency Analytics recommendations, + make sure the Red Hat GA Repository (${REDHAT_MAVEN_REPOSITORY}) has been added to your project configuration. + This ensures that the applied dependencies work correctly. + Learn how to add the repository: [Click here](${REDHAT_MAVEN_REPOSITORY_DOCUMENTATION_URL})`; + vscode.window.showWarningMessage(msg); +} + /** * Registers stack analysis commands to track RHDA report generations. * @param context - The extension context. diff --git a/src/redhatTelemetry.ts b/src/redhatTelemetry.ts index f61c7382..dc1ba3e1 100644 --- a/src/redhatTelemetry.ts +++ b/src/redhatTelemetry.ts @@ -7,6 +7,7 @@ import { getRedHatService, TelemetryEvent, TelemetryService } from '@redhat-deve enum TelemetryActions { componentAnalysisDone = 'component_analysis_done', componentAnalysisFailed = 'component_analysis_failed', + componentAnalysisRecommendationAccepted = 'component_analysis_recommendation_accepted', vulnerabilityReportDone = 'vulnerability_report_done', vulnerabilityReportFailed = 'vulnerability_report_failed', vulnerabilityReportEditor = 'vulnerability_report_editor', diff --git a/src/utils.ts b/src/utils.ts index 2bfbc9b7..e2f98a15 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,6 +2,13 @@ import { settingNameMappings } from './constants'; +/** + * Applies setting name mappings to a given message. + * This function replaces occurrences of keys in the `settingNameMappings` object + * with their corresponding values in the provided message. + * @param message - The message to which setting name mappings will be applied. + * @returns The modified message with setting name mappings applied. + */ export function applySettingNameMappings(message: string): string { let modifiedMessage = message; diff --git a/test/config.test.ts b/test/config.test.ts index 617370d1..209ba727 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -30,7 +30,7 @@ suite('Config module', () => { test('should initialize Config properties with default extension settings', async () => { expect(globalConfig.stackAnalysisCommand).to.eq(commands.STACK_ANALYSIS_COMMAND); - expect(globalConfig.rhRepositoryRecommendationNotificationCommand).to.eq(commands.REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION_COMMAND); + expect(globalConfig.trackRecommendationAcceptanceCommand).to.eq(commands.TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND); expect(globalConfig.utmSource).to.eq(GlobalState.UTM_SOURCE); expect(globalConfig.matchManifestVersions).to.eq('true'); expect(globalConfig.usePythonVirtualEnvironment).to.eq('false'); @@ -64,7 +64,7 @@ suite('Config module', () => { expect(globalConfig.telemetryId).to.equal(mockId); expect(process.env['VSCEXT_STACK_ANALYSIS_COMMAND']).to.eq(commands.STACK_ANALYSIS_COMMAND); - expect(process.env['VSCEXT_REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION_COMMAND']).to.eq(commands.REDHAT_REPOSITORY_RECOMMENDATION_NOTIFICATION_COMMAND); + expect(process.env['VSCEXT_TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND']).to.eq(commands.TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND); expect(process.env['VSCEXT_UTM_SOURCE']).to.eq(GlobalState.UTM_SOURCE); expect(process.env['VSCEXT_MATCH_MANIFEST_VERSIONS']).to.eq('true'); expect(process.env['VSCEXT_USE_PYTHON_VIRTUAL_ENVIRONMENT']).to.eq('false'); diff --git a/test/extension.test.ts b/test/extension.test.ts index 0056c4f7..0c9adc30 100644 --- a/test/extension.test.ts +++ b/test/extension.test.ts @@ -19,6 +19,7 @@ suite('Fabric8 Analytics Extension', () => { const FABRIC8_COMMANDS: string[] = [ Commands.STACK_ANALYSIS_COMMAND, Commands.STACK_LOGS_COMMAND, + Commands.TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND, Commands.STACK_ANALYSIS_FROM_EDITOR_COMMAND, Commands.STACK_ANALYSIS_FROM_EXPLORER_COMMAND, Commands.STACK_ANALYSIS_FROM_PIE_BTN_COMMAND,