File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -218,9 +218,31 @@ jobs:
218
218
- name : Post Comment on the PR
219
219
env :
220
220
GH_TOKEN : ${{ github.token }}
221
+ COMMENT_MARKER : " nix-helm-diff-777f3796-c80d-4d68-bf4f-8faad564f03f"
221
222
run : |
222
223
prNumber=$(cut -d/ -f1 <<<'${{ github.ref_name }}')
223
- gh pr comment "$prNumber" --body "$(cat pr-comment.md)"
224
+ # The `gh` command doesn’t return numeric comment ids, but instead node_ids, which don’t work with the regular API
225
+ # Why the regular API? Because the `gh` command doesn’t support editing comments:
226
+ existingCommentId=$(
227
+ curl --fail-with-body -sSL \
228
+ -X GET \
229
+ -H "Authorization: Bearer $GH_TOKEN" \
230
+ -H "Accept: application/vnd.github+json" \
231
+ -H "X-GitHub-Api-Version: 2022-11-28" \
232
+ "https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${prNumber}/comments" \
233
+ | jq -r --arg commentMarker "$COMMENT_MARKER" 'first(.[] | select(.body | contains($commentMarker)) | .id)'
234
+ )
235
+ if [ -z "$existingCommentId" ]; then
236
+ gh pr comment "$prNumber" --body "$(cat pr-comment.md) <!-- $COMMENT_MARKER -->"
237
+ else
238
+ curl --fail-with-body -sSL \
239
+ -X PATCH \
240
+ -H "Authorization: Bearer $GH_TOKEN" \
241
+ -H "Accept: application/vnd.github+json" \
242
+ -H "X-GitHub-Api-Version: 2022-11-28" \
243
+ "https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/comments/${existingCommentId}" \
244
+ -d "$(jq --null-input --arg body "$(cat pr-comment.md) <!-- $COMMENT_MARKER -->" '{body: $body}')"
245
+ fi
224
246
225
247
226
248
deploy :
You can’t perform that action at this time.
0 commit comments