While trying to set the build status of a commit through ssh, I was experiencing some difficulties. I first set the build status successfully, using a GitHub personal access token. Based on this answer, I created the following curl command:
#!/bin/bash
USER="red"
REPO="code"
COMMIT_SHA="6ec8d6ef221c3e317fa20b1f541770b8f46f065c"
MY_TOKEN="somelongpersonaltoken"
curl -H "Authorization: token $MY_TOKEN" --request POST --data '{"state": "failure", "description": "Failed!", "target_url": "https://www.stackoverflow.com"}' https://api.github.com/repos/$USER/$REPO/statuses/$COMMIT_SHA
Which sets the build status similar to the red cross below:
Next, I retrieved the GitHub commit status, using:
GET https://api.github.com/repos/$USER/$REPO/commits/$COMMIT_SHA/statuses
Which outputs:
[{"url":"https://api.github.com/repos/... ,"state":"failure","description":"Failed!","target_url":"https://www.stackoverflow.com","context":"default","created_at":"2021-12-19T10:10:20Z","updated_at":"2021-12-19T10:10:20Z"...,"site_admin":false}}]
Which is as expected.
Then for the second part, I tried to omit using a GitHub personal access token, and use my ssh credentials to set the commit build status. However, this answer seems to suggest that that is currently not possible. Hence, I would like to ask:
How can I set a GitHub commit build status using ssh credentials in Bash?