I´m trying to use github statuses, but the documentation is not clear enough
Let´s say that my repo project is https://github.com/politrons/proyectV
They claim in the documentation that the post it should be
POST /repos/:owner/:repo/statuses/:sha
With a body
{
"state": "success",
"target_url": "https://example.com/build/status",
"description": "The build succeeded!",
"context": "continuous-integration/jenkins"
}
So in my case I´m trying
POST https://github.com/repos/politrons/proyectV/statuses/1
With Body
{
"state": "success",
"target_url": "https://example.com/build/status",
"description": "The build succeeded!",
"context": "continuous-integration/jenkins"
}
But github return 404.
Any idea what I´m doing wrong? Some curl examples about this it would be great!!
EDITED:
I create a pull request on branch Test-status and when I try
curl -v -X GET "https://api.github.com/repos/politrons/proyectV/pulls/1"
I recieve the json with a lot of information. Then I´m getting the sha information of the header and send this POST command
curl --request POST --data '{"state": "success", "description": "It works!", "target_url": "http://localhost"}' https://api.github.com/repos/politrons/projectV/statuses/5f4927adcfdc238ba8f46442b737d8ab912cc6ee
But then I receive
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
"1" is unlikely to be a commit SHA in your repository—note that statuses are set on commits, not on pull requests, so should you want to set the status on a pull request, you actually want to set it on the head commit of that pull request.
Using the API to get your pull request (assuming it's pull request "1"):
GET /repos/politrons/proyectV/pulls/1
In curl
:
curl -X GET https://api.github.com/repos/politrons/proyectV/pulls/1
Allows us to get the head SHA:
"head": {
"label": "new-topic",
"ref": "new-topic",
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
...
}
Which is what you actually set the status on:
POST /repos/politrons/proyectV/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e
In curl
:
curl -X POST -H 'Content-Type: application/json' --data '{"state": "success", ...}' https://<token>:[email protected]/repos/politrons/proyectV/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With