-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.py
More file actions
executable file
·170 lines (135 loc) · 5.16 KB
/
Copy pathdemo.py
File metadata and controls
executable file
·170 lines (135 loc) · 5.16 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
#!/usr/bin/env python3
"""
演示GitHub Bounty Agent的完整工作流程
"""
import os
import sys
from pathlib import Path
# 添加项目路径
sys.path.insert(0, str(Path(__file__).parent))
def demo_workflow():
"""演示完整工作流程"""
print("=" * 70)
print("🤖 GitHub Bounty Agent - 完整流程演示")
print("=" * 70)
# 1. 导入模块
print("\n📦 步骤1: 导入模块")
print(" from opencode_agent import OpenCodeBountyAgent")
try:
from opencode_agent import OpenCodeBountyAgent
print(" ✅ 模块导入成功")
except Exception as e:
print(f" ❌ 模块导入失败: {e}")
return False
# 2. 设置环境变量(演示模式)
print("\n⚙️ 步骤2: 配置环境")
print(" 设置 GITHUB_TOKEN 和 GITHUB_USERNAME")
if not os.getenv("GITHUB_TOKEN"):
print(" ℹ️ 使用演示Token(仅用于测试)")
os.environ["GITHUB_TOKEN"] = "demo_token"
if not os.getenv("GITHUB_USERNAME"):
print(" ℹ️ 使用演示用户名")
os.environ["GITHUB_USERNAME"] = "demo_user"
print(" ✅ 环境配置完成")
# 3. 创建Agent实例
print("\n🤖 步骤3: 创建Agent实例")
try:
agent = OpenCodeBountyAgent()
print(" ✅ Agent创建成功")
print(f" 用户名: {agent.username}")
print(f" 工作目录: {agent.work_dir}")
except Exception as e:
print(f" ❌ Agent创建失败: {e}")
return False
# 4. 查找赏金任务
print("\n🔍 步骤4: 查找赏金任务")
try:
tasks = agent.find_bounty_tasks(languages=["python", "javascript"], limit=5)
print(f" ✅ 找到 {len(tasks)} 个任务")
for i, task in enumerate(tasks[:3], 1):
print(f" {i}. {task['title']}")
except Exception as e:
print(f" ❌ 查找任务失败: {e}")
return False
# 5. 分析任务
print("\n🔬 步骤5: 分析任务详情")
if tasks:
try:
task = tasks[0]
print(f" 分析任务: {task['title']}")
# 这里只是演示,不实际调用API
print(" ✅ 分析完成(演示模式)")
except Exception as e:
print(f" ❌ 分析失败: {e}")
# 6. 生成解决方案
print("\n💡 步骤6: 生成解决方案")
print(" 基于任务分析生成实施方案")
print(" ✅ 解决方案已生成")
# 7. Fork和克隆(演示)
print("\n🍴 步骤7: Fork并克隆仓库")
print(" 演示模式:跳过实际Fork和克隆")
print(" ✅ 仓库准备完成")
# 8. 实现代码(演示)
print("\n⚙️ 步骤8: 实现代码修改")
print(" 根据解决方案实现功能")
print(" ✅ 代码实现完成")
# 9. 运行测试(演示)
print("\n🧪 步骤9: 运行测试")
print(" 验证代码正确性")
print(" ✅ 测试通过")
# 10. 提交代码(演示)
print("\n📤 步骤10: 提交并推送代码")
print(" 提交到Fork的仓库")
print(" ✅ 代码已推送")
# 11. 创建PR(演示)
print("\n🎯 步骤11: 创建Pull Request")
print(" 提交PR到原始仓库")
print(" ✅ PR已创建")
# 12. 检查PR状态(演示)
print("\n📊 步骤12: 检查PR状态")
print(" 监控PR进度")
print(" ✅ PR状态正常")
# 总结
print("\n" + "=" * 70)
print("✅ 工作流程演示完成!")
print("=" * 70)
print("\n📝 使用真实GitHub Token可以执行完整流程:")
print(" export GITHUB_TOKEN='your_token'")
print(" export GITHUB_USERNAME='your_username'")
print(" python3 opencode_agent.py --action process --auto")
print("\n🚀 Agent已准备好在OpenCode中使用!")
return True
def show_usage():
"""显示使用说明"""
print("\n" + "=" * 70)
print("📖 GitHub Bounty Agent - 使用指南")
print("=" * 70)
print("\n🔧 方式1: 命令行模式")
print(" 查找任务:")
print(" $ python3 opencode_agent.py --action find --languages python")
print("\n 处理任务:")
print(" $ python3 opencode_agent.py --action process --auto")
print("\n🔧 方式2: Python代码调用")
print(" from opencode_agent import OpenCodeBountyAgent")
print(" agent = OpenCodeBountyAgent()")
print(" result = agent.process_bounty(languages=['python'])")
print("\n🔧 方式3: 在OpenCode中调用")
print(" Agent会自动从环境变量读取配置")
print(" 可以直接作为OpenCode工具使用")
print("\n📚 更多信息请查看:")
print(" - README.md - 完整文档")
print(" - OPENCODE_AGENT.md - OpenCode集成指南")
print(" - SUMMARY.md - 项目总结")
def main():
"""主函数"""
print("\n")
# 演示工作流程
success = demo_workflow()
# 显示使用指南
show_usage()
print("\n" + "=" * 70)
print("✅ 演示结束")
print("=" * 70 + "\n")
return 0 if success else 1
if __name__ == "__main__":
sys.exit(main())