Skip to content

Commit f6252dd

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents cdec921 + 5ef8324 commit f6252dd

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Close Spam Issues
2+
3+
on:
4+
issues:
5+
types: [opened, edited]
6+
workflow_dispatch:
7+
# 允许手动触发
8+
9+
jobs:
10+
close-spam-issues:
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
issues: write
15+
contents: read
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Close spam issues with short descriptions
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
run: |
25+
echo "? Starting spam issue cleanup..."
26+
27+
closed_count=0
28+
29+
# 使用 GitHub CLI 获取所有开放的 issues
30+
echo "? Fetching open issues..."
31+
32+
# 获取所有开放的 issues (不包括 PR)
33+
issues=$(gh issue list --state open --json number,title,body,author --limit 100)
34+
35+
if [ "$(echo "$issues" | jq '. | length')" = "0" ]; then
36+
echo "? No open issues found."
37+
exit 0
38+
fi
39+
40+
echo "? Processing $(echo "$issues" | jq '. | length') issues..."
41+
42+
# 处理每个 issue
43+
echo "$issues" | jq -r '.[] | @base64' | while read -r issue_data; do
44+
issue=$(echo "$issue_data" | base64 --decode)
45+
46+
issue_number=$(echo "$issue" | jq -r '.number')
47+
issue_title=$(echo "$issue" | jq -r '.title')
48+
issue_body=$(echo "$issue" | jq -r '.body // ""')
49+
issue_author=$(echo "$issue" | jq -r '.author.login')
50+
51+
# 计算标题和描述长度(去除空白字符)
52+
title_length=$(echo "$issue_title" | tr -d '[:space:]' | wc -c)
53+
body_length=$(echo "$issue_body" | tr -d '[:space:]' | wc -c)
54+
55+
echo "? Issue #$issue_number: '$issue_title' by $issue_author"
56+
echo " ? Title: $title_length chars, Body: $body_length chars"
57+
58+
# 如果标题和描述都少于20个字符,则关闭issue
59+
if [ "$title_length" -lt 20 ] && [ "$body_length" -lt 20 ]; then
60+
echo "? Closing spam issue #$issue_number (title: $title_length chars, body: $body_length chars)"
61+
62+
# 构建评论内容并写入临时文件
63+
echo "? This issue has been automatically closed due to insufficient content." > /tmp/comment.txt
64+
echo "" >> /tmp/comment.txt
65+
echo "**Reason:** Both title and description are too short (less than 20 characters each)" >> /tmp/comment.txt
66+
echo "- Title length: $title_length characters" >> /tmp/comment.txt
67+
echo "- Description length: $body_length characters" >> /tmp/comment.txt
68+
echo "" >> /tmp/comment.txt
69+
echo "Please provide more detailed information when creating issues. If this was closed in error, feel free to reopen with additional details." >> /tmp/comment.txt
70+
echo "" >> /tmp/comment.txt
71+
echo "@tinymins" >> /tmp/comment.txt
72+
73+
# 使用 GitHub CLI 添加评论
74+
if gh issue comment "$issue_number" --body-file /tmp/comment.txt; then
75+
echo "? Added comment to issue #$issue_number"
76+
77+
# 关闭 issue
78+
if gh issue close "$issue_number" --reason "not planned"; then
79+
echo "? Closed issue #$issue_number"
80+
closed_count=$((closed_count + 1))
81+
else
82+
echo "? Failed to close issue #$issue_number"
83+
fi
84+
else
85+
echo "? Failed to add comment to issue #$issue_number"
86+
fi
87+
else
88+
echo "? Issue #$issue_number has sufficient content, keeping open"
89+
fi
90+
91+
echo "---"
92+
done
93+
94+
echo "? Spam cleanup completed. Closed $closed_count issues."
95+
96+
- name: Report cleanup summary
97+
if: github.event_name == 'workflow_dispatch'
98+
run: |
99+
echo "? Spam issue cleanup workflow completed successfully!"
100+
echo ""
101+
echo "? This workflow automatically CLOSES issues with insufficient content:"
102+
echo " - Both title AND description must be shorter than 20 characters"
103+
echo " - Issues are closed with 'not planned' reason"
104+
echo " - A comment is added explaining the closure"
105+
echo " - @tinymins is notified in the comment"
106+
echo ""
107+
echo "? This workflow runs automatically on:"
108+
echo " ? New issues being opened (immediate spam detection)"
109+
echo " ?? Issues being edited (re-evaluation of content)"
110+
echo " ? Manual trigger (batch cleanup via Actions tab)"
111+
echo ""
112+
echo "? Closed issues can be reopened if they were closed in error."

0 commit comments

Comments
 (0)