Skip to content

Commit 5aa88b0

Browse files
authored
Update discussion_auto_close.yml
1 parent 967908e commit 5aa88b0

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

.github/workflows/discussion_auto_close.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
types: [created]
66

77
permissions:
8+
issues: write
89
discussions: write
910

1011
jobs:
@@ -28,19 +29,33 @@ jobs:
2829
else
2930
echo "too_short=false" >> "$GITHUB_OUTPUT"
3031
fi
31-
echo "$GITHUB_OUTPUT"
32+
echo "$GITHUB_OUTPUT""
3233
33-
- name: Comment and close if too short
34+
- name: Notify User via GitHub Mention (Generates Email) then Delete Discussion
3435
if: steps.validation.outputs.too_short == 'true'
35-
run: |
36-
curl -X POST \
37-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
38-
-H "Accept: application/vnd.github.v3+json" \
39-
"https://api.github.com/repos/${{ github.repository }}/discussions/${{ github.event.discussion.number }}/comments" \
40-
-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."}'
41-
42-
curl -X PATCH \
43-
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
44-
-H "Accept: application/vnd.github.v3+json" \
45-
"https://api.github.com/repos/${{ github.repository }}/discussions/${{ github.event.discussion.number }}" \
46-
-d '{"state": "closed"}'
36+
uses: actions/github-script@v7
37+
env:
38+
WORDS: ${{ steps.validation.outputs.words }}
39+
CHARS: ${{ steps.validation.outputs.chars }}
40+
with:
41+
script: |
42+
const { discussion } = context.payload;
43+
44+
await github.graphql(`
45+
mutation($discussionId: ID!, $body: String!) {
46+
addDiscussionComment(input: {
47+
discussionId: $discussionId,
48+
body: $body
49+
}) { comment { id } }
50+
}`,
51+
{
52+
discussionId: discussion.node_id,
53+
body: `⚠️ @${discussion.user.login}\nDiscussion closed: To protect against spam, discussion posts that do not meet a minimum word and character count are automatically deleted. Please provide more details in a new post.`
54+
}
55+
);
56+
57+
await github.graphql(`
58+
mutation($discussionId: ID!) {
59+
deleteDiscussion(input: {id: $discussionId}) { discussion { id } }
60+
}`, { discussionId: discussion.node_id }
61+
);

0 commit comments

Comments
 (0)