文件最后提交记录最后更新时间
3 个月前
4 个月前
3 个月前
4 个月前
README

AtomGit CLI (Python Version)

这是 AtomGit CLI 的 Python 版本实现,完全重写了原有的 Go 版本,保持所有功能不变。

功能特性

  • 认证管理 - 查看认证状态和令牌
  • 仓库管理 - 列出、查看、创建、克隆、派生、删除仓库
  • Pull Request 管理 - 列出、查看、创建、关闭、编辑 PR 及评论操作
  • Issue 管理 - 列出、查看、创建、关闭议题及评论操作
  • 许可证合规 - 检查许可证合规性
  • SSH 密钥管理 - 添加 SSH 密钥到账户
  • 标签管理 - 创建、列出、删除 Git 标签

安装

从源码安装

cd scripts_python
pip install -e .

安装依赖

pip install -r requirements.txt

配置

在使用之前,需要配置访问令牌。创建 token 文件:

推荐方式:遵循 XDG 规范

$XDG_CONFIG_HOME/ag-cli/token.json

默认路径为 ~/.config/ag-cli/token.json

兼容旧方式的路径

~/.atomgit_personal_token.json

文件内容:

{
  "access_token": "your-token-here",
  "user": "your-username"
}

使用方法

查看帮助

ag --help

认证

# 查看认证状态
ag auth status

# 显示当前 token
ag auth token

仓库管理

# 列出仓库
ag repo list

# 查看仓库详情
ag repo view owner/repo

# 创建仓库
ag repo create my-project --public --description "My project"

# 克隆仓库
ag repo clone owner/repo

# Fork 仓库
ag repo fork owner/repo --name my-fork --public

# 删除仓库
ag repo delete owner/repo --yes

Pull Request 管理

# 列出 PR
ag pr list owner/repo
ag pr list owner/repo --state closed

# 查看 PR
ag pr view owner/repo 123

# 创建 PR
ag pr create owner/repo --title "Fix bug" --body "Description" --base master --head feature-branch

# 关闭 PR
ag pr close owner/repo 123

# PR 评论
ag pr comment create owner/repo 123 --body "LGTM!"
ag pr comment view owner/repo 123

Issue 管理

# 列出 Issue
ag issue list owner/repo
ag issue list owner/repo --state all

# 查看 Issue
ag issue view owner/repo 42

# 创建 Issue
ag issue create owner/repo --title "Bug report" --body "Description"

# 关闭 Issue
ag issue close owner/repo 42

# Issue 评论
ag issue comment create owner/repo 42 --body "I can reproduce this issue"
ag issue comment view owner/repo 42

标签管理

# 列出标签
ag tag list owner/repo

# 创建标签
ag tag create owner/repo v1.0.0 --message "Release version 1.0.0" --ref main

# 删除标签
ag tag delete owner/repo v1.0.0

SSH 密钥管理

# 添加 SSH key
ag ssh-key add ~/.ssh/id_rsa.pub --title "My Laptop"

许可证合规检查

# 检查许可证
ag license check MIT
ag license check Apache-2.0

项目结构

scripts_python/
├── ag_cli/
│   ├── api/
│   │   ├── __init__.py
│   │   ├── client.py          # API 客户端
│   │   └── types.py           # 数据类型定义
│   ├── config/
│   │   ├── __init__.py
│   │   └── config.py          # 配置管理
│   ├── commands/
│   │   ├── __init__.py
│   │   ├── auth/              # 认证命令
│   │   ├── repo/              # 仓库命令
│   │   ├── pr/                # PR 命令
│   │   ├── issue/             # Issue 命令
│   │   ├── license/           # 许可证命令
│   │   ├── ssh_key/           # SSH 密钥命令
│   │   └── tag/               # 标签命令
│   ├── __init__.py
│   └── main.py                # 主入口
├── pyproject.toml             # 项目配置
├── requirements.txt           # 依赖列表
└── README.md                  # 本文件

技术栈

  • Python 3.8+ - 编程语言
  • Click - 命令行框架
  • Requests - HTTP 客户端
  • dataclasses - 数据类

与 Go 版本的对比

特性 Go 版本 Python 版本
语言 Go 1.24 Python 3.8+
CLI 框架 Cobra Click
HTTP 客户端 net/http requests
数据结构 struct dataclass
配置管理 自定义 自定义
功能完整性 100% 100%

开发

运行测试

pytest

代码格式化

black ag_cli/

代码检查

flake8 ag_cli/

API

使用 AtomGit API v5: https://api.atomgit.com/api/v5

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!