Skip to content

Commit

Permalink
feat: send fix applied analytics (#543)
Browse files Browse the repository at this point in the history
* feat: send fix applied analytics

* fix: move the analytics call to after fix applied

* fix: lint warnings

* chore: update changelog

* fix: add error handler on failing to send analytic for autofix applied
  • Loading branch information
acke authored Oct 15, 2024
1 parent 383c313 commit 192b431
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- New error message in UI when net new scan is done on an invalid repository. Net new scans only work on Git.
- Clear in Memory cache when branch is changed.
- Added Clear Persisted Cache command.
- Add support for ai fix feedback analytic when pressing apply on a fix.

## [2.18.2]
- Update Language Server Protocol version to 15.
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ Code changes require extension reload when run in debug.
## Run tests and debug

- Unit tests

- Run `npm run test:unit` for a single execution, `npm run test:unit:watch` to watch for changes.
- Make sure to re-run the command to pick up new files, if new `**.test.ts` is added.

- Integration tests
- Run `npm run test:integration`.

- Run Lint
- npm `npm run lint`

You can debug tests via VS Code debugger, selecting "Extension Unit Tests" or "Extension Integration Tests" respectively.

## Analytics, experimentation and error reporting
Expand Down
1 change: 1 addition & 0 deletions src/snyk/common/constants/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const SNYK_WORKSPACE_SCAN_COMMAND = 'snyk.workspace.scan';
export const SNYK_TRUST_WORKSPACE_FOLDERS_COMMAND = 'snyk.trustWorkspaceFolders';
export const SNYK_GET_ACTIVE_USER = 'snyk.getActiveUser';
export const SNYK_CODE_FIX_DIFFS_COMMAND = 'snyk.code.fixDiffs';
export const SNYK_CODE_SUBMIT_FIX_FEEDBACK = 'snyk.code.submitFixFeedback';
export const SNYK_FEATURE_FLAG_COMMAND = 'snyk.getFeatureFlagStatus';
export const SNYK_CLEAR_CACHE_COMMAND = 'snyk.clearCache';
export const SNYK_CLEAR_PERSISTED_CACHE_COMMAND = 'snyk.clearPersistedCache';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { marked } from 'marked';
import * as vscode from 'vscode';
import {
SNYK_CODE_FIX_DIFFS_COMMAND,
SNYK_CODE_SUBMIT_FIX_FEEDBACK,
SNYK_IGNORE_ISSUE_COMMAND,
SNYK_OPEN_BROWSER_COMMAND,
SNYK_OPEN_LOCAL_COMMAND,
Expand Down Expand Up @@ -277,7 +278,7 @@ export class CodeSuggestionWebviewProvider
}

case 'applyGitDiff': {
const { patch, filePath } = message.args;
const { patch, filePath, fixId } = message.args;

const fileContent = readFileSync(filePath, 'utf8');
const patchedContent = applyPatch(fileContent, patch);
Expand All @@ -304,6 +305,11 @@ export class CodeSuggestionWebviewProvider
this.highlightAddedCode(filePath, patch);
this.setupCloseOnSave(filePath);

try {
await vscode.commands.executeCommand(SNYK_CODE_SUBMIT_FIX_FEEDBACK, fixId, 'FIX_APPLIED');
} catch (e) {
throw new Error('Error in submit fix feedback');
}
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ declare const acquireVsCodeApi: any;
args: {
patch: string;
filePath: string;
fixId: string;
};
};

Expand Down Expand Up @@ -154,13 +155,13 @@ declare const acquireVsCodeApi: any;
| OpenBrowserMessage
| IgnoreIssueMessage
| GetAutofixDiffsMesssage
| SetAutofixDiffsMessage
| SetAutofixErrorMessage
| ApplyGitDiffMessage
| SetSuggestionMessage
| GetSuggestionMessage
| SetLessonMessage
| GetLessonMessage
| SetAutofixDiffsMessage
| SetAutofixErrorMessage;
| GetLessonMessage;

const vscode = acquireVsCodeApi();

Expand All @@ -187,9 +188,9 @@ declare const acquireVsCodeApi: any;
previousDiffElem: document.getElementById('previous-diff') as HTMLElement,
diffSelectedIndexElem: document.getElementById('diff-counter') as HTMLElement,

generateAIFixButton: document.getElementById('generate-ai-fix') as HTMLElement,
applyFixButton: document.getElementById('apply-fix') as HTMLElement,
retryGenerateFixButton: document.getElementById('retry-generate-fix') as HTMLElement,
generateAIFixButton: document.getElementById('generate-ai-fix') as HTMLElement,

fixAnalysisTabElem: document.getElementById('fix-analysis-tab') as HTMLElement,
fixAnalysisContentElem: document.getElementById('fix-analysis-content') as HTMLElement,
Expand Down Expand Up @@ -296,10 +297,11 @@ declare const acquireVsCodeApi: any;
const diffSuggestion = suggestion.diffs[diffSelectedIndex];
const filePath = suggestion.filePath;
const patch = diffSuggestion.unifiedDiffsPerFile[filePath];
const fixId = suggestion.id;

const message: ApplyGitDiffMessage = {
type: 'applyGitDiff',
args: { filePath, patch },
args: { filePath, patch, fixId },
};
sendMessage(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
args: {
patch: string;
filePath: string;
fixId: string;
};
};

Expand Down Expand Up @@ -239,10 +240,11 @@
const diffSuggestion = suggestion.diffs[diffSelectedIndex];
const filePath = suggestion.filePath;
const patch = diffSuggestion.unifiedDiffsPerFile[filePath];
const fixId = suggestion.id;

const message: ApplyGitDiffMessage = {
type: 'applyGitDiff',
args: { filePath, patch },
args: { filePath, patch, fixId },
};
sendMessage(message);
}
Expand Down
1 change: 1 addition & 0 deletions src/snyk/snykCode/views/suggestion/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type ApplyGitDiffMessage = {
args: {
patch: string;
filePath: string;
fixId: string;
};
};

Expand Down

0 comments on commit 192b431

Please sign in to comment.