github-community-projects / github-community-projects/safe-settings
check_suite.rerequested handler fails with "head_sha wasn't supplied" when re-running dry-run check via GitHub UI
- Dominant language
- JavaScript
- Stars
- 921
- Forks
- 226
- Avg merge
- 18h 3m
- Merged PRs (30d)
- 14
Description
## Problem Description
### What is actually happening
When re-running the "Safe-setting validator" check via the GitHub UI (clicking **Re-run** on the check suite/check run for a dry-run PR check), GitHub Actions fails with:
```
Invalid request.
"head_sha" wasn't supplied.
```
This error was observed in our application logs — the GitHub UI itself gives no useful error information.
The `check_suite.rerequested` handler in `index.js` calls `createCheckRun(context)` with no arguments:
```js
robot.on(['check_suite.rerequested'], async context => {
robot.log.debug('Check suite was rerequested!')
return createCheckRun(context)
})
```
(Note: this handler is also registered twice, back-to-back, with identical bodies.)
But `createCheckRun` requires `head_sha` to build the `checks.create` payload:
```js
async function createCheckRun (context, pull_request, head_sha, head_branch) {
const { payload } = context
const res = await context.octokit.rest.checks.create({
owner: payload.repository.owner.login,
repo: payload.repository.name,
name: 'Safe-setting validator',
head_sha
})
...
}
```
Since no `head_sha` is passed in on rerequest, `head_sha` is `undefined`, and the `checks.create` REST call is sent without it — which the Checks API requires — producing the error above.
By contrast, every other call site (`check_suite.requested`, `pull_request.opened`, `pull_request.reopened`) correctly pulls `head_sha` out of the payload (e.g. `context.payload.check_suite.head_sha` or `payload.pull_request.head.sha`) before calling `createCheckRun`.
### What is expected behavior
Re-running the dry-run check via the GitHub UI should re-trigger the "Safe-setting validator" check run successfully, the same way the initial check suite creation does.
The `check_suite.rerequested` handler should extract `head_sha`, `head_branch`, and `pull_request` from `context.payload.check_suite` (same as the existing `check_suite.requested` handler) and pass them into `createCheckRun`. The duplicate handler registration should also be removed.
### Error output, if available
```
Invalid request.
"head_sha" wasn't supplied.
```
## Context
### Are you using the hosted instance of probot/settings or running your own?
Running our own instance.
### If running your own instance, are you using it with github.com or GitHub Enterprise?
github.com
#### Version of probot/settings
2.1.20-rc.3 (main-enterprise @ 4578aea)
#### Version of GitHub Enterprise
N/A (github.com)
Contributor guide
Research direction
Start in index.js by comparing the check_suite.rerequested handler with the existing check_suite.requested handler and the createCheckRun signature. Verify that the rerequested payload supplies head_sha, head_branch, and pull_request, and remove the duplicate registration. Done means re-running the Safe-setting validator through the GitHub UI successfully creates the check run without the missing head_sha error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100