4
4
from colorama import init , Fore , Back , Style
5
5
import sys
6
6
7
- # 访问秘钥和线程配置
7
+ # Replace with your own GitHub token.
8
+ # See https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
8
9
ACCESS_TOKEN = "ghp_xxxxxxxxxxxxxxxxxxxx"
9
- THREAD = 4 # 默认线程数量
10
+ THREAD = 4 # Thread count, default 4.
10
11
11
12
12
13
def pr_filter (pr ):
13
- """优化后的PR过滤器,假设已通过state='open'过滤"""
14
14
if pr .draft :
15
15
return False
16
16
if pr .user .login in ["dependabot[bot]" , "renovate[bot]" ]:
17
17
return True
18
18
return False
19
19
20
20
21
+ def repo_filter (repo ):
22
+ if repo .archived : return False ;
23
+ return True
24
+
25
+
26
+ def prefix (color : Fore , status , name ):
27
+ return f"{ color } [{ status } ] { Fore .RESET } <{ Fore .LIGHTBLUE_EX } { name } { Fore .RESET } >"
28
+
21
29
def handle_repo (r : Repository ):
30
+ if not repo_filter (r ):
31
+ tqdm .write (f"{ prefix (Fore .MAGENTA , "START" , r .name )} Repo filtered, skipped." )
32
+
22
33
try :
23
34
pull_requests = r .get_pulls (state = 'open' )
24
35
pr_list = list (pull_requests )
25
36
pr_count = len (pr_list )
26
37
27
38
if pr_count == 0 :
28
- tqdm .write (f"{ Fore .MAGENTA } [ START] { Fore . RESET } < { Fore . LIGHTBLUE_EX } { r .name } { Fore . RESET } > No PRs found, skipped." )
39
+ tqdm .write (f"{ prefix ( Fore .MAGENTA , " START" , r .name ) } No PRs found, skipped." )
29
40
return
30
- tqdm .write (f"{ Fore .MAGENTA } [ START] { Fore . RESET } < { Fore . LIGHTBLUE_EX } { r .name } { Fore . RESET } > with { pr_count } PRs." )
41
+ tqdm .write (f"{ prefix ( Fore .MAGENTA , " START" , r .name ) } with { pr_count } PRs, processing ." )
31
42
32
43
stats = {'skipped' : 0 , 'done' : 0 , 'errors' : 0 }
33
44
with tqdm (pr_list , desc = f"{ r .name :15} " , leave = False ) as pbar :
@@ -45,20 +56,17 @@ def handle_repo(r: Repository):
45
56
stats ['done' ] += 1
46
57
except Exception as ex :
47
58
stats ['errors' ] += 1
48
- tqdm .write (
49
- f"{ Fore .RED } [ERROR] { Fore .RESET } <{ Fore .BLUE } { r .name } { Fore .CYAN } #{ pr .number } { Fore .RESET } >"
50
- f" Failed to process : { str (ex )} "
51
- )
59
+ tqdm .write (f"{ prefix (Fore .RED , 'ERROR' , r .name )} Failed to process #{ pr .id } : { str (ex )} " )
52
60
finally :
53
61
pbar .set_postfix_str (f"S:{ stats ['skipped' ]} D:{ stats ['done' ]} E:{ stats ['errors' ]} " )
54
62
tqdm .write (
55
- f"{ Fore .GREEN } [ DONE] { Fore . RESET } < { Fore . LIGHTBLUE_EX } { r .name } { Fore . RESET } > "
63
+ f"{ prefix ( Fore .RED , ' DONE' , r .name ) } "
56
64
f"MERGED: { stats ['done' ]} "
57
65
f"SKIPPED: { stats ['skipped' ]} "
58
66
f"ERRORS: { stats ['errors' ]} "
59
67
)
60
68
except Exception as ex :
61
- tqdm .write (f"{ Fore .RED } [ ERROR] < { Fore . BLUE } { r .name } { Fore . RESET } > Failed to process : { str (ex )} " )
69
+ tqdm .write (f"{ prefix ( Fore .RED , ' ERROR' , r .name ) } Failed to process : { str (ex )} " )
62
70
63
71
64
72
if __name__ == "__main__" :
@@ -89,7 +97,7 @@ def handle_repo(r: Repository):
89
97
with ThreadPoolExecutor (max_workers = THREAD ) as executor :
90
98
futures = [executor .submit (handle_repo , repo ) for repo in repos ]
91
99
92
- with tqdm (total = len (repos ), unit = "repo" ,desc = "Repositories Progress" ) as main_pbar :
100
+ with tqdm (total = len (repos ), unit = "repo" , desc = "Repositories Progress" ) as main_pbar :
93
101
for future in as_completed (futures ):
94
102
try :
95
103
future .result ()
0 commit comments