我可以通过 API 检索 GitHub PR 审核状态吗?

Mik*_*ard 7 github github-api

我不想检索评论的“状态”(例如“开放”、“关闭”),而是检索状态(例如“已批准”)。但是我看不到通过 API 执行此操作的方法。无论状态如何,它始终返回一个空的 JSON 数组。

例如,此_应该_返回“已批准”状态,但它什么也不返回:

https://github.mydomain.com/api/v3/repos/myOrg/myRepo/statuses/8675309

结果是:

[

]

API 不支持此操作(“查看状态”)吗?

Mad*_*hat 5

您实际上应该尝试不同的 API。根据GitHub的Status API文档,

状态 API 允许外部服务用errorfailurependingsuccess状态标记提交,然后反映在涉及这些提交的拉取请求中。

因此,状态 API提供每个提交的状态作为 PR 的一部分,例如,作为提交推送的一部分构建失败或成功。以下请求只会返回状态作为参考的一部分。

GET /repos/:owner/:repo/commits/:ref/statuses
Run Code Online (Sandbox Code Playgroud)

您需要的是Reviews API,您可以在其中获取 PR 的评论,其中包含state您期望的字段。API 是

GET /repos/:owner/:repo/pulls/:number/reviews
Run Code Online (Sandbox Code Playgroud)

示例响应是

[
  {
    "id": 80,
    "node_id": "MDE3OlB1bGxSZXF1ZXN0UmV2aWV3ODA=",
    "user": {
      "login": "octocat",
      "id": 1,
      "node_id": "MDQ6VXNlcjE=",
      "avatar_url": "https://github.com/images/error/octocat_happy.gif",
      "gravatar_id": "",
      "url": "https://api.github.com/users/octocat",
      "html_url": "https://github.com/octocat",
      "followers_url": "https://api.github.com/users/octocat/followers",
      "following_url": "https://api.github.com/users/octocat/following{/other_user}",
      "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
      "organizations_url": "https://api.github.com/users/octocat/orgs",
      "repos_url": "https://api.github.com/users/octocat/repos",
      "events_url": "https://api.github.com/users/octocat/events{/privacy}",
      "received_events_url": "https://api.github.com/users/octocat/received_events",
      "type": "User",
      "site_admin": false
    },
    "body": "Here is the body for the review.",
    "commit_id": "ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091",
    "state": "APPROVED",
    "html_url": "https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80",
    "pull_request_url": "https://api.github.com/repos/octocat/Hello-World/pulls/12",
    "_links": {
      "html": {
        "href": "https://github.com/octocat/Hello-World/pull/12#pullrequestreview-80"
      },
      "pull_request": {
        "href": "https://api.github.com/repos/octocat/Hello-World/pulls/12"
      }
    }
  }
]
Run Code Online (Sandbox Code Playgroud)

请注意,响应中的状态字段具有您正在查找的“已批准”状态。

有关更多信息,请参阅评论 API 的GitHub 文档

  • 好的,太好了 - 感谢您提供的信息!看起来这样就可以了! (2认同)