-
Notifications
You must be signed in to change notification settings - Fork 0
45 lines (37 loc) · 1.44 KB
/
restrict-issue-comments.yml
File metadata and controls
45 lines (37 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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"