Github 状态示例

pau*_*aul 6 git github github-api jenkins

我正在尝试使用 github statuses,但文档不够清楚

假设我的回购项目是https://github.com/politrons/proyectV

他们在文档中声称该帖子应该是

POST /repos/:owner/:repo/statuses/:sha
Run Code Online (Sandbox Code Playgroud)

带着身体

{
  "state": "success",
  "target_url": "https://example.com/build/status",
  "description": "The build succeeded!",
  "context": "continuous-integration/jenkins"
}
Run Code Online (Sandbox Code Playgroud)

所以就我而言,我正在尝试

发布https://github.com/repos/politrons/proyectV/statuses/1

与身体

{
      "state": "success",
      "target_url": "https://example.com/build/status",
      "description": "The build succeeded!",
      "context": "continuous-integration/jenkins"
    }
Run Code Online (Sandbox Code Playgroud)

但是github返回404。

知道我做错了什么吗?一些关于这个的卷曲例子会很棒!!

编辑:

我在分支 Test-status 上创建了一个拉取请求,当我尝试时

   curl -v -X GET "https://api.github.com/repos/politrons/proyectV/pulls/1"
Run Code Online (Sandbox Code Playgroud)

我收到了包含大量信息的 json。然后我获取标题的 sha 信息并发送此 POST 命令

curl --request POST --data '{"state": "success", "description": "It works!", "target_url": "http://localhost"}' https://api.github.com/repos/politrons/projectV/statuses/5f4927adcfdc238ba8f46442b737d8ab912cc6ee
Run Code Online (Sandbox Code Playgroud)

但后来我收到

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
} 
Run Code Online (Sandbox Code Playgroud)

kfb*_*kfb 5

“1”不太可能是您存储库中的提交 SHA——请注意,状态是在commits上设置的,不是在 pull request 上设置的,所以如果您想在 pull request 上设置状态,您实际上希望在头提交上设置它那个拉取请求。

使用 API 来获取您的拉取请求(假设它是拉取请求“1”):

GET /repos/politrons/proyectV/pulls/1
Run Code Online (Sandbox Code Playgroud)

curl

curl -X GET https://api.github.com/repos/politrons/proyectV/pulls/1
Run Code Online (Sandbox Code Playgroud)

允许我们获得头部 SHA:

"head": {
    "label": "new-topic",
    "ref": "new-topic",
    "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
    ...
}
Run Code Online (Sandbox Code Playgroud)

这是您实际设置的状态:

POST /repos/politrons/proyectV/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e
Run Code Online (Sandbox Code Playgroud)

curl

curl -X POST -H 'Content-Type: application/json' --data '{"state": "success", ...}' https://<token>:x-oauth-basic@api.github.com/repos/politrons/proyectV/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e
Run Code Online (Sandbox Code Playgroud)