我可以通过 API 检索 GitHub PR 审核状态吗?
Can I retrieve a GitHub PR review status via the API?
我不想检索评论的 "state"(例如 'open'、'closed'),而是检索状态(例如 'approved')。但是,我看不到通过 API 执行此操作的方法。无论状态如何,它总是 return 是一个空的 JSON 数组。
例如,这个 _should_ return 状态 "approved",但它 return 什么都没有:
https://github.mydomain.com/api/v3/repos/myOrg/myRepo/statuses/8675309
结果:
[
]
API不支持这个操作('review status')吗?
您实际上应该尝试不同的 API。根据GitHub的Status API documentation,
The status API allows external services to mark commits with an error
, failure
, pending
, or success
state, which is then reflected in pull requests involving those commits.
因此 Status API 提供每个提交的状态作为 PR 的一部分,例如,如果构建失败或成功作为提交推送的一部分.以下请求只会 return 状态作为参考的一部分。
GET /repos/:owner/:repo/commits/:ref/statuses
您需要的是 评论 API,您可以在其中获取 PR 的评论,其中包含您的 state
字段期待。 API 是
GET /repos/:owner/:repo/pulls/:number/reviews
样本响应是
[
{
"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"
}
}
}
]
请注意,响应中的 state 字段具有您要查找的 APPROVED 状态。
评论 GitHub documentation 中的更多信息 API。
我不想检索评论的 "state"(例如 'open'、'closed'),而是检索状态(例如 'approved')。但是,我看不到通过 API 执行此操作的方法。无论状态如何,它总是 return 是一个空的 JSON 数组。
例如,这个 _should_ return 状态 "approved",但它 return 什么都没有:
https://github.mydomain.com/api/v3/repos/myOrg/myRepo/statuses/8675309
结果:
[
]
API不支持这个操作('review status')吗?
您实际上应该尝试不同的 API。根据GitHub的Status API documentation,
The status API allows external services to mark commits with an
error
,failure
,pending
, orsuccess
state, which is then reflected in pull requests involving those commits.
因此 Status API 提供每个提交的状态作为 PR 的一部分,例如,如果构建失败或成功作为提交推送的一部分.以下请求只会 return 状态作为参考的一部分。
GET /repos/:owner/:repo/commits/:ref/statuses
您需要的是 评论 API,您可以在其中获取 PR 的评论,其中包含您的 state
字段期待。 API 是
GET /repos/:owner/:repo/pulls/:number/reviews
样本响应是
[
{
"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"
}
}
}
]
请注意,响应中的 state 字段具有您要查找的 APPROVED 状态。
评论 GitHub documentation 中的更多信息 API。