Github 状态示例

标签 git github jenkins github-api

我正在尝试使用 github 状态,但是 documentation不够清楚

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

他们在文档中声称它应该是这样的帖子

POST /repos/:owner/:repo/statuses/:sha

有 body

{
  "state": "success",
  "target_url": "https://example.com/build/status",
  "description": "The build succeeded!",
  "context": "continuous-integration/jenkins"
}

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

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

有 body

{
      "state": "success",
      "target_url": "https://example.com/build/status",
      "description": "The build succeeded!",
      "context": "continuous-integration/jenkins"
    }

但是 github 返回 404。

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

编辑:

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

   curl -v -X GET "https://api.github.com/repos/politrons/proyectV/pulls/1"

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

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

然后我收到了

{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
} 

最佳答案

“1”不太可能是您存储库中的提交 SHA——请注意状态是在提交上设置的,而不是在 pull 请求上设置的,所以如果您想在 pull 请求上设置状态,您实际上想将其设置在该 pull 请求的头部提交上。

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

GET /repos/politrons/proyectV/pulls/1

curl 中:

curl -X GET https://api.github.com/repos/politrons/proyectV/pulls/1

允许我们获取头部 SHA:

"head": {
    "label": "new-topic",
    "ref": "new-topic",
    "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
    ...
}

您实际将状态设置为:

POST /repos/politrons/proyectV/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e

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

关于Github 状态示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40237009/

相关文章:

git - 将某些命令分配给用户

linux - 尝试删除 Git 修订历史记录中涉及长文件名的提交消息

git - 如何将 Git 版本控制 (Bitbucket) 添加到现有源代码文件夹?

git - 撤消 git pull --rebase?

github - 在 GitHub 中针对拉取请求显示 Jenkins 管道状态

java - 使用 aspose.diagram java 读取组/容器内的形状

git - 在 git 中创建别名

jenkins - Gradle发布插件无构建任务

ios - 使用 Crashlytics Fabric 的崩溃报告在更新后不起作用

macos - 如何在 Mac 上完全卸载 Jenkins