Home > Software engineering >  How to create a commit status in GitHub?
How to create a commit status in GitHub?

Time:08-29

I want to set a commit status in my personal repo. I'm following the directives in this url enter image description here

As you can see, there are no status in this commit. Then, I try to set a status in the commit with the following request, and I get the response below.

  curl -X POST -H "Accept: application/vnd.github json" -H "Authorization: token <TOKEN>" https://api.github.com/repos/andresdiegolanda/hello-world/578138334ad1f8dc874886ed2afb99e3265565be -d '{"state":"success","target_url":"https://example.com/build/status","description":"The build succeeded!","context":"continuous-integration/jenkins"}'

enter image description here

My question is: What am I doing wrong, that doesn't allow me to set the status in the request?

CodePudding user response:

The the Create commit status API

curl \
  -X POST \
  -H "Accept: application/vnd.github json" \ 
  -H "Authorization: token <TOKEN>" \
  https://api.github.com/repos/OWNER/REPO/statuses/SHA \
  -d '{"state":"success","target_url":"https://example.com/build/status","description":"The build succeeded!","context":"continuous-integration/jenkins"}'

In your example:

https://api.github.com/repos/andresdiegolanda/hello-world/578138334ad1f8dc874886ed2afb99e3265565be

I did not see the /statuses/ part.

The other option is to use the GitHub CLI:

# GitHub CLI api
# https://cli.github.com/manual/gh_api

gh api \
  --method POST \
  -H "Accept: application/vnd.github json" \
  /repos/OWNER/REPO/statuses/SHA \
  -f state='success'
 -f target_url='https://example.com/build/status'
 -f description='The build succeeded!'
 -f context='continuous-integration/jenkins'
  • Related