Reputation: 124656
Using the web UI of GitHub, you can edit the review summary of a PR review, for example as in this screenshot (see the pencil icon with the "Edit review summary" tooltip):
How to do this using the GitHub API?
I looked through the documentation but couldn't find a way to do this. I monitored the web service calls triggered on the page while making the change using the UI, I found a call to https://api.github.com/repos/SonarSourceIT/pr-decoration/pull/3195/reviews/91117155/update
, so I tried to do the same using curl
:
$ 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"
}
I'm not surprised this didn't work, as the URL doesn't look like any of the documented API methods.
Note that this is not the same as editing a comment. Editing a comment is possible (documented here), but I want to edit the review summary, which is something else.
Is this possible to do using the REST API v3? I'm not interested in hacky solutions or using Selenium or similar. I'm looking for a clean API solution, or confirmation that this is in fact not possible with the current REST API v3.
Update
As confirmed by GitHub support, this is not possible using the REST API v3 as of today. (I confirm the suggestion in the accepted answer works, I will probably use that as a workaround.)
Upvotes: 2
Views: 2699
Reputation: 45402
You can use GraphQL API v4 to update pull request review using updatePullRequestReview :
updatePullRequestReview
You can test the following in 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
}
}
}
You can find additionnal info about forming graphql call here
The following script uses curl & jq to request the list of reviews, extract the first one & update the review body :
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
Note that you can also update pull request review comment using updatePullRequestReviewComment
Upvotes: 2