Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github statuses examples

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"
} 
like image 735
paul Avatar asked Oct 25 '16 10:10

paul


1 Answers

"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
like image 192
kfb Avatar answered Oct 06 '22 14:10

kfb