Skip to content

Commit 8323185

Browse files
authored
Update restrict-issue-comments.yml
1 parent 1f0e06f commit 8323185

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
# .github/workflows/restrict-issue-comments-alt.yml
2-
name: Restrict Issue Comments - Alternative
1+
name: Restrict Issue Comments
32

43
on:
54
issue_comment:
65
types: [created]
76

87
permissions:
98
issues: write
10-
contents: write
9+
members: read
1110

1211
jobs:
1312
moderate-comments:
@@ -23,6 +22,9 @@ jobs:
2322
COMMENT_USER="${{ github.event.comment.user.login }}"
2423
ISSUE_CREATOR="${{ github.event.issue.user.login }}"
2524
ORG_NAME="ChatAndBuild"
25+
REPO="${{ github.repository }}"
26+
27+
echo "Processing comment by $COMMENT_USER on issue #$ISSUE_NUMBER"
2628
2729
# Check if commenter is issue creator
2830
if [ "$COMMENT_USER" = "$ISSUE_CREATOR" ]; then
@@ -31,19 +33,19 @@ jobs:
3133
fi
3234
3335
# Check if commenter is organization member
34-
if gh api orgs/$ORG_NAME/members/$COMMENT_USER > /dev/null 2>&1; then
36+
if gh api "orgs/$ORG_NAME/members/$COMMENT_USER" > /dev/null 2>&1; then
3537
echo "✅ Allowing comment from org member: $COMMENT_USER"
3638
exit 0
3739
fi
3840
39-
echo "🚫 Restricting comment from: $COMMENT_USER"
41+
echo "🚫 Restricting comment from unauthorized user: $COMMENT_USER"
4042
41-
# Delete comment
42-
gh api -X DELETE /repos/${{ github.repository }}/issues/comments/$COMMENT_ID
43+
# Delete the unauthorized comment
44+
gh api -X DELETE "/repos/$REPO/issues/comments/$COMMENT_ID"
45+
echo "✅ Deleted comment from $COMMENT_USER"
4346
44-
# Lock issue
45-
gh api -X PUT /repos/${{ github.repository }}/issues/$ISSUE_NUMBER/lock
47+
# Add warning comment (this will be allowed since it's from the workflow)
48+
gh api -X POST "/repos/$REPO/issues/$ISSUE_NUMBER/comments" \
49+
-f body="⚠️ **Comment Removed**\n\n@$COMMENT_USER, only @$ORG_NAME organization members and the issue creator (@$ISSUE_CREATOR) can comment on this issue.\n\nYour comment has been removed but the discussion remains open for authorized participants."
4650
47-
# Add warning
48-
gh api -X POST /repos/${{ github.repository }}/issues/$ISSUE_NUMBER/comments \
49-
-f body="⚠️ **Comment Restricted**\n\nOnly @$ORG_NAME organization members and the issue creator (@$ISSUE_CREATOR) can comment on this issue."
51+
echo "✅ Added warning comment"

0 commit comments

Comments
 (0)