-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathccloop.py
More file actions
65 lines (50 loc) · 2.03 KB
/
Copy pathccloop.py
File metadata and controls
65 lines (50 loc) · 2.03 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
#!/usr/bin/env python3
"""ccloop CLI 入口"""
import argparse
import subprocess
import sys
from ccloop_lib.config import GITHUB_TOKEN, CLAUDE_CMD, configure, setup_logging
from ccloop_lib.lock import acquire_lock, release_lock
from ccloop_lib import config
from ccloop_lib.solver import CCLoop
def main():
parser = argparse.ArgumentParser(description="ccloop - GitHub Issue 自动解决")
parser.add_argument("repo", help="GitHub 仓库 (owner/repo)")
parser.add_argument("--dry-run", action="store_true",
help="dry-run:CC 正常调用,不推送/建PR/评论")
parser.add_argument("--label", help="只处理特定 label")
parser.add_argument("--work-dir", help="工作目录(clone+运行CC),默认在 ccloop 同级目录")
parser.add_argument("--clean", action="store_true",
help="清理工作目录后退出(不执行其他操作)")
args = parser.parse_args()
configure(args.repo, work_dir=args.work_dir)
if args.clean:
from ccloop_lib.git_ops import GitOps
GitOps.clean(config.WORK_DIR)
return
if not GITHUB_TOKEN:
print("请设置 GITHUB_TOKEN 环境变量")
sys.exit(1)
try:
subprocess.run([CLAUDE_CMD, "--version"],
capture_output=True, check=True, timeout=10)
except (FileNotFoundError, subprocess.CalledProcessError):
print(f"未找到 claude CLI ({CLAUDE_CMD}),请先安装 Claude Code")
sys.exit(1)
if args.label:
config.ISSUE_LABEL = args.label
log = setup_logging()
if not acquire_lock(config.LOCK_FILE):
log.info(f"[{args.repo}] 另一个实例正在运行,退出")
sys.exit(0)
mode = "DRY-RUN" if args.dry_run else "LIVE"
log.info(f"启动 ccloop [{args.repo}] ({mode} 模式)")
try:
solver = CCLoop(dry_run=args.dry_run)
solver.run()
except KeyboardInterrupt:
log.info("用户中断")
finally:
release_lock(config.LOCK_FILE)
if __name__ == "__main__":
main()