So as it turns out, I tried to update the first comment using the GitHub API for pull requests comments or issues comments. But that was wrong because the first comment on the GitHub pull request page is actually not a comment! I realized it is the 'body' of the pull request and can super easily be updated using this update API and to read the 'body' you can use this get API:
For curl (GET):
This will get you all the data of the Pull Request. If you want just the body text then you would need to write additional commands to extract it. Check out the script in the next section under GitHub CLI (GET) which gives you the complete turn-key solution for getting the body text.
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token <TOKEN>" \
https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER
For curl (UPDATE):
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token <TOKEN>" \
https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER \
-d '{"body":"updated body"}'
for GitHub CLI (GET):
This will get you all the information from the pull request and you will need to extract the body text (see the next code snippet for the script that gets you the body text).
# GitHub CLI api
# https://cli.github.com/manual/gh_api
gh api \
-H "Accept: application/vnd.github+json" \
/repos/OWNER/REPO/pulls/PULL_NUMBER
here is the code for extracting exactly the body text:
pr_data=$(gh api -H "Accept: application/vnd.github+json" /repos/OWNER/REPO/pulls/PULL_REQUEST_NUMBER)
body_row=$(grep "body" <<< "$pr_data")
body_string=`echo "$body_row" | awk -F 'body":' '{printf $NF}'`
body_string2=`echo "$body_string" | cut -d'"' -f 2`
echo $body_string2
for GitHub CLI (UPDATE):
# GitHub CLI api
# https://cli.github.com/manual/gh_api
gh api \
--method PATCH \
-H "Accept: application/vnd.github+json" \
/repos/OWNER/REPO/pulls/PULL_NUMBER \
-f body='updated body'