File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3838
3939 - name : Create or update comment
4040 run : |
41+ COMMENT_PREFIX="QHelp previews"
42+ COMMENT_AUTHOR="github-actions[bot]"
4143 PR_NUMBER="$(grep -o '^[0-9]\+$' pr_number.txt)"
44+
4245 # comment_id.txt may be empty if there is no existing comment
4346 if [ -s comment_id.txt ]
4447 then
5053 # Create new comment
5154 jq --rawfile body comment_body.txt '{"body":$body}' -n | gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" -X POST --input -
5255 else
53- # Update existing comment
54- jq --rawfile body comment_body.txt '{"body":$body}' -n | gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" -X PATCH --input -
56+ # Fetch existing comment, and validate:
57+ # - comment belongs to the PR with number $PR_NUMBER
58+ # - comment starts with the expected prefix ("QHelp previews")
59+ # - comment author is github-actions[bot]
60+ FILTER="select(.issue_url | test(\"${GITHUB_REPOSITORY}/issues/${PR_NUMBER}$\")) \
61+ | select(.body | test(\"^${COMMENT_PREFIX}\")) \
62+ | select(.user.login == \"${COMMENT_AUTHOR}\") \
63+ | .id"
64+ COMMENT_ID=$(gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" | jq "${FILTER}")
65+ if [ $COMMENT_ID ]
66+ then
67+ # Update existing comment
68+ jq --rawfile body comment_body.txt '{"body":$body}' -n | gh api "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" -X PATCH --input -
69+ else
70+ echo "Comment ${COMMENT_ID} did not pass validations: not editing."
71+ fi
5572 fi
5673 env :
5774 GITHUB_TOKEN : ${{ github.token }}
You can’t perform that action at this time.
0 commit comments