Skip to content

Commit 30c87e9

Browse files
committed
feat: Support multi-thread merging.
1 parent 23e994b commit 30c87e9

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A simple python script to merge all filtered PRs in a GitHub user/org/repository.
44

5-
![Example](example.png)
5+
![Example](doc/example.png)
66

77
## Usage
88

example.png doc/example.png

File renamed without changes.

src/run.py

+20-12
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,41 @@
44
from colorama import init, Fore, Back, Style
55
import sys
66

7-
# 访问秘钥和线程配置
7+
# Replace with your own GitHub token.
8+
# See https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
89
ACCESS_TOKEN = "ghp_xxxxxxxxxxxxxxxxxxxx"
9-
THREAD = 4 # 默认线程数量
10+
THREAD = 4 # Thread count, default 4.
1011

1112

1213
def pr_filter(pr):
13-
"""优化后的PR过滤器,假设已通过state='open'过滤"""
1414
if pr.draft:
1515
return False
1616
if pr.user.login in ["dependabot[bot]", "renovate[bot]"]:
1717
return True
1818
return False
1919

2020

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+
2129
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+
2233
try:
2334
pull_requests = r.get_pulls(state='open')
2435
pr_list = list(pull_requests)
2536
pr_count = len(pr_list)
2637

2738
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.")
2940
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.")
3142

3243
stats = {'skipped': 0, 'done': 0, 'errors': 0}
3344
with tqdm(pr_list, desc=f"{r.name:15}", leave=False) as pbar:
@@ -45,20 +56,17 @@ def handle_repo(r: Repository):
4556
stats['done'] += 1
4657
except Exception as ex:
4758
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)}")
5260
finally:
5361
pbar.set_postfix_str(f"S:{stats['skipped']} D:{stats['done']} E:{stats['errors']}")
5462
tqdm.write(
55-
f"{Fore.GREEN}[DONE] {Fore.RESET}<{Fore.LIGHTBLUE_EX}{r.name}{Fore.RESET}> "
63+
f"{prefix(Fore.RED, 'DONE', r.name)} "
5664
f"MERGED: {stats['done']} "
5765
f"SKIPPED: {stats['skipped']} "
5866
f"ERRORS: {stats['errors']} "
5967
)
6068
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)}")
6270

6371

6472
if __name__ == "__main__":
@@ -89,7 +97,7 @@ def handle_repo(r: Repository):
8997
with ThreadPoolExecutor(max_workers=THREAD) as executor:
9098
futures = [executor.submit(handle_repo, repo) for repo in repos]
9199

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:
93101
for future in as_completed(futures):
94102
try:
95103
future.result()

0 commit comments

Comments
 (0)