From cf021fd450b2799e665c72268032a8ec010a755c Mon Sep 17 00:00:00 2001 From: John Steele Date: Thu, 5 Sep 2024 13:28:08 -0700 Subject: [PATCH] feat: New preference to enable/disable analysis upon open or save manifest documents. Signed-off-by: John Steele --- package.json | 12 ++++++++++++ src/config.ts | 12 ++++++++++++ test/config.test.ts | 3 +++ 3 files changed, 27 insertions(+) diff --git a/package.json b/package.json index 50b1a9fa..83206465 100644 --- a/package.json +++ b/package.json @@ -181,6 +181,18 @@ "type": "object", "title": "Red Hat Dependency Analytics configuration", "properties": { + "redHatDependencyAnalytics.analyzeOnOpenDocument": { + "type": "boolean", + "default": false, + "markdownDescription": "Automatically run analysis upon opening any supported manifest file (package.json, pom.xml, go.mod, requirements.txt, build.gradle, Dockerfile, Containerfile).", + "scope": "window" + }, + "redHatDependencyAnalytics.analyzeOnSaveDocument": { + "type": "boolean", + "default": false, + "markdownDescription": "Automatically run analysis upon saving any supported manifest file (package.json, pom.xml, go.mod, requirements.txt, build.gradle, Dockerfile, Containerfile).", + "scope": "window" + }, "redhat.telemetry.enabled": { "type": "boolean", "default": null, diff --git a/src/config.ts b/src/config.ts index f6306bc0..031a6243 100644 --- a/src/config.ts +++ b/src/config.ts @@ -10,6 +10,10 @@ import { getTelemetryId } from './redhatTelemetry'; * Represents the configuration settings for the extension. */ class Config { + + analyzeOnOpenDocument: string; + analyzeOnSaveDocument: string; + telemetryId: string; stackAnalysisCommand: string; trackRecommendationAcceptanceCommand: string; @@ -74,6 +78,9 @@ class Config { loadData() { const rhdaConfig = this.getRhdaConfig(); + this.analyzeOnOpenDocument = rhdaConfig.analyzeOnOpenDocument ? 'true' : 'false'; + this.analyzeOnSaveDocument = rhdaConfig.analyzeOnSaveDocument ? 'true' : 'false'; + this.stackAnalysisCommand = commands.STACK_ANALYSIS_COMMAND; this.trackRecommendationAcceptanceCommand = commands.TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND; this.utmSource = GlobalState.UTM_SOURCE; @@ -112,6 +119,11 @@ class Config { * @private */ private async setProcessEnv(): Promise { + + process.env['VSCEXT_ANALYZE_ON_OPEN_DOCUMENT'] = this.analyzeOnOpenDocument; + process.env['VSCEXT_ANALYZE_ON_SAVE_DOCUMENT'] = this.analyzeOnSaveDocument; + + process.env['VSCEXT_STACK_ANALYSIS_COMMAND'] = this.stackAnalysisCommand; process.env['VSCEXT_TRACK_RECOMMENDATION_ACCEPTANCE_COMMAND'] = this.trackRecommendationAcceptanceCommand; process.env['VSCEXT_UTM_SOURCE'] = this.utmSource; diff --git a/test/config.test.ts b/test/config.test.ts index 0ccd2d23..0d9e82f0 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -71,6 +71,9 @@ suite('Config module', () => { expect(globalConfig.telemetryId).to.equal(mockId); + expect(process.env['VSCEXT_ANALYZE_ON_OPEN_DOCUMENT']).to.eq('false'); + expect(process.env['VSCEXT_ANALYZE_ON_SAVE_DOCUMENT']).to.eq('false'); + expect(process.env['VSCEXT_STACK_ANALYSIS_COMMAND']).to.eq(commands.STACK_ANALYSIS_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);