-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathupdate_blacklist.py
More file actions
78 lines (64 loc) · 2.19 KB
/
update_blacklist.py
File metadata and controls
78 lines (64 loc) · 2.19 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
76
77
78
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
"""
通过GitHub Issue更新黑名单用户的脚本
"""
import yaml
import os
import re
def load_config():
"""加载配置文件"""
with open('config.yaml', 'r', encoding='utf-8') as f:
return yaml.load(f, Loader=yaml.FullLoader)
def save_config(config):
"""保存配置文件"""
with open('config.yaml', 'w', encoding='utf-8') as f:
yaml.dump(config, f, allow_unicode=True, default_flow_style=False, sort_keys=False)
def extract_blacklist_users(body):
"""从issue内容中提取黑名单用户"""
users = []
# 匹配用户名列表,支持多种格式
lines = body.split('\n')
for line in lines:
# 移除注释和空白行
line = line.split('#')[0].strip()
if not line:
continue
# 匹配逗号分隔的用户名
if ',' in line:
users.extend([user.strip() for user in line.split(',') if user.strip()])
else:
# 匹配单个用户名
users.append(line.strip())
# 去重并过滤空字符串
return list(set([user for user in users if user]))
def update_blacklist():
"""更新黑名单用户"""
# 获取issue内容
issue_body = os.environ.get('ISSUE_BODY', '')
if not issue_body:
print("No issue body found")
return
# 提取黑名单用户
new_users = extract_blacklist_users(issue_body)
if not new_users:
print("No new users found in issue body")
return
# 加载现有配置
config = load_config()
all_config = config.get('all_config', {})
black_user = all_config.get('black_user', [])
# 添加新用户,去重
original_count = len(black_user)
for user in new_users:
if user not in black_user:
black_user.append(user)
# 保存更新后的配置
all_config['black_user'] = black_user
config['all_config'] = all_config
save_config(config)
print(f"Added {len(black_user) - original_count} new users to blacklist")
print(f"Total blacklist users: {len(black_user)}")
print(f"New users: {', '.join(new_users)}")
if __name__ == "__main__":
update_blacklist()