-
Notifications
You must be signed in to change notification settings - Fork 567
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 --json-file-output option for snyk test #1107
Conversation
449d5cc
to
aea2b8c
Compare
8474f14
to
f5f4829
Compare
f5f4829
to
d50e296
Compare
@maxjeffos can you also make sure the output of --print-deps is in that file too if the option is specified. I'm using the depgraph for something and that'd be great to have in this function. Thanks! |
src/cli/index.ts
Outdated
try { | ||
writeFileSync(jsonOutputFile, stringifiedJson); | ||
} catch (err) { | ||
console.error(err); |
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.
potentially 'ugly' for user
for example: snyk test --json-file-output
(no path provided) produces:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received type boolean (true)
at Object.openSync (fs.js:450:10)
at Object.writeFileSync (fs.js:1279:35)
at saveJsonResultsToFile (/Users/phill/code/snyk/src/cli/index.ts:156:5)
at handleError (/Users/phill/code/snyk/src/cli/index.ts:111:5)
at main (/Users/phill/code/snyk/src/cli/index.ts:273:28)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: 'ERR_INVALID_ARG_TYPE'
}
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.
maybe some validation of argument passed?
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 is resolved now and I added some tests for it. Thanks.
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 update help text 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.
should we support a path to json?
for example: snyk test ---json-file-output=path/to/ouput.json
at the moment this causes ENOENT error
If we don't want to support this, we should validate input and display friendly message explaining arg should be filename only (no path).
d50e296
to
3d7afdc
Compare
3d7afdc
to
8a84ae2
Compare
src/cli/index.ts
Outdated
} | ||
|
||
if (jsonOutputFile.constructor.name !== String.name) { | ||
console.error("jsonOutputFile is invalid type"); |
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.
"--json-output-file should be a filename path"
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.
👍
51bce38
to
c5c52ad
Compare
🎉 This PR is included in version 1.332.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What does this PR do?
This allows a user to directly save JSON format output to a file as specified by the --json-file-output= parameter, regardless of whether they are using the human-readable or json output. The primary use-case of this is to enable users (and Snyk CI plugins) to simultaneously get the human readable output while saving a JSON format output to a file for other purposes (for example, generating a report).
Where should the reviewer start?
Please take a look at the code and advise as to testing best-practices. I will then include appropriate tests for this PR.
How should this be manually tested?
Say you want to save the JSON output to a file called "snyk-output.json" in the current directory. You could then run snyk test --json-file-output=snyk-output.json which should do a normal snyk test and generate the human-readable output to stdout but at the same time save the JSON format output to snyk-output.json.
Any background context you want to provide?
We need this for #1027 and snyk/snyk-azure-pipelines-task#30 as well as for another CI plugin we're currently working on.
This PR replaces a #1059 which I will close once this gets traction
What are the relevant tickets?
Additional questions