File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 38
38
39
39
- name : Create or update comment
40
40
run : |
41
+ COMMENT_PREFIX="QHelp previews"
42
+ COMMENT_AUTHOR="github-actions[bot]"
41
43
PR_NUMBER="$(grep -o '^[0-9]\+$' pr_number.txt)"
44
+
42
45
# comment_id.txt may be empty if there is no existing comment
43
46
if [ -s comment_id.txt ]
44
47
then
50
53
# Create new comment
51
54
jq --rawfile body comment_body.txt '{"body":$body}' -n | gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" -X POST --input -
52
55
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
55
72
fi
56
73
env :
57
74
GITHUB_TOKEN : ${{ github.token }}
You can’t perform that action at this time.
0 commit comments