如何使用 API 更新 GitHub 拉取请求审查的评论文本
How to update the comment text of a GitHub Pull Request Review using the API
使用 GitHub 的网络 UI,您可以编辑 PR 评论的评论摘要,例如在这个屏幕截图中(参见带有 "Edit review summary" 工具提示的铅笔图标):
如何使用 GitHub API?
我查看了 documentation 但找不到执行此操作的方法。我在使用 UI 进行更改时监视了在页面上触发的 Web 服务调用,我发现了对 https://api.github.com/repos/SonarSourceIT/pr-decoration/pull/3195/reviews/91117155/update
的调用,因此我尝试使用 curl
:[=19 进行相同的操作=]
$ curl -sL -u janos-ss:$token https://api.github.com/repos/SonarSourceIT/pr-decoration/pull/3195/reviews/91117155/update -X POST -d @comment.json | jq . | tee response.json
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
我对这不起作用并不感到惊讶,因为 URL 看起来不像任何已记录的 API 方法。
请注意,这与编辑评论不同。可以编辑评论 (documented here),但我想编辑 评论摘要,这是另外一回事。
这可以使用 REST API v3 来实现吗?我对 hacky 解决方案或使用 Selenium 或类似解决方案不感兴趣。我正在寻找一个干净的 API 解决方案,或者确认这实际上对于当前的 REST API v3.
是不可能的
更新
正如 GitHub 支持所确认的那样,从今天开始使用 REST API v3 是不可能的。 (我确认接受的答案中的建议有效,我可能会使用它作为解决方法。)
您可以使用 GraphQL API v4 to update pull request review using updatePullRequestReview :
- 通过拉取请求编号查找评论并获取评论 ID 的查询
- 要执行的突变
updatePullRequestReview
您可以在 the GraphQL explorer 中测试以下内容:
query FindReview {
repository(owner: "bertrandmartel", name: "speed-test-lib") {
pullRequest(number: 46) {
reviews(first: 100) {
edges {
node {
id
}
}
}
}
}
}
mutation UpdateReview {
updatePullRequestReview(input: {pullRequestReviewId: "MDE3OlB1bGxSZXF1ZXN0UmV2aWV3OTExNjM5NjI=", body: "some test"}) {
pullRequestReview {
updatedAt
}
}
}
您可以找到有关形成 graphql 调用的其他信息here
以下脚本使用 curl & jq 请求评论列表,提取第一个并更新评论正文:
owner="SonarSourceIT"
name="pr-decoration"
pr=3195
access_token="YOUR_ACCESS_TOKEN"
# find reviews for PR - extract the first review ID
review_id=$(curl -s -H "Authorization: Token $access_token" \
-d '{ "query": "query { repository(owner: \"'$owner'\", name: \"'$name'\") { pullRequest(number: '$pr') { reviews(first: 100) { edges { node { id } } } } } }" }' \
https://api.github.com/graphql | \
jq -r '.data.repository.pullRequest.reviews.edges[0].node.id')
curl -s -H "Authorization: Token $access_token" \
-d '{ "query": "mutation { updatePullRequestReview(input: {pullRequestReviewId: \"'$review_id'\", body: \"some test2\"}) { pullRequestReview { updatedAt } } }" }' \
https://api.github.com/graphql
请注意,您还可以使用 updatePullRequestReviewComment
更新拉取请求审查评论
使用 GitHub 的网络 UI,您可以编辑 PR 评论的评论摘要,例如在这个屏幕截图中(参见带有 "Edit review summary" 工具提示的铅笔图标):
如何使用 GitHub API?
我查看了 documentation 但找不到执行此操作的方法。我在使用 UI 进行更改时监视了在页面上触发的 Web 服务调用,我发现了对 https://api.github.com/repos/SonarSourceIT/pr-decoration/pull/3195/reviews/91117155/update
的调用,因此我尝试使用 curl
:[=19 进行相同的操作=]
$ curl -sL -u janos-ss:$token https://api.github.com/repos/SonarSourceIT/pr-decoration/pull/3195/reviews/91117155/update -X POST -d @comment.json | jq . | tee response.json
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3"
}
我对这不起作用并不感到惊讶,因为 URL 看起来不像任何已记录的 API 方法。
请注意,这与编辑评论不同。可以编辑评论 (documented here),但我想编辑 评论摘要,这是另外一回事。
这可以使用 REST API v3 来实现吗?我对 hacky 解决方案或使用 Selenium 或类似解决方案不感兴趣。我正在寻找一个干净的 API 解决方案,或者确认这实际上对于当前的 REST API v3.
是不可能的更新
正如 GitHub 支持所确认的那样,从今天开始使用 REST API v3 是不可能的。 (我确认接受的答案中的建议有效,我可能会使用它作为解决方法。)
您可以使用 GraphQL API v4 to update pull request review using updatePullRequestReview :
- 通过拉取请求编号查找评论并获取评论 ID 的查询
- 要执行的突变
updatePullRequestReview
您可以在 the GraphQL explorer 中测试以下内容:
query FindReview {
repository(owner: "bertrandmartel", name: "speed-test-lib") {
pullRequest(number: 46) {
reviews(first: 100) {
edges {
node {
id
}
}
}
}
}
}
mutation UpdateReview {
updatePullRequestReview(input: {pullRequestReviewId: "MDE3OlB1bGxSZXF1ZXN0UmV2aWV3OTExNjM5NjI=", body: "some test"}) {
pullRequestReview {
updatedAt
}
}
}
您可以找到有关形成 graphql 调用的其他信息here
以下脚本使用 curl & jq 请求评论列表,提取第一个并更新评论正文:
owner="SonarSourceIT"
name="pr-decoration"
pr=3195
access_token="YOUR_ACCESS_TOKEN"
# find reviews for PR - extract the first review ID
review_id=$(curl -s -H "Authorization: Token $access_token" \
-d '{ "query": "query { repository(owner: \"'$owner'\", name: \"'$name'\") { pullRequest(number: '$pr') { reviews(first: 100) { edges { node { id } } } } } }" }' \
https://api.github.com/graphql | \
jq -r '.data.repository.pullRequest.reviews.edges[0].node.id')
curl -s -H "Authorization: Token $access_token" \
-d '{ "query": "mutation { updatePullRequestReview(input: {pullRequestReviewId: \"'$review_id'\", body: \"some test2\"}) { pullRequestReview { updatedAt } } }" }' \
https://api.github.com/graphql
请注意,您还可以使用 updatePullRequestReviewComment
更新拉取请求审查评论