Skip to content

Restrict Issue Comments #25

Restrict Issue Comments

Restrict Issue Comments #25

name: Restrict Issue Comments
on:
issue_comment:
types: [created]
permissions:
issues: write
contents: write
jobs:
moderate-comments:
runs-on: ubuntu-latest
steps:
- name: Check permissions and moderate
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
# Get issue and comment details
ISSUE_NUMBER=${{ github.event.issue.number }}
COMMENT_ID=${{ github.event.comment.id }}
COMMENT_USER="${{ github.event.comment.user.login }}"
ISSUE_CREATOR="${{ github.event.issue.user.login }}"
ORG_NAME="ChatAndBuild"
REPO="${{ github.repository }}"
echo "Processing comment by $COMMENT_USER on issue #$ISSUE_NUMBER"
# Check if commenter is issue creator
if [ "$COMMENT_USER" = "$ISSUE_CREATOR" ]; then
echo "✅ Allowing comment from issue creator: $COMMENT_USER"
exit 0
fi
# Check if commenter is organization member
if gh api "orgs/$ORG_NAME/members/$COMMENT_USER"; then
echo "✅ Allowing comment from org member: $COMMENT_USER"
exit 0
fi
echo "🚫 Restricting comment from unauthorized user: $COMMENT_USER"
# Delete the unauthorized comment
gh api -X DELETE "/repos/$REPO/issues/comments/$COMMENT_ID"
echo "✅ Deleted comment from $COMMENT_USER"