基础网址:https://api.github.com
所有请求均需添加以下头部信息:-H "Authorization: token $GITHUB_TOKEN"
可使用 gh-env.sh 辅助工具自动设置 $GITHUB_TOKEN、$\GH_OWNER 和 $GH_REPO 的值:
source "${HERMES_HOME:-$HOME/.hermes}/skills/github/github-auth/scripts/gh-env.sh"
| 操作 | 方法 | 接口地址 |
| 获取仓库信息 | GET | /repos/{owner}/{repo} |
| 创建用户仓库 | POST | /user/repos |
| 创建组织仓库 | POST | /orgs/{org}/repos |
| 更新仓库 | PATCH | /repos/{owner}/{repo} |
| 删除仓库 | DELETE | /repos/{owner}/{repo} |
| 列出个人仓库 | GET | /user/repos?per_page=30&sort=updated |
| 列出组织仓库 | GET | /orgs/{org}/repos |
| 复制仓库 | POST | /repos/{owner}/{repo}/forks |
| 根据模板创建仓库 | POST | /repos/{owner}/{template}/generate |
| 获取标签 | GET | /repos/{owner}/{repo}/topics |
| 设置标签 | PUT | /repos/{owner}/{repo}/topics |
| 操作 | 方法 | 接口地址 |
| 列出合并请求 | GET | /repos/{owner}/{repo}/pulls?state=open |
| 创建合并请求 | POST | /repos/{owner}/{repo}/pulls |
| 获取合并请求详情 | GET | /repos/{owner}/{repo}/pulls/{number} |
| 更新合并请求 | PATCH | /repos/{owner}/{repo}/pulls/{number} |
| 列出合并请求中的文件 | GET | /repos/{owner}/{repo}/pulls/{number}/files |
| 合并合并请求 | PUT | /repos/{owner}/{repo}/pulls/{number}/merge |
| 请求审核人 | POST | /repos/{owner}/{repo}/pulls/{number}/requested_reviewers |
| 创建代码审查 | POST | /repos/{owner}/{repo}/pulls/{number}/reviews |
| 添加内联评论 | POST | /repos/{owner}/{repo}/pulls/{number}/comments |
{"merge_method": "squash", "commit_title": "feat: description (#N)"}
合并方式:"merge"、"squash"、"rebase"
"APPROVE"、"REQUEST_CHANGES"、"COMMENT"
| 操作 | 方法 | 接口地址 |
| 列出问题 | GET | /repos/{owner}/{repo}/issues?state=open |
| 创建问题 | POST | /repos/{owner}/{repo}/issues |
| 获取问题详情 | GET | /repos/{owner}/{repo}/issues/{number} |
| 更新问题 | PATCH | /repos/{owner}/{repo}/issues/{number} |
| 添加评论 | POST | /repos/{owner}/{repo}/issues/{number}/comments |
| 添加标签 | POST | /repos/{owner}/{repo}/issues/{number}/labels |
| 移除标签 | DELETE | /repos/{owner}/{repo}/issues/{number}/labels/{name} |
| 添加负责人 | POST | /repos/{owner}/{repo}/issues/{number}/assignees |
| 列出所有标签 | GET | /repos/{owner}/{repo}/labels |
| 搜索问题 | GET | /search/issues?q={query}+repo:{owner}/{repo} |
注意:Issues API 也会返回 PR 相关信息。解析数据时,请使用 "pull_request" not in item 进行过滤。
| 操作 | 方法 | 接口地址 |
| 列出工作流 | GET | /repos/{owner}/{repo}/actions/workflows |
| 列出运行记录 | GET | /repos/{owner}/{repo}/actions/runs?per_page=10 |
| 按分支列出运行记录 | GET | /repos/{owner}/{repo}/actions/runs?branch={branch} |
| 获取特定运行记录 | GET | /repos/{owner}/{repo}/actions/runs/{run_id} |
| 下载日志 | GET | /repos/{owner}/{repo}/actions/runs/{run_id}/logs |
| 重新运行 | POST | /repos/{owner}/{repo}/actions/runs/{run_id}/rerun |
| 重新运行失败的作业 | POST | /repos/{owner}/{repo}/actions/runs/{run_id}/rerun-failed-jobs |
| 触发任务分发 | POST | /repos/{owner}/{repo}/actions/workflows/{id}/dispatches |
| 获取提交状态 | GET | /repos/{owner}/{repo}/commits/{sha}/status |
| 检查提交对应的运行记录 | GET | /repos/{owner}/{repo}/commits/{sha}/check-runs |
| 操作 | 方法 | 接口地址 |
| 列出版本发布记录 | GET | /repos/{owner}/{repo}/releases |
| 创建版本发布 | POST | /repos/{owner}/{repo}/releases |
| 获取特定版本发布记录 | GET | /repos/{owner}/{repo}/releases/{id} |
| 删除版本发布记录 | DELETE | /repos/{owner}/{repo}/releases/{id} |
| 上传资源文件 | POST | https://uploads.github.com/repos/{owner}/{repo}/releases/{id}/assets?name={filename} |
| 操作 | 方法 | 端点 |
| 列出机密信息 | GET | /repos/{owner}/{repo}/actions/secrets |
| 获取公钥 | GET | /repos/{owner}/{repo}/actions/secrets/public-key |
| 设置机密信息 | PUT | /repos/{owner}/{repo}/actions/secrets/{name} |
| 删除机密信息 | DELETE | /repos/{owner}/{repo}/actions/secrets/{name} |
| 操作 | 方法 | 端点 |
| 获取分支保护规则 | GET | /repos/{owner}/{repo}/branches/{branch}/protection |
| 设置分支保护规则 | PUT | /repos/{owner}/{repo}/branches/{branch}/protection |
| 删除分支保护规则 | DELETE | /repos/{owner}/{repo}/branches/{branch}/protection |
| 操作 | 方法 | 端点 |
| 获取当前用户信息 | GET | /user |
| 列出用户拥有的仓库 | GET | /user/repos |
| 列出用户的 Gist 内容 | GET | /gists |
| 创建新 Gist | POST | /gists |
| 搜索仓库 | GET | /search/repositories?q={query} |
大多数列表类端点支持以下参数:
?per_page=100(每页最多 100 条记录)
?page=2 用于翻到下一页
| 可通过 Link 请求头中的 rel="next" 字段获取下一页地址 |
- 已认证用户:每小时 5,000 次请求
- 查询剩余请求次数:
curl -s -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/rate_limit
# GET
curl -s -H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$GH_OWNER/$GH_REPO
# POST with JSON body
curl -s -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$GH_OWNER/$GH_REPO/issues \
-d '{"title": "...", "body": "..."}'
# PATCH (update)
curl -s -X PATCH \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$GH_OWNER/$GH_REPO/issues/42 \
-d '{"state": "closed"}'
# DELETE
curl -s -X DELETE \
-H "Authorization: token $GITHUB_TOKEN" \
https://api.github.com/repos/$GH_OWNER/$GH_REPO/issues/42/labels/bug
# Parse JSON response with python3
curl -s ... | python3 -c "import sys,json; data=json.load(sys.stdin); print(data['field'])"