-
Notifications
You must be signed in to change notification settings - Fork 6
75 lines (65 loc) · 2.39 KB
/
Copy pathblacklist-issue.yml
File metadata and controls
75 lines (65 loc) · 2.39 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Blacklist Management
on:
issues:
types: [opened, edited]
issue_comment:
types: [created]
jobs:
update-blacklist:
runs-on: ubuntu-latest
if: github.event.issue.title == '添加黑名单用户' || contains(github.event.comment.body, '/add-blacklist')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyyaml
- name: Update blacklist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_BODY: ${{ github.event.issue.body || github.event.comment.body }}
run: python ./update_blacklist.py
- name: Commit and Push Changes
id: commit
run: |
git diff --quiet
if [ $? -ne 0 ]; then
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git add config.yaml
git commit -m "Update blacklist from issue #${{ github.event.issue.number }}"
git push origin main
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "No changes to commit" >&2
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Comment and Close Issue
uses: actions/github-script@v6
with:
script: |
const changed = '${{ steps.commit.outputs.changed }}' === 'true';
let commentBody = '';
if (changed) {
commentBody = '✅ 黑名单用户已成功添加到配置文件!';
} else {
commentBody = 'ℹ️ 没有添加新的黑名单用户,所有用户已存在于黑名单中。';
}
// 回复用户
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.issue.number }},
body: commentBody
});
// 关闭issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.issue.number }},
state: 'closed'
});