-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_agent.py
More file actions
129 lines (96 loc) · 3.56 KB
/
Copy pathrun_agent.py
File metadata and controls
129 lines (96 loc) · 3.56 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
#!/usr/bin/env python3
"""
主入口脚本 - 运行 Bounty Agent
支持本地运行和 CI/CD 环境
"""
import os
import sys
import json
import subprocess
from pathlib import Path
from datetime import datetime
def check_environment():
"""检查环境"""
print("=" * 70)
print("环境检查")
print("=" * 70)
token = os.getenv("GITHUB_TOKEN")
username = os.getenv("GITHUB_USERNAME")
if not token:
print("❌ 错误: 未设置 GITHUB_TOKEN 环境变量")
return False, None, None
print(f"✅ GITHUB_TOKEN 已设置 ({len(token)} 字符)")
print(f"✅ GITHUB_USERNAME: {username or '未设置'}")
opencode_path = subprocess.run(
["which", "opencode"],
capture_output=True,
text=True
)
if opencode_path.returncode == 0:
print(f"✅ OpenCode CLI: {opencode_path.stdout.strip()}")
else:
print("⚠️ OpenCode CLI 未安装,将使用 fallback 模式")
return True, token, username
def setup_workspace(work_dir: Path):
"""设置工作目录"""
work_dir.mkdir(parents=True, exist_ok=True)
(work_dir / "results").mkdir(exist_ok=True)
(work_dir / "logs").mkdir(exist_ok=True)
print(f"✅ 工作目录: {work_dir.absolute()}")
def run_agent(token: str, username: str, work_dir: Path, target_pr_count: int = 10):
"""运行 Agent"""
print("\n" + "=" * 70)
print("启动 Bounty Agent")
print("=" * 70)
from opencode_bounty_agent import EnhancedBountyAgent
agent = EnhancedBountyAgent(
token=token,
username=username or "robellliu-dev",
work_dir=work_dir
)
results = agent.run_batch(
target_pr_count=target_pr_count,
max_parallel=3
)
return results
def main():
print("\n" + "=" * 70)
print("🤖 GitHub Bounty Agent - 自动化赏金任务处理")
print("=" * 70)
print(f"启动时间: {datetime.now().isoformat()}")
print()
ok, token, username = check_environment()
if not ok:
sys.exit(1)
work_dir = Path(os.getenv("WORK_DIR", "./workspace"))
setup_workspace(work_dir)
target_pr_count = int(os.getenv("TARGET_PR_COUNT", "10"))
try:
results = run_agent(token or "", username or "robellliu-dev", work_dir, target_pr_count)
print("\n" + "=" * 70)
print("📊 执行结果")
print("=" * 70)
print(f"目标 PR 数: {results.get('target_pr_count', 0)}")
print(f"找到任务数: {results.get('tasks_found', 0)}")
print(f"处理任务数: {results.get('tasks_processed', 0)}")
print(f"创建 PR 数: {results.get('prs_created', 0)}")
print(f"成功率: {results.get('success_rate', 0) * 100:.1f}%")
if results.get("pr_urls"):
print("\n创建的 PR:")
for url in results["pr_urls"]:
print(f" ✅ {url}")
if results.get("errors"):
print("\n错误列表:")
for error in results["errors"][:5]:
print(f" ❌ {error}")
result_file = work_dir / "results" / f"run_{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)
print(f"\n结果已保存到: {result_file}")
except Exception as e:
print(f"\n❌ 执行失败: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()