问题
I want to update a comment in a Github PR or issue and I found it hard to find a working example. That's why I ask this question, to answer it myself. Hopefully someone else can use this.
回答1:
The following snippet will update an issue or PR comment using a GraphQL mutation and curl.
Make sure you replace <REPLACE WITH YOUR GITHUB PERSONAL ACCESS TOKEN>
with an access token that has repo
scope on the repo in which the PR/issue appears.
Then replace the REPLACE WITH COMMENT NODE ID
with the node_id of your comment, e.g. MDEyOklzc3VlQ29tbWVudDc2NDc0NzcwOA==
.
Please note the ugly look of escaping quotes and backslashes.
curl -H "Authorization: bearer <REPLACE WITH YOUR GITHUB PERSONAL ACCESS TOKEN>" -X POST -d \
"{ \
\"query\": \"mutation { \
updateIssueComment(input: { \
id: \\\"REPLACE WITH COMMENT NODE ID\\\", \
body: \\\"This is fantastic\\\" \
}) { \
issueComment { \
lastEditedAt \
} \
} \
}\"
} \
" https://api.github.com/graphql
This example query returns the issue's last edit time like so:
{"data":{"updateIssueComment":{"issueComment":{"lastEditedAt":"2021-01-21T23:45:53Z"}}}}
Make sure you read this documentation for the GraphQL mutation reference and for a manual on how to use the GraphQL endpoint manipulation:
https://docs.github.com/en/graphql/reference/mutations#updateissuecomment
https://docs.github.com/en/graphql/guides/forming-calls-with-graphql#communicating-with-graphql
来源:https://stackoverflow.com/questions/65837496/how-to-update-a-issue-or-pr-comment-in-github-using-curl-and-a-graphql-updateiss