Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

How to update a issue or PR comment in Github using curl and a GraphQL updateIssueComment mutation

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.

question from:https://stackoverflow.com/questions/65837496/how-to-update-a-issue-or-pr-comment-in-github-using-curl-and-a-graphql-updateiss

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...