我不想检索评论的“状态”(例如,“打开”,“关闭”),而是检索状态(例如,“已批准”)。我看不到通过API执行此操作的方法。无论状态如何,它总是返回一个空的JSON数组。
例如,此 _should _ 返回状态为“已批准”,但不返回任何内容:
https://github.mydomain.com/api/v3/repos/myOrg/myRepo/statuses/8675309
导致:
[
]
API不支持此操作(“查看状态”)吗?
答案 0 :(得分:1)
您实际上应该尝试使用其他API。根据GitHub的Status API documentation,
状态API允许外部服务以
error
,failure
,pending
或success
状态标记提交,然后在涉及那些提交的请求请求中反映出来
因此,状态API 作为PR的一部分提供了每个提交的状态,例如,如果构建失败或作为提交推送的一部分而成功。以下请求将仅返回状态作为参考的一部分。
GET /repos/:owner/:repo/commits/:ref/statuses
您需要的是 Reviews API ,您可以在其中获取PR的评论,该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"
}
}
}
]
请注意,响应中的状态字段具有您要查找的已批准状态。
有关评论API的GitHub documentation中的详细信息。