Skip to content

Delete PR Comments

Delete PR Comments #4

name: Delete PR Comments
on:
workflow_dispatch:
jobs:
delete-comments:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Delete comments
run: |
set -x # Enable debug mode to see commands being run
PRS=$(gh pr list --state open --json number -q '.[].number') || { echo "Failed to list PRs"; exit 1; }
echo "Found PRs: $PRS"
for PR in $PRS; do
echo "Processing PR #$PR"
# Get all comments on the PR
COMMENTS=$(gh api /repos/${{ github.repository }}/issues/$PR/comments \
--jq '.[] | select(.body | contains("Can't wait to you")) | .id') || { echo "Failed to get comments for PR #$PR"; continue; }
echo "Found comments to delete: $COMMENTS"
# Delete each matching comment
for COMMENT_ID in $COMMENTS; do
echo "Attempting to delete comment $COMMENT_ID from PR #$PR"
gh api --method DELETE /repos/${{ github.repository }}/issues/comments/$COMMENT_ID || echo "Failed to delete comment $COMMENT_ID"
done
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_DEBUG: 1 # Enable GitHub CLI debugging