Andres
Andres

Reputation: 10717

How to create a commit status in GitHub?

I want to set a commit status in my personal repo. I'm following the directives in this url https://docs.github.com/en/rest/commits/statuses When I hit the GitHub REST API with the following request, I get the response below:

 curl -H "Accept: application/vnd.github+json" -H "Authorization: token <TOKEN>" https://api.github.com/repos/andresdiegolanda/hello-world/commits/7f7e31e1956bb76e29fb94d1345954d5cb407c96

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?

Upvotes: 1

Views: 2405

Answers (1)

VonC
VonC

Reputation: 1323953

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'

Upvotes: 2

Related Questions