-
Notifications
You must be signed in to change notification settings - Fork 64
45 lines (38 loc) · 1.7 KB
/
discussion_auto_close.yml
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: Auto-Close Very Short Discussions
on:
discussion:
types: [created]
permissions:
discussions: write
jobs:
validate-discussion:
runs-on: ubuntu-latest
steps:
- name: Check word and character count
id: validation
run: |
MIN_WORDS=5
MIN_CHARS=10
BODY=$(jq -r '.discussion.body' "$GITHUB_EVENT_PATH")
WORD_COUNT=$(echo "$BODY" | wc -w)
CHAR_COUNT=$(echo -n "$BODY" | wc -m)
if [ "$WORD_COUNT" -lt $MIN_WORDS ] || [ "$CHAR_COUNT" -lt $MIN_CHARS ]; then
echo "too_short=true" >> "$GITHUB_OUTPUT"
echo "words=$WORD_COUNT" >> "$GITHUB_OUTPUT"
echo "chars=$CHAR_COUNT" >> "$GITHUB_OUTPUT"
else
echo "too_short=false" >> "$GITHUB_OUTPUT"
fi
- name: Comment and close if too short
if: steps.validation.outputs.too_short == 'true'
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/discussions/${{ github.event.discussion.number }}/comments" \
-d '{"body": "⚠️ Discussion closed: To protect against spam, discussion posts that do not meet a minimum word and character count are automatically closed. Please provide more details in your post."}'
curl -X PATCH \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/${{ github.repository }}/discussions/${{ github.event.discussion.number }}" \
-d '{"state": "closed"}'