-
Notifications
You must be signed in to change notification settings - Fork 31
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: add advisor preview #127
Conversation
src/snyk/advisor/AdvisorTypes.ts
Outdated
@@ -0,0 +1,13 @@ | |||
export type AdvisorScoreLabel = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Names of the files should follow camel casing - see other files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did see other files before. For example: https://github.com/snyk/vscode-extension/blob/feat/advisor_score/src/snyk/common/commands/types.ts#L10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean files, not types :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, okay.
@@ -0,0 +1,75 @@ | |||
import * as vscode from 'vscode'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rely on vscode abstractions instead, for testing purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please eleborate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you write unit tests, "vscode" module cannot be resolved since tests run not within VS Code. To overcome this, we invert our dependency on vscode module through dependency inversion mechanisms. You can see inversions in src/snyk/common/vscode
folder.
src/snyk/common/vscode/types.ts
Outdated
@@ -25,3 +25,28 @@ export type DecorationOptions = vscode.DecorationOptions; | |||
export type ThemeColor = vscode.ThemeColor; | |||
export type ThemableDecorationInstanceRenderOptions = vscode.ThemableDecorationInstanceRenderOptions; | |||
export type CodeActionProviderMetadata = vscode.CodeActionProviderMetadata; | |||
export enum Language { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file contains mappings between local types and vscode API ones.
The following types are unrelated to vscode
, thus shouldn't be part of /vscode/types.ts.
hoverMessageMarkdown.appendMarkdown(`| ${label}: | | | ${score?.labels[label]} |`); | ||
hoverMessageMarkdown.appendMarkdown('\n'); | ||
}); | ||
hoverMessageMarkdown.appendMarkdown(`[More Details](http://snyk.io/advisor/npm-package/${score.name})`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make use of existing configuration variables instead of hardcoding the link here? E.g. defaultAuthHost from configuration.ts
if (supportedLanguage) { | ||
const modules = getModules(fileName, document.getText(), supportedLanguage).filter(isValidModuleName); | ||
const promises = modules | ||
.map(module => this.vulnerabilityCountProvider.getVulnerabilityCount(module, supportedLanguage)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this map? Vulnerability Count doesn't relate to advisor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we only show advisor score for packages that has vulnerabilities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the case in IntelliJ Advisor integration as well? I didn't see the feature plan and tbh this wouldn't be my expectation 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the requirements that I got from Oren - @snyk/advisor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please verify if we're aligned on that requirement with IntelliJ plugin.
} | ||
|
||
const result = new CliError(err, ''); | ||
console.error('Failed to get scores', result.error.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errors should be reported via Logger class. See logger injection in other classes.
src/snyk/common/api/apiСlient.ts
Outdated
post<T = unknown, R = AxiosResponse<T>>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<R> { | ||
this.http.interceptors.request.use(req => { | ||
if (req.method === 'post') { | ||
req.baseURL = this.configuration.baseApiUrl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class should work with the same base Url for API. If there's a need to work with different API url, you either create another class or introduce type parameter here indicating what type of Snyk Api we want to POST to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to create a new class just for a single method? I think it's a bit overkill and duplication of classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is important to follow single responsibility principle. Use another suggested option then, if you don't like another class. But first determine what's the difference between these two APIs and only then make a decision please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand and I agree on that, it looks like a duplication now that I look at it. But I think this is not the case because apiClient is common and generic.
Another solution can be that we'll use a helper function/class that will return the right url according to the request method (in this case). What do you think about it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can keep single responsibility principle with a new function/class, then sure :) Sometimes it's better to duplicate rather than making a thing less comprehensible when glancing at the code.
@@ -0,0 +1,44 @@ | |||
export default [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't duplicate the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it to common, how is that a duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
snyk/vscode-extension/src/snyk/snykOss/constants/nativeModules.ts
Issues found from quick glance:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's quite many comments I've left but it's much better after the last iteration 👍. Let's have a call when you will go through them. There are few bits that I still want to discuss.
Something you shouldn't also forget is testing the implemented bits 😉
src/snyk/base/modules/snykLib.ts
Outdated
@@ -141,7 +142,8 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib { | |||
|
|||
try { | |||
const oldResult = this.ossService.getResult(); | |||
const result = await this.ossService.test(manual, reportTriggeredEvent); | |||
const result: OssResult = await this.ossService.test(manual, reportTriggeredEvent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert file to the original? There's no need to write type for the variable, let's have changes clean for git blame
to work fine when needed.
src/snyk/snykOss/services/vulnerabilityCount/parsers/packageJsonParser.ts
Show resolved
Hide resolved
As discussed offline, I'll be taking this PR over and merging it afterwards. |
e955749
to
1b06383
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bless me for self approving it.
Thank you for your work on it @sangress 👏 |
Thanks @michelkaporin for mentioning. Good luck with future features :) |
Add advisor score to vscode extension
Score will show for packages with vulnerabilities, as shown in the following image:
To see this feature in action, use a package.json file with a package that known to have a score lower then 70, then hover with your mouse over the
Advisor Score
text with the mouse to see the advisor score details.Example dependencies: