Skip to content

Commit 92657b0

Browse files
authored
Fix Comment Update job: use gh api instead of gh pr review (#438)
* use gh api instead of gh pr review * remove backslashes * trigger workflow to test comment update * use patch instead of delete * take2-trigger workflow to test comment update * use an actual new line to avoid \n being treated as literal chars
1 parent e78ec62 commit 92657b0

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

.github/workflows/analyze.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,29 @@ jobs:
6363
run: |
6464
MARKER="<!-- Analyze workflow report -->"
6565
COMMENT_BODY="${MARKER}\n$(cat ./results/analysis_report.md)"
66-
EXISTING_COMMENT_ID=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq ".comments[] | select(.body | contains(\"${MARKER}\")) | .id" | head -1)
67-
if [ ! -z "$EXISTING_COMMENT_ID" ]; then
68-
gh api -X DELETE /repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT_ID
69-
fi
70-
echo -e "$COMMENT_BODY" | gh pr comment ${{ github.event.pull_request.number }} --body-file -
66+
EXISTING_COMMENT_ID=$(gh api "/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" --jq ".[] | select(.body | contains(\"${MARKER}\")) | .id" | head -1)
67+
if [ -n "$EXISTING_COMMENT_ID" ]; then
68+
echo "Updating existing comment with ID: $EXISTING_COMMENT_ID"
69+
echo "$COMMENT_BODY" | gh api -X PATCH "/repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT_ID" -F body=@-
70+
else
71+
echo "Creating new comment"
72+
echo "$COMMENT_BODY" | gh pr comment ${{ github.event.pull_request.number }} --body-file -
73+
fi
7174
cat ./results/analysis_report.md
7275
- name: Update comment for PR
7376
if: ${{ github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' }}
7477
env:
7578
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7679
run: |
7780
MARKER="<!-- Analyze workflow report -->"
78-
COMMENT_BODY="${MARKER}\n$(cat ./results/analysis_report.md)"
79-
EXISTING_COMMENT_ID=$(gh pr view ${{ github.event.pull_request.number }} --json comments --jq ".comments[] | select(.body | contains(\"${MARKER}\")) | .id" | head -1)
80-
if [ ! -z "$EXISTING_COMMENT_ID" ]; then
81-
gh api -X DELETE /repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT_ID
81+
COMMENT_BODY="${MARKER}
82+
$(cat ./results/analysis_report.md)"
83+
EXISTING_COMMENT_ID=$(gh api "/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" --jq ".[] | select(.body | contains(\"${MARKER}\")) | .id" | head -1)
84+
if [ -n "$EXISTING_COMMENT_ID" ]; then
85+
echo "Updating existing comment with ID: $EXISTING_COMMENT_ID"
86+
echo "$COMMENT_BODY" | gh api -X PATCH "/repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT_ID" -F body=@-
87+
else
88+
echo "Creating new comment"
89+
echo "$COMMENT_BODY" | gh pr comment ${{ github.event.pull_request.number }} --body-file -
8290
fi
83-
echo -e "$COMMENT_BODY" | gh pr comment ${{ github.event.pull_request.number }} --body-file -
8491
cat ./results/analysis_report.md

0 commit comments

Comments
 (0)