Skip to content

Conversation

@aitchiss
Copy link
Contributor

@aitchiss aitchiss commented Apr 17, 2025

🎉 Thanks for submitting a pull request! 🎉

Summary

Fixes https://linear.app/netlify/issue/WRFL-2391/persist-secret-scanning-output-on-deploy

Send results of secret scan to API on completion.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures
    we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or
    something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures
    your code follows our style guide and passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@aitchiss aitchiss force-pushed the suzanne/wrfl-2391-persist-secret-scanning-output-on-deploy branch from 49fdc90 to c6ba087 Compare April 17, 2025 10:35
@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@aitchiss aitchiss force-pushed the suzanne/wrfl-2391-persist-secret-scanning-output-on-deploy branch from c6ba087 to cc6d820 Compare April 17, 2025 10:46
@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@aitchiss aitchiss force-pushed the suzanne/wrfl-2391-persist-secret-scanning-output-on-deploy branch from cc6d820 to 9ea5e26 Compare April 17, 2025 10:48
@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@aitchiss aitchiss marked this pull request as ready for review April 17, 2025 11:08
@aitchiss aitchiss requested a review from a team as a code owner April 17, 2025 11:08
t.truthy(request.body.secrets_scan.secretsScanMatches)
})

test('secrets scan does not send report to API if deploy ID is string 0', async (t) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is the deploy id '0'?
Could we instead say "secrets scan does not send report to API when ....(situation that causes deploy id to be 0)"

t.true(requests.length === 0)
})

test('secrets scan does not send report to API if deploy ID is undefined', async (t) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same note as above here, when is the deploy id not set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually shouldn't happen, as far as I can tell (we have tests that indicate it should always be set to the default of '0' at least) so I'll remove this spec

deployId: string
}) {
try {
// @ts-expect-error API type is not defined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we aren't adding in a new @ts-expect-error unless we absolutely need to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll see what I can do. It doesn't look like NetlifyAPI contains the type definitions for the dynamically created functions like createPluginRun or this updateDeployValidations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the correct type for the API methods but unfortunately the updateDeployValidations isn't included. Inspecting the DynamicMethods it seems like createPluginRun which is also used in the codebase also isn't included in the types. Both of these are private/internal-only methods which I am assuming we don't want to bundle into the type definitions, which I think should be why they don't appear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we want to bundle them into the type definitions? I'm not saying we do want to, I just want to understand

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd need to dig into it more but I'm assuming it's because it's a public package and we don't actively want external folks using those methods. Same as we don't publish the internal methods in https://open-api.netlify.com/

@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@aitchiss
Copy link
Contributor Author

@pieh @mrstork I think this is ready for re-review now - thank you 🙏

@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

try {
// @ts-expect-error Property 'updateDeployValidations' does not exist on type 'DynamicMethods'. This is a private/internal-only method and isn't generated in the type definitions.
await api.updateDeployValidations({ deploy_id: deployId, body: { secrets_scan: secretScanResult } })
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we are catching specific named errors here, but it's possible we don't know at this time what could go wrong with this call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a malformed payload is what springs to mind, but it's still behind a feature flag and being iterated on, so I'd suggest we monitor initially and improve as we go

},
)

if (deployId && deployId !== '0') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the deployId cannot be unset, is it still necessary to check the value in this clause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I put it here out of an abundance of caution, but it does look like we always have either a deploy_id or the default one:

deployId: combinedEnv.DEPLOY_ID || DEFAULT_DEPLOY_ID,

@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@aitchiss aitchiss enabled auto-merge (squash) April 23, 2025 08:56
@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@aitchiss aitchiss merged commit 5505efb into main Apr 23, 2025
32 of 33 checks passed
@aitchiss aitchiss deleted the suzanne/wrfl-2391-persist-secret-scanning-output-on-deploy branch April 23, 2025 09:28
This was referenced Sep 2, 2025
This was referenced Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment