github / dependency-submission-toolkit

A TypeScript library for creating dependency snapshots.
MIT License
46 stars 10 forks source link

Get the right SHA for the snapshot depending on the event type #42

Closed juxtin closed 1 year ago

juxtin commented 1 year ago

As noted in the Actions docs, context.sha can represent different things in different event types. In a pull_request event, it happens not to be the sha of the head commit for some reason. Instead, in those cases you're meant to get the head sha from the pull_request payload.

This PR introduces a helper function, shaFromContext, that matches on the event type and gets the correct sha for the snapshot. I've also taken the liberty of doing a few quick test refactors.

For prior art, see: