fix: correctly override user input param of sha#123
fix: correctly override user input param of sha#123jantiebot wants to merge 2 commits intoadvanced-security:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes snapshot SHA overriding so that user-provided snapshotConfig.sha properly takes precedence when generating dependency snapshots (as used by the action/CLI), and updates the compiled dist bundle accordingly.
Changes:
- Use
snapshotConfig.sha(not the newly-createdsnapshot.sha) when applying a user-specified SHA override. - Regenerate
dist/index.js, reflecting the SHA override fix plus bundled dependency code updates.
Reviewed changes
Copilot reviewed 1 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/snapshot-generator.ts | Corrects SHA override source to use user-provided snapshotConfig.sha. |
| dist/index.js | Rebuilt bundle reflecting the SHA override change plus additional bundled dependency/version/code updates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const specifiedSha = getNonEmptyValue(snapshotConfig?.sha); | ||
| if (specifiedSha) { | ||
| snapshot.sha = specifiedSha; | ||
| } |
There was a problem hiding this comment.
getNonEmptyValue expects a string and calls .trim(), but SnapshotConfig.sha is typed as any. Now that snapshotConfig.sha is being passed in, a non-string value would throw at runtime. Consider tightening SnapshotConfig (sha/ref as string | undefined) and/or making getNonEmptyValue guard on typeof str === 'string' before trimming.
| const specifiedSha = getNonEmptyValue(snapshotConfig?.sha); | ||
| if (specifiedSha) { | ||
| snapshot.sha = specifiedSha; | ||
| } |
There was a problem hiding this comment.
There are existing tests for generateSnapshot, but this change to override snapshot.sha from snapshotConfig.sha isn’t covered. Add a test that passes a snapshotConfig with sha set and asserts the returned snapshot has that sha (and ideally that whitespace-only input is ignored).
For me this fixes the issue where the
snapshot-shainput parameter was ignored and instead the head SHA from thegithub.event.pull_requestcontext was used. Please check if there is a similar issue when using thesnapshot-refparameter. If I recall correctly I couldn't make it work with that input parameter either.In order to submit the dependency graph of the base branch in a PR, I'm calling this action as follows:
Now the
snapshot-shainput parameter is used properly and the dependency graph is available as expected.