'Create comment on pull request
GitHub's comment API seems to allow you to create comments on a pull request, but only if you supply a specific line number in the diff to comment on. Is there a way to create a comment on the pull request as a whole, the equivalent of typing at the bottom of the pull request screen in GitHub's web interface?
Solution 1:[1]
According to Ivan, I was able to do something like:
$ curl -s -H "Authorization: token ${ACCESS_TOKEN}" \
-X POST -d '{"body": "Your Message to Comment"}' \
"https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/issues/${PR_NUMBER}/comments"
or
$ curl -s -u "${GITHUB_ACCOUNT} \
-X POST -d '{"body": "Your Message to Comment"}' \
"https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/issues/${PR_NUMBER}/comments"
with password prompt
Solution 2:[2]
Using GraphQL API v4, you would need to get the Pull Request id using pullrequest Schema and perform addComment mutation afterwards :
query FindPullRequestID {
repository(owner:"bertrandmartel", name:"ustream-dl") {
pullRequest(number:2) {
id
}
}
}
mutation AddPullRequestComment {
addComment(input:{subjectId:"MDExOlB1bGxSZXF1ZXN0MTU0NzExOTA0",body: "test comment"}) {
commentEdge {
node {
createdAt
body
}
}
subject {
id
}
}
}
Solution 3:[3]
Use this CURL:
curl -s -H "Authorization: token your_token_here" \
-X POST -d '{"body":"Some Comments"}' \
"https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/reviews"
or Python code:
import requests
headers = {
'Authorization': 'token your_token_here',
}
data = '{"body":"Some Comments"}'
response = requests.post('https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/reviews', headers=headers, data=data)
print (response.json())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tuomastik |
| Solution 2 | Bertrand Martel |
| Solution 3 | Alok Kelsey |
