Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: send fix applied analytics #543

Merged
merged 7 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading