Skip to content

Commit

Permalink
ci: fix blockerbot duplicate comment
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaelahidev committed Dec 21, 2024
1 parent cbdc75b commit 019d92f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/create-demo-attachments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@ jobs:
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
COMMENTS_URL="https://api.github.com/repos/${{ github.repository }}/issues/$PR_NUMBER/comments"
# Get the most recent bot comment that contains "Branch Links"
curl -H "Authorization: token ${{ secrets.BLOCKERABOT_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
$COMMENTS_URL > comments.json
if [ -s comments.json ] && [ "$(jq 'type' comments.json)" = "array" ] && [ "$(jq 'length' comments.json)" != "0" ]; then
cat comments.json | jq -r '.[] | select(.user.login == "blockerabot" and (.body | test("Branch Links"; "i"))) | .id' > comment_id.txt
fi
# If comment ID is found, set it to environment variable
if [[ -s comment_id.txt ]]; then
COMMENT_ID=$(cat comment_id.txt)
echo "comment_id=${COMMENT_ID}" >> $GITHUB_ENV
# Extract the most recent comment ID from blockerabot that contains "Branch Links"
if [ -s comments.json ] && [ "$(jq 'type' comments.json)" = "array" ]; then
COMMENT_ID=$(jq -r 'map(select(.user.login == "blockerabot" and contains(.body, "Branch Links"))) | last | .id' comments.json)
if [ "$COMMENT_ID" != "null" ] && [ ! -z "$COMMENT_ID" ]; then
echo "comment_id=$COMMENT_ID" >> $GITHUB_ENV
echo "Found existing comment ID: $COMMENT_ID"
else
echo "No existing comment found"
fi
fi
# Step to encode JSON with Base64
Expand Down

0 comments on commit 019d92f

Please sign in to comment.