@@ -58,38 +58,28 @@ runs:
5858 COMMENT_BODY=""
5959 fi
6060
61- # Find existing comment
62- COMMENT_ID =$(gh pr view ${PR_NUMBER} \
61+ # Find all existing comments with our identifier
62+ COMMENT_IDS =$(gh pr view ${PR_NUMBER} \
6363 --repo ${GITHUB_REPOSITORY} \
6464 --json comments \
6565 --jq '.comments[] | select(.body | contains("'"${COMMENT_IDENTIFIER}"'")) | .id')
6666
67- if [ -n "$COMMENT_BODY" ]; then
68- # Success case: create or update comment
69- if [ -n "$COMMENT_ID" ]; then
70- # Try to update existing comment, fall back to creating new one if it fails (e.g., 404)
71- if ! gh api \
72- --method PATCH \
73- -H "Accept: application/vnd.github+json" \
74- "/repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" \
75- -f body="${COMMENT_BODY}" 2>/dev/null; then
76- # Comment no longer exists, create a new one
77- gh pr comment ${PR_NUMBER} \
78- --repo ${GITHUB_REPOSITORY} \
79- --body "${COMMENT_BODY}"
67+ # Delete all existing comments with our identifier to avoid duplicates
68+ if [ -n "$COMMENT_IDS" ]; then
69+ echo "Found existing comment(s), deleting to avoid duplicates..."
70+ while IFS= read -r comment_id; do
71+ if [ -n "$comment_id" ]; then
72+ gh api \
73+ --method DELETE \
74+ -H "Accept: application/vnd.github+json" \
75+ "/repos/${GITHUB_REPOSITORY}/issues/comments/${comment_id}" 2>/dev/null || true
8076 fi
81- else
82- # Create new comment
83- gh pr comment ${PR_NUMBER} \
84- --repo ${GITHUB_REPOSITORY} \
85- --body "${COMMENT_BODY}"
86- fi
87- else
88- # Failure case: delete comment if it exists (ignore errors if already deleted)
89- if [ -n "$COMMENT_ID" ]; then
90- gh api \
91- --method DELETE \
92- -H "Accept: application/vnd.github+json" \
93- "/repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" 2>/dev/null || true
94- fi
77+ done <<< "$COMMENT_IDS"
78+ fi
79+
80+ # Create new comment if job succeeded
81+ if [ -n "$COMMENT_BODY" ]; then
82+ gh pr comment ${PR_NUMBER} \
83+ --repo ${GITHUB_REPOSITORY} \
84+ --body "${COMMENT_BODY}"
9585 fi
0 commit comments