fix: raise error when the previous sha cannot be determined and since_last_remote_commit is true (#1554)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack
2023-09-08 19:18:37 -06:00
committed by GitHub
parent 4a0a3c4aa5
commit 523e8b6f11
3 changed files with 42 additions and 33 deletions

View File

@@ -419,30 +419,36 @@ export const getSHAForPullRequestEvent = async (
if (
!previousSha ||
(previousSha &&
(await verifyCommitSha({sha: previousSha, cwd: workingDirectory})) !==
0)
(await verifyCommitSha({
sha: previousSha,
cwd: workingDirectory,
showAsErrorMessage: false
})) !== 0)
) {
if (
github.context.payload.action &&
github.context.payload.action === 'synchronize'
) {
throw Error(
'Unable to locate the previous commit in the local history. Please ensure to checkout pull request HEAD commit instead of the merge commit. See: https://github.com/actions/checkout/blob/main/README.md#checkout-pull-request-head-commit-instead-of-merge-commit)'
)
} else {
core.info(
`Unable to locate the remote branch head sha for ${github.context.eventName} (${github.context.payload.action}) events. Falling back to the previous commit in the local history.`
)
}
core.info(
`Unable to locate the previous commit in the local history for ${github.context.eventName} (${github.context.payload.action}) event. Falling back to the previous commit in the local history.`
)
previousSha = await getParentSha({
cwd: workingDirectory
})
if (!previousSha) {
core.warning(
'Unable to locate the previous commit in the local history. Falling back to the pull request base sha.'
if (
github.context.payload.action &&
github.context.payload.action === 'synchronize' &&
previousSha &&
(await verifyCommitSha({sha: previousSha, cwd: workingDirectory})) !==
0
) {
throw new Error(
'Unable to locate the previous commit in the local history. Please ensure to checkout pull request HEAD commit instead of the merge commit. See: https://github.com/actions/checkout/blob/main/README.md#checkout-pull-request-head-commit-instead-of-merge-commit'
)
}
if (!previousSha) {
throw new Error(
'Unable to locate the previous commit in the local history. Please ensure to checkout pull request HEAD commit instead of the merge commit. See: https://github.com/actions/checkout/blob/main/README.md#checkout-pull-request-head-commit-instead-of-merge-commit'
)
previousSha = github.context.payload.pull_request?.base?.sha
}
}
} else {