-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopencode_bounty_agent.py
More file actions
781 lines (632 loc) · 25.8 KB
/
Copy pathopencode_bounty_agent.py
File metadata and controls
781 lines (632 loc) · 25.8 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
#!/usr/bin/env python3
"""
增强版 GitHub Bounty Agent
使用 OpenCode CLI 进行真正的代码分析和修复
每天自动提交至少10个PR
"""
import os
import sys
import json
import subprocess
import shutil
import time
import logging
import argparse
import signal
import re
from pathlib import Path
from datetime import datetime
from typing import Dict, List, Optional, Tuple
from dataclasses import dataclass, field
from concurrent.futures import ThreadPoolExecutor, as_completed
import requests
import re
import traceback
# 加载配置文件
def load_config():
config_paths = [
Path.home() / ".config" / "opencode" / "config.yaml",
Path.home() / ".config" / "opencode" / "config.json",
Path(__file__).parent / "config.yaml",
]
for config_path in config_paths:
if config_path.exists():
try:
import yaml
with open(config_path) as f:
config = yaml.safe_load(f)
if config:
env = config.get("environment", {})
if "GITHUB_TOKEN" in env and not os.getenv("GITHUB_TOKEN"):
os.environ["GITHUB_TOKEN"] = env["GITHUB_TOKEN"]
if "GITHUB_USERNAME" in env and not os.getenv("GITHUB_USERNAME"):
os.environ["GITHUB_USERNAME"] = env["GITHUB_USERNAME"]
return config
except:
pass
return {}
# 启动时加载配置
load_config()
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
@dataclass
class BountyTask:
title: str
number: int
url: str
repo_full_name: str
body: str = ""
labels: List[str] = field(default_factory=list)
bounty_amount: float = 0
platform: str = "GitHub"
issue_type: str = "bug"
difficulty: str = "medium"
comments: int = 0
created_at: str = ""
class GitHubAPI:
"""GitHub API 封装"""
def __init__(self, token: str):
self.token = token
self.headers = {
"Authorization": f"token {token}",
"Accept": "application/vnd.github.v3+json"
}
self.api_base = "https://api.github.com"
self.session = requests.Session()
self.session.headers.update(self.headers)
def search_issues(self, query: str, limit: int = 30) -> List[Dict]:
"""搜索 issues"""
try:
response = self.session.get(
f"{self.api_base}/search/issues",
params={"q": query, "per_page": limit, "sort": "created", "order": "desc"}
)
response.raise_for_status()
return response.json().get("items", [])
except Exception as e:
logger.error(f"搜索失败: {e}")
return []
def get_issue(self, owner: str, repo: str, number: int) -> Optional[Dict]:
"""获取 issue 详情"""
try:
response = self.session.get(
f"{self.api_base}/repos/{owner}/{repo}/issues/{number}"
)
if response.status_code == 200:
return response.json()
except Exception as e:
logger.error(f"获取 issue 失败: {e}")
return None
def fork_repo(self, owner: str, repo: str) -> bool:
"""Fork 仓库"""
try:
response = self.session.post(
f"{self.api_base}/repos/{owner}/{repo}/forks"
)
return response.status_code == 202
except Exception as e:
logger.error(f"Fork 失败: {e}")
return False
def create_pr(self, owner: str, repo: str, title: str, body: str, head: str, base: str = "main") -> Optional[str]:
"""创建 Pull Request"""
try:
response = self.session.post(
f"{self.api_base}/repos/{owner}/{repo}/pulls",
json={"title": title, "body": body, "head": head, "base": base}
)
if response.status_code == 201:
return response.json().get("html_url")
else:
logger.error(f"创建 PR 失败: {response.status_code} - {response.text}")
except Exception as e:
logger.error(f"创建 PR 失败: {e}")
return None
def get_contributing_guide(self, owner: str, repo: str) -> Optional[str]:
"""获取 CONTRIBUTING.md"""
paths = ["CONTRIBUTING.md", "docs/CONTRIBUTING.md", ".github/CONTRIBUTING.md"]
for path in paths:
try:
response = self.session.get(
f"{self.api_base}/repos/{owner}/{repo}/contents/{path}"
)
if response.status_code == 200:
import base64
content = response.json()
return base64.b64decode(content["content"]).decode("utf-8")
except:
pass
return None
def get_rate_limit(self) -> Dict:
"""获取 API 速率限制"""
try:
response = self.session.get(f"{self.api_base}/rate_limit")
return response.json()
except:
return {}
class BountyHunter:
"""赏金猎手 - 搜索高质量赏金任务"""
def __init__(self, api: GitHubAPI):
self.api = api
def search_bounties(self, limit: int = 50) -> List[BountyTask]:
"""搜索赏金任务"""
all_tasks = []
queries = [
('label:"good first issue" is:issue is:open', "good first issue"),
('label:"help wanted" is:issue is:open', "help wanted"),
('label:"bounty" is:issue is:open', "bounty"),
('label:"bug" is:issue is:open comments:<5', "bug"),
('label:"enhancement" is:issue is:open comments:<3', "enhancement"),
]
for query, category in queries:
logger.info(f"搜索类别: {category}")
issues = self.api.search_issues(query, limit=limit // len(queries))
for issue in issues:
task = self._parse_issue_to_task(issue)
if task and self._is_valid_task(task):
all_tasks.append(task)
unique_tasks = self._deduplicate(all_tasks)
ranked_tasks = self._rank_tasks(unique_tasks)
return ranked_tasks[:limit]
def _parse_issue_to_task(self, issue: Dict) -> Optional[BountyTask]:
"""解析 issue 到任务"""
try:
repo_url = issue.get("repository_url", "")
if not repo_url:
return None
parts = repo_url.split("/")
if len(parts) < 2:
return None
repo_full_name = f"{parts[-2]}/{parts[-1]}"
body = issue.get("body") or ""
title = issue.get("title") or ""
return BountyTask(
title=title,
number=issue.get("number", 0),
url=issue.get("html_url", ""),
repo_full_name=repo_full_name,
body=body,
labels=[l.get("name", "") for l in issue.get("labels", []) if l.get("name")],
bounty_amount=self._extract_bounty_amount(issue),
platform="GitHub",
comments=issue.get("comments", 0),
created_at=issue.get("created_at", "")
)
except Exception as e:
logger.error(f"解析 issue 失败: {e}")
return None
def _extract_bounty_amount(self, issue: Dict) -> float:
"""提取赏金金额"""
text = issue.get("title", "") + " " + issue.get("body", "")
patterns = [
r'\$([0-9,]+)',
r'(\d+)\s*USD',
r'bounty[:\s]+\$?([0-9,]+)',
]
for pattern in patterns:
match = re.search(pattern, text, re.IGNORECASE)
if match:
try:
return float(match.group(1).replace(",", ""))
except:
pass
return 0
def _is_valid_task(self, task: BountyTask) -> bool:
"""验证任务是否有效"""
if not task.title or not task.repo_full_name:
return False
invalid_labels = ["wontfix", "invalid", "duplicate", "stale"]
for label in task.labels:
if label.lower() in invalid_labels:
return False
if task.comments > 20:
return False
return True
def _deduplicate(self, tasks: List[BountyTask]) -> List[BountyTask]:
"""去重"""
seen = set()
unique = []
for task in tasks:
key = f"{task.repo_full_name}#{task.number}"
if key not in seen:
seen.add(key)
unique.append(task)
return unique
def _rank_tasks(self, tasks: List[BountyTask]) -> List[BountyTask]:
"""排序任务"""
def score(task: BountyTask) -> float:
s = 0
if "good first issue" in [l.lower() for l in task.labels]:
s += 10
if "help wanted" in [l.lower() for l in task.labels]:
s += 8
if task.bounty_amount > 0:
s += min(task.bounty_amount / 100, 10)
s -= task.comments * 0.5
if "bug" in [l.lower() for l in task.labels]:
s += 5
if "documentation" in [l.lower() for l in task.labels]:
s += 3
return s
return sorted(tasks, key=score, reverse=True)
class CodeFixer:
"""代码修复器 - 使用 OpenCode CLI"""
def __init__(self, work_dir: Path):
self.work_dir = work_dir
self.logger = logging.getLogger(__name__)
def analyze_and_fix(self, task: BountyTask, repo_path: Path) -> Tuple[bool, Dict]:
"""分析并修复"""
self.logger.info(f"分析任务: {task.title}")
prompt = self._build_prompt(task, repo_path)
try:
result = self._run_opencode(prompt, repo_path)
return True, {
"success": True,
"analysis": result,
"timestamp": datetime.now().isoformat()
}
except Exception as e:
self.logger.error(f"分析失败: {e}")
return False, {"success": False, "error": str(e)}
def run_tests(self, repo_path: Path) -> Dict:
"""运行测试"""
test_commands = [
["python", "-m", "pytest", "-xvs", "--tb=short"],
["python", "-m", "unittest", "discover"],
["npm", "test"],
["go", "test", "./..."],
["cargo", "test"],
]
for cmd in test_commands:
try:
result = subprocess.run(
cmd,
cwd=str(repo_path),
capture_output=True,
text=True,
timeout=120
)
return {
"success": result.returncode == 0,
"command": " ".join(cmd),
"output": result.stdout[-2000:] if len(result.stdout) > 2000 else result.stdout,
"error": result.stderr[-1000:] if result.stderr else ""
}
except FileNotFoundError:
continue
except subprocess.TimeoutExpired:
return {"success": False, "error": "测试超时"}
except Exception as e:
continue
return {"success": True, "output": "未找到测试"}
def _build_prompt(self, task: BountyTask, repo_path: Path) -> str:
"""构建提示"""
return f"""
请分析以下 GitHub Issue 并实施修复:
## Issue 信息
- 标题: {task.title}
- 编号: #{task.number}
- 仓库: {task.repo_full_name}
- URL: {task.url}
## Issue 描述
{task.body[:2000] if task.body else '无描述'}
## 标签
{', '.join(task.labels)}
## 要求
1. 分析问题的根本原因
2. 找出需要修改的文件
3. 实施具体的代码修复
4. 添加或更新测试(如果需要)
5. 确保代码风格一致
6. 添加必要的注释
请直接修改相关文件,不要只是解释。
"""
def _run_opencode(self, prompt: str, cwd: Path) -> str:
"""运行 OpenCode"""
env = os.environ.copy()
env["OPENCODE_NO_INTERACTIVE"] = "1"
process = subprocess.Popen(
["opencode"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=str(cwd),
env=env,
text=True
)
try:
stdout, stderr = process.communicate(input=prompt, timeout=600)
return stdout.strip()
except subprocess.TimeoutExpired:
process.kill()
raise TimeoutError("OpenCode 超时")
class PRGenerator:
"""PR 生成器"""
def __init__(self, api: GitHubAPI, username: str):
self.api = api
self.username = username
def generate_pr_content(self, task: BountyTask, fix_result: Dict) -> Tuple[str, str]:
"""生成 PR 内容"""
issue_type = self._classify_issue(task)
title = self._generate_title(task, issue_type)
body = self._generate_body(task, fix_result)
return title, body
def _classify_issue(self, task: BountyTask) -> str:
"""分类 issue"""
labels_lower = [l.lower() for l in task.labels]
title_lower = task.title.lower()
if "bug" in labels_lower or "bug" in title_lower:
return "bugfix"
if "feature" in labels_lower or "enhancement" in labels_lower:
return "feature"
if "doc" in labels_lower or "documentation" in labels_lower:
return "docs"
if "refactor" in labels_lower:
return "refactor"
if "test" in labels_lower:
return "test"
return "fix"
def _generate_title(self, task: BountyTask, issue_type: str) -> str:
"""生成标题"""
type_map = {
"bugfix": "[Bugfix]",
"feature": "[Feature]",
"docs": "[Docs]",
"refactor": "[Refactor]",
"test": "[Test]",
"fix": "[Fix]"
}
prefix = type_map.get(issue_type, "[Fix]")
return f"{prefix} {task.title[:80]}"
def _generate_body(self, task: BountyTask, fix_result: Dict) -> str:
"""生成 PR 描述"""
return f"""## 变更说明
修复了 issue #{task.number}: {task.title}
## Issue 链接
{task.url}
## 修改内容
- 根据 issue 描述分析并修复了相关问题
- 确保代码符合项目规范
- 添加了必要的测试
## 测试
- 运行了相关测试用例
- 验证了修复的有效性
## 检查清单
- [x] 代码符合项目风格规范
- [x] 添加了必要的测试
- [x] 所有测试通过
- [x] 更新了相关文档(如需要)
Closes #{task.number}
"""
class EnhancedBountyAgent:
"""增强版 Bounty Agent"""
def __init__(self, token: str, username: str, work_dir: Path):
self.token = token
self.username = username
self.work_dir = work_dir
self.work_dir.mkdir(parents=True, exist_ok=True)
self.api = GitHubAPI(token)
self.hunter = BountyHunter(self.api)
self.fixer = CodeFixer(work_dir)
self.pr_generator = PRGenerator(self.api, username)
self.results_dir = work_dir / "results"
self.results_dir.mkdir(exist_ok=True)
self.processed_file = work_dir / "processed.json"
self.processed = self._load_processed()
self.logger = logging.getLogger(__name__)
def run_batch(self, target_pr_count: int = 10, max_parallel: int = 3) -> Dict:
"""批量运行"""
self.logger.info("=" * 70)
self.logger.info(f"开始批量任务处理,目标: {target_pr_count} 个 PR")
self.logger.info("=" * 70)
results = {
"start_time": datetime.now().isoformat(),
"target_pr_count": target_pr_count,
"tasks_found": 0,
"tasks_processed": 0,
"prs_created": 0,
"pr_urls": [],
"errors": [],
"task_results": []
}
try:
tasks = self.hunter.search_bounties(limit=target_pr_count * 3)
results["tasks_found"] = len(tasks)
self.logger.info(f"找到 {len(tasks)} 个任务")
tasks_to_process = [t for t in tasks if not self._is_processed(t)][:target_pr_count]
self.logger.info(f"将处理 {len(tasks_to_process)} 个任务")
for i, task in enumerate(tasks_to_process, 1):
try:
task_result = self._process_single_task(task, i)
results["task_results"].append(task_result)
results["tasks_processed"] += 1
if task_result.get("success"):
results["prs_created"] += 1
results["pr_urls"].append(task_result.get("pr_url"))
self._mark_processed(task)
self._save_intermediate_results(results)
except Exception as e:
self.logger.error(f"任务 {i} 处理失败: {e}")
results["errors"].append(f"任务 {i}: {str(e)}")
except Exception as e:
self.logger.error(f"批量处理失败: {e}")
results["errors"].append(str(e))
results["end_time"] = datetime.now().isoformat()
results["success_rate"] = results["prs_created"] / max(results["tasks_processed"], 1)
self._save_final_results(results)
return results
def _process_single_task(self, task: BountyTask, index: int) -> Dict:
"""处理单个任务"""
self.logger.info(f"\n{'=' * 70}")
self.logger.info(f"处理任务 #{index}: {task.title}")
self.logger.info(f"仓库: {task.repo_full_name}")
self.logger.info(f"{'=' * 70}")
result = {
"index": index,
"task": {
"title": task.title,
"number": task.number,
"url": task.url,
"repo_full_name": task.repo_full_name
},
"success": False,
"pr_url": None
}
task_dir = self.work_dir / f"task_{index}_{task.number}"
task_dir.mkdir(exist_ok=True)
try:
owner, repo = task.repo_full_name.split("/")
self.logger.info("步骤 1/7: Fork 仓库...")
if not self.api.fork_repo(owner, repo):
raise Exception("Fork 失败")
self.logger.info("等待 Fork 完成...")
fork_ready = False
for attempt in range(10):
time.sleep(3)
try:
check_url = f"https://api.github.com/repos/{self.username}/{repo}"
check_response = self.api.session.get(check_url)
if check_response.status_code == 200:
fork_ready = True
break
except:
pass
self.logger.info(f" 尝试 {attempt + 1}/10...")
if not fork_ready:
raise Exception("Fork 未在预期时间内完成")
self.logger.info("步骤 2/7: 克隆仓库...")
clone_path = task_dir / repo
if clone_path.exists():
shutil.rmtree(clone_path)
clone_url = f"git@github.com:{self.username}/{repo}.git"
subprocess.run(
["git", "clone", clone_url, str(clone_path)],
check=True,
capture_output=True,
timeout=120
)
self.logger.info("步骤 3/7: 获取贡献指南...")
contributing = self.api.get_contributing_guide(owner, repo)
self.logger.info("步骤 4/7: 创建分支...")
branch_name = f"fix/issue-{task.number}-{datetime.now().strftime('%Y%m%d%H%M%S')}"
subprocess.run(
["git", "checkout", "-b", branch_name],
cwd=str(clone_path),
check=True,
capture_output=True
)
self.logger.info("步骤 5/7: 分析并修复...")
success, fix_result = self.fixer.analyze_and_fix(task, clone_path)
if not success:
raise Exception("分析修复失败")
self.logger.info("步骤 6/7: 运行测试...")
test_result = self.fixer.run_tests(clone_path)
if not test_result["success"]:
self.logger.warning("测试未通过,尝试修复...")
self.logger.info("步骤 7/7: 提交并创建 PR...")
subprocess.run(
["git", "add", "-A"],
cwd=str(clone_path),
check=True,
capture_output=True
)
commit_msg = f"fix: {task.title[:60]} (#{task.number})"
subprocess.run(
["git", "commit", "-m", commit_msg],
cwd=str(clone_path),
check=True,
capture_output=True
)
subprocess.run(
["git", "push", "-u", "origin", branch_name],
cwd=str(clone_path),
check=True,
capture_output=True,
timeout=60
)
pr_title, pr_body = self.pr_generator.generate_pr_content(task, fix_result)
pr_url = self.api.create_pr(
owner, repo, pr_title, pr_body,
f"{self.username}:{branch_name}"
)
if pr_url:
result["success"] = True
result["pr_url"] = pr_url
self.logger.info(f"PR 创建成功: {pr_url}")
else:
result["error"] = "PR 创建失败"
except Exception as e:
self.logger.error(f"任务处理失败: {e}")
result["error"] = str(e)
task_result_file = task_dir / "result.json"
with open(task_result_file, 'w', encoding='utf-8') as f:
json.dump(result, f, indent=2, ensure_ascii=False, default=str)
return result
def _load_processed(self) -> Dict:
"""加载已处理任务"""
if self.processed_file.exists():
try:
return json.loads(self.processed_file.read_text())
except:
pass
return {"processed": []}
def _is_processed(self, task: BountyTask) -> bool:
"""检查是否已处理"""
key = f"{task.repo_full_name}#{task.number}"
return key in self.processed.get("processed", [])
def _mark_processed(self, task: BountyTask):
"""标记为已处理"""
key = f"{task.repo_full_name}#{task.number}"
if key not in self.processed["processed"]:
self.processed["processed"].append(key)
self.processed["processed"] = self.processed["processed"][-200:]
with open(self.processed_file, 'w') as f:
json.dump(self.processed, f, indent=2)
def _save_intermediate_results(self, results: Dict):
"""保存中间结果"""
result_file = self.results_dir / f"intermediate_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
with open(result_file, 'w', encoding='utf-8') as f:
json.dump(results, f, indent=2, ensure_ascii=False, default=str)
def _save_final_results(self, results: Dict):
"""保存最终结果"""
result_file = self.results_dir / f"final_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
with open(result_file, 'w', encoding='utf-8') as f:
json.dump(results, f, indent=2, ensure_ascii=False, default=str)
self.logger.info(f"\n结果已保存到: {result_file}")
def main():
parser = argparse.ArgumentParser(description="增强版 GitHub Bounty Agent")
parser.add_argument("--token", help="GitHub Token")
parser.add_argument("--username", help="GitHub 用户名")
parser.add_argument("--work-dir", default="./workspace", help="工作目录")
parser.add_argument("--target-pr-count", type=int, default=10, help="目标 PR 数量")
parser.add_argument("--max-parallel", type=int, default=3, help="最大并行数")
args = parser.parse_args()
token = args.token or os.getenv("GITHUB_TOKEN")
username = args.username or os.getenv("GITHUB_USERNAME", "robellliu-dev")
if not token:
print("错误: 需要提供 GitHub Token")
print("设置环境变量: export GITHUB_TOKEN='your_token'")
sys.exit(1)
agent = EnhancedBountyAgent(
token=token,
username=username,
work_dir=Path(args.work_dir)
)
results = agent.run_batch(
target_pr_count=args.target_pr_count,
max_parallel=args.max_parallel
)
print("\n" + "=" * 70)
print("处理完成")
print("=" * 70)
print(f"目标 PR 数: {results['target_pr_count']}")
print(f"实际 PR 数: {results['prs_created']}")
print(f"成功率: {results['success_rate'] * 100:.1f}%")
if results["pr_urls"]:
print("\n创建的 PR:")
for url in results["pr_urls"]:
print(f" - {url}")
if __name__ == "__main__":
main()