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

夙愿已清 提交于 2021-01-29 05:33:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!