Skip to content

Commit 6b9fef1

Browse files
authored
chore: when diffing, update existing comments (#1149)
LW-10047
1 parent fec4f35 commit 6b9fef1

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

.github/workflows/std.yml

+23-1
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,31 @@ jobs:
218218
- name: Post Comment on the PR
219219
env:
220220
GH_TOKEN: ${{ github.token }}
221+
COMMENT_MARKER: "nix-helm-diff-777f3796-c80d-4d68-bf4f-8faad564f03f"
221222
run: |
222223
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
224246
225247
226248
deploy:

0 commit comments

Comments
 (0)