phylum-dev / community-extensions

A collection of community extensions for the Phylum CLI
https://www.phylum.io/
GNU General Public License v3.0
1 stars 1 forks source link

Export project data against defined policy #43

Closed louislang closed 5 months ago

louislang commented 5 months ago

This PR updates the exporter to only export issues that have caused a policy violation. The exporter will first attempt to pull the policy from the group level, before falling back to the project level policy. If no policy is defined, the default Phylum policy is used.

matt-phylum commented 5 months ago

Testing this extension locally results in errors. Basically, this same error is repeated for the number of projects to export:

It's probably because the Phylum default policy is returned as plain text instead of a string in a containing JSON document like the project and group policies are.

louislang commented 5 months ago

Testing this extension locally results in errors. Basically, this same error is repeated for the number of projects to export:

There was an issue fetching the project data: SyntaxError: Unexpected token 'p', "package po"... is not valid JSON
    at parse (<anonymous>)
    at packageData (ext:deno_fetch/22_body.js:369:14)
    at consumeBody (ext:deno_fetch/22_body.js:246:12)
    at eventLoopTick (ext:core/01_core.js:178:11)
    at async fetchPolicyRequest (file:///Users/maxrake/.local/share/phylum/extensions/export/policy.ts:12:22)
    at async fetchDefaultPolicy (file:///Users/maxrake/.local/share/phylum/extensions/export/policy.ts:23:12)
    at async fetchPolicy (file:///Users/maxrake/.local/share/phylum/extensions/export/policy.ts:56:30)
    at async fetchProjectData (file:///Users/maxrake/.local/share/phylum/extensions/export/main.ts:21:24)
    at async file:///Users/maxrake/.local/share/phylum/extensions/export/main.ts:110:22
    at async run (https://deno.land/x/p_limit@v1.0.0/mod.ts:30:26)

I'm not sure exactly what the fix is for this.

It might also be nice to update the README for this extension to something like:

This extension will iterate through your projects and export issues that have caused a policy violation.

Seems like you got something back that wasn't a JSON response, as expected. It seems like you got back a raw policy maybe? Going to hold off fixing this as I think doing what @matt-phylum suggested might obviate the need for that entire block of code.