Skip to content

Commit

Permalink
feat: New preference to enable/disable analysis upon open or save man…
Browse files Browse the repository at this point in the history
…ifest documents.

Signed-off-by: John Steele <[email protected]>
  • Loading branch information
johnsteele committed Sep 5, 2024
1 parent a450036 commit cf021fd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -112,6 +119,11 @@ class Config {
* @private
*/
private async setProcessEnv(): Promise<void> {

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;
Expand Down
3 changes: 3 additions & 0 deletions test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cf021fd

Please sign in to comment.