Skip to content

Commit

Permalink
chore: track redhat version recommendation acceptance for telemetry
Browse files Browse the repository at this point in the history
Signed-off-by: Ilona Shishov <[email protected]>
  • Loading branch information
IlonaShishov committed Mar 31, 2024
1 parent 3a0c635 commit 48d5207
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 27 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
export const SET_SNYK_TOKEN_COMMAND = 'rhda.setSnykToken';
export const TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND = 'rhda.trackRecommendationAcceptance';
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getTelemetryId } from './redhatTelemetry';
class Config {
telemetryId: string;
stackAnalysisCommand: string;
rhRepositoryRecommendationNotificationCommand: string;
trackRecommendationAcceptanceCommand: string;
utmSource: string;
matchManifestVersions: string;
usePythonVirtualEnvironment: string;
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -92,7 +92,7 @@ class Config {
*/
private async setProcessEnv(): Promise<void> {
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;
Expand Down
29 changes: 20 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
);

Expand Down Expand Up @@ -177,7 +177,7 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
disposableStackAnalysisCommand,
disposableStackLogsCommand,
rhRepositoryRecommendationNotification,
disposableTrackRecommendationAcceptance,
// disposableSetSnykToken,
caStatusBarProvider,
);
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/redhatTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 48d5207

Please sign in to comment.