Skip to content

Commit d5ea5c7

Browse files
committed
feat: add 'ignore for this file' in notifications
1 parent 63b43de commit d5ea5c7

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ class Config {
201201
// process.env['VSCEXT_EXHORT_SNYK_TOKEN'] = token;
202202
}
203203

204+
/**
205+
* Adds a path to the workspace-local redHatDependencyAnalytics.exclude list.
206+
* @param path The path to add
207+
*/
208+
async addFileToExcludeList(path: string) {
209+
const original = vscode.workspace.getConfiguration('redHatDependencyAnalytics').inspect('exclude');
210+
const newValues = [...((original?.workspaceValue as string[] | undefined) || []), path];
211+
await vscode.workspace.getConfiguration('redHatDependencyAnalytics').update('exclude', newValues);
212+
}
213+
204214
/**
205215
* Authorizes the RHDA (Red Hat Dependency Analytics) service.
206216
* @param context The extension context for authorization.

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export enum StatusMessages {
2121
export enum PromptText {
2222
FULL_STACK_PROMPT_TEXT = `Open Red Hat Dependency Analytics Report`,
2323
LSP_FAILURE_TEXT = `Open the output window`,
24+
IGNORE_FILE = 'Ignore this file',
2425
}
2526

2627
export enum Titles {

src/extension.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ export async function activate(context: vscode.ExtensionContext) {
105105

106106
const showVulnerabilityFoundPrompt = async (msg: string, filePath: vscode.Uri) => {
107107
const fileName = path.basename(filePath.fsPath);
108-
const selection = await vscode.window.showWarningMessage(`${msg}`, PromptText.FULL_STACK_PROMPT_TEXT);
108+
const selection = await vscode.window.showWarningMessage(`${msg}`, PromptText.FULL_STACK_PROMPT_TEXT as string, PromptText.IGNORE_FILE);
109109
if (selection === PromptText.FULL_STACK_PROMPT_TEXT) {
110110
record(context, TelemetryActions.vulnerabilityReportPopupOpened, { manifest: fileName, fileName: fileName });
111111
vscode.commands.executeCommand(commands.STACK_ANALYSIS_COMMAND, filePath.fsPath);
112+
} else if (selection === PromptText.IGNORE_FILE) {
113+
outputChannelDep.info(`Added "${filePath.fsPath}" to workspace exclude list`);
114+
await globalConfig.addFileToExcludeList(filePath.fsPath);
112115
} else {
113116
record(context, TelemetryActions.vulnerabilityReportPopupIgnored, { manifest: fileName, fileName: fileName });
114117
}
@@ -123,12 +126,16 @@ export async function activate(context: vscode.ExtensionContext) {
123126
}
124127
});
125128

126-
notifications.on('caError', (errorData: CANotificationData) => {
129+
notifications.on('caError', async (errorData: CANotificationData) => {
127130
const notification = new CANotification(errorData);
128131
caStatusBarProvider.setError();
129132

130133
// Since CA is an automated feature, only warning message will be shown on failure
131-
vscode.window.showWarningMessage(`RHDA error while analyzing ${errorData.uri.fsPath}: ${notification.errorMsg()}`);
134+
const selection = await vscode.window.showWarningMessage(`RHDA error while analyzing ${errorData.uri.fsPath}: ${notification.errorMsg()}`, PromptText.IGNORE_FILE);
135+
if (selection === PromptText.IGNORE_FILE) {
136+
outputChannelDep.info(`Added "${errorData.uri.fsPath}" to workspace exclude list`);
137+
await globalConfig.addFileToExcludeList(errorData.uri.fsPath);
138+
}
132139

133140
// Record telemetry event
134141
record(context, TelemetryActions.componentAnalysisFailed, { manifest: path.basename(notification.origin().fsPath), fileName: path.basename(notification.origin().fsPath), error: notification.errorMsg() });
@@ -151,6 +158,7 @@ export async function activate(context: vscode.ExtensionContext) {
151158

152159
vscode.workspace.onDidChangeConfiguration(() => {
153160
globalConfig.loadData();
161+
outputChannelDep.debug(`configuration updated`);
154162
});
155163
}
156164

@@ -213,8 +221,11 @@ function showRHRepositoryRecommendationNotification() {
213221
* @param context - The extension context.
214222
*/
215223
function registerStackAnalysisCommands(context: vscode.ExtensionContext) {
216-
217-
const invokeFullStackReport = async (filePath: string) => {
224+
const recordAndInvoke = async (origin: string, uri: vscode.Uri) => {
225+
// TODO: vscode.window.activeTextEditor may be null
226+
const fileUri = uri || vscode.window.activeTextEditor!.document.uri;
227+
const filePath = fileUri.fsPath;
228+
record(context, origin, { manifest: path.basename(filePath), fileName: path.basename(filePath) });
218229
const fileName = path.basename(filePath);
219230
try {
220231
await generateRHDAReport(context, filePath, outputChannelDep);
@@ -227,14 +238,6 @@ function registerStackAnalysisCommands(context: vscode.ExtensionContext) {
227238
}
228239
};
229240

230-
const recordAndInvoke = (origin: string, uri: vscode.Uri) => {
231-
// TODO: vscode.window.activeTextEditor may be null
232-
const fileUri = uri || vscode.window.activeTextEditor!.document.uri;
233-
const filePath = fileUri.fsPath;
234-
record(context, origin, { manifest: path.basename(filePath), fileName: path.basename(filePath) });
235-
invokeFullStackReport(filePath);
236-
};
237-
238241
const registerCommand = (cmd: string, action: TelemetryActions) => {
239242
return vscode.commands.registerCommand(cmd, recordAndInvoke.bind(null, action));
240243
};

0 commit comments

Comments
 (0)