Initial commit: add all skills

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 17:48:53 +08:00
commit dea5db60d9
31 changed files with 3111 additions and 0 deletions

1
github-gh-skill/.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
* text=auto eol=lf

4
github-gh-skill/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
__pycache__/
*.py[cod]
.venv/
venv/

86
github-gh-skill/SKILL.md Normal file
View File

@@ -0,0 +1,86 @@
---
name: github-gh-skill
description: 使用 GitHub CLI`gh`处理认证、仓库、Issue、Pull Request、Actions、Release以及通过 JSON/JQ 调用 API 查询数据。适用于用户提到 `gh`、GitHub CLI、终端里的 GitHub、PR、Issue、Actions、Release或需要不打开浏览器直接获取 GitHub 数据的场景。
---
# GitHub CLIgh技能
## 何时启用
用户提到:`gh`、GitHub CLI、命令行操作 GitHub、PR/Issue/Release/Actions、或需要从终端拉取 GitHub 信息时,优先按本技能执行。
## 前置检查(一次性)
1. **检查 `gh` 是否已安装**:执行 `gh --version`
- 若命令不存在,**自动安装最新版**:根据系统包管理器执行安装(如 `apt install gh -y``yum install gh -y``brew install gh`)。
- 安装失败再**提示用户手动安装**(参考官网 <https://cli.github.com/>)。
2. 若需私有资源,执行 `gh auth status`;未登录则 `gh auth login`(非 CI 场景由用户完成交互)。
3. 需要脚本化检测时,运行跨平台脚本:`python scripts/check_gh.py`(或 `python3 ...`,仅需 Python 3.8+ 与标准库)。
## 高效原则(给 Agent
- **优先机器可读**:能用 `--json` 就用;需要筛选时用 `--jq`(避免解析人类表格输出)。
- **减少交互**:批量操作用 `--yes` / `-y`;需要合并且非交互时用环境变量或文档中的标志位(见 [reference.md](reference.md))。
- **先定目标再选子命令**issue / pr / repo / workflow / release / api —— 不要猜,缺参数时 `gh <cmd> --help`
- **API 兜底**`gh` 子命令缺能力时用 `gh api`,路径以官方 REST 为准。
## 模块索引(按场景跳转)
| 模块 | 内容 |
|------|------|
| A. 认证与上下文 | `gh auth`,默认仓库 |
| B. 仓库 | `gh repo clone/view/create` |
| C. Issue | `gh issue list/create/view/close` |
| D. PR | `gh pr list/create/view/diff/merge/checkout` |
| E. Actions | `gh run list/view/watch/rerun` |
| F. Release | `gh release list/create` |
| G. 高级 | `gh api`GraphQL |
**详细命令与模板**见 [reference.md](reference.md)。
## A. 认证与上下文
- 查看登录:`gh auth status`
- 设置默认仓库(减少重复 `-R`):在仓库目录内 `gh repo set-default`
## B. 仓库
- 克隆:`gh repo clone owner/name`
- 当前仓库信息JSON`gh repo view --json name,owner,url,defaultBranchRef`
## C. Issue
- 列表JSON`gh issue list --json number,title,state,author,labels`
- 创建:`gh issue create --title "..." --body "..."`
## D. Pull Request
- 列表:`gh pr list --json number,title,state,headRefName`
- 检出本地分支:`gh pr checkout <number>`
- 查看差异:`gh pr diff <number>`
## E. GitHub Actionsworkflow / run
- 运行列表:`gh run list --limit 20`
- 单次运行详情 + 日志:`gh run view <run-id> --log`
## F. Release 与标签
- 列表:`gh release list --limit 20`
- 创建(需明确 tag 与说明):`gh release create <tag> --notes "..."`
## G. `gh api`REST
- GET 示例:`gh api repos/{owner}/{repo}/issues --jq '.[0].title'`
- 占位符:`{owner}` `{repo}` 在已关联 git remote 时常可自动解析;不确定时显式传 `-R owner/repo`
## 错误处理
- **401/403**:检查 `gh auth status`、token 权限repo、workflow 等)。
- **未找到命令**:升级 `gh` 或改用 `gh api`
- **交互阻塞**CI/自动化中避免会打开编辑器的命令;为 `pr merge` 等加 `--merge`/`--squash`/`--rebase` 等非交互选项。
## 附加资源
- 完整命令表与 JSON 字段提示:[reference.md](reference.md)
- 环境检查脚本(模块化,中文注释;跨平台,仅标准库):[scripts/check_gh.py](scripts/check_gh.py)

View File

@@ -0,0 +1,95 @@
# gh 参考手册(渐进披露)
主说明见 [SKILL.md](SKILL.md)。此处补充常用命令与非交互参数。
## 全局
| 用途 | 示例 |
|------|------|
| 帮助 | `gh <command> --help` |
| 指定仓库 | `-R owner/repo` 或在仓库目录执行 |
| JSON 输出 | `--json field1,field2` |
| jq 过滤 | `--jq 'select(.state=="OPEN")'` |
## auth
```bash
gh auth status
gh auth login
gh auth token
```
## repo
```bash
gh repo view --json name,owner,url,description
gh repo clone owner/name
gh repo create name --public --source=. --remote=origin --push
```
## issue
```bash
gh issue list --state open --limit 50
gh issue list --json number,title,labels,assignees
gh issue view 123 --json body,author,comments
gh issue create --title "t" --body "b" --label bug
gh issue close 123
```
## pr
```bash
gh pr list --state open
gh pr view 42 --json title,body,commits,files
gh pr checkout 42
gh pr diff 42
gh pr merge 42 --squash --delete-branch
```
合并时若需避免编辑器:使用 `--title`/`--body` 与明确的合并策略标志。
## workflow / run
```bash
gh workflow list
gh run list --workflow "ci.yml" --limit 10
gh run view <run-id>
gh run watch <run-id>
gh run rerun <run-id>
```
## release
```bash
gh release list
gh release view v1.2.3
gh release create v1.2.3 ./dist/*.zip --notes "..."
```
## api
```bash
# GET
gh api user
# 带查询参数
gh api repos/{owner}/{repo}/pulls --paginate
# POST示例
gh api repos/{owner}/{repo}/issues -f title="x" -f body="y"
```
GraphQL 使用 `gh api graphql -f query='...'`(复杂查询优先查 GitHub 文档)。
## JSON 字段提示
不同子命令可用字段以 `gh <cmd> list --json` 的帮助为准。常见:
- `gh pr list --json`: `number,title,state,headRefName,baseRefName,author,url`
- `gh issue list --json`: `number,title,state,labels,assignees,author`
## CI 环境变量
- `GH_TOKEN`:非交互调用时常用(注意最小权限原则)。
- 具体行为以当前 `gh` 版本文档为准。

View File

@@ -0,0 +1,84 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
模块GitHub CLIgh跨平台环境检测脚本。
说明:跨平台单文件,仅依赖 Python 标准库;
供 Agent 或本地一键验证 gh 是否可用、版本与登录用户(不打印 token
"""
from __future__ import annotations
import shutil
import subprocess
import sys
# 区域:配置常量
GH_SKILL_PREFIX = "github-gh-skill:"
def resolve_gh_executable() -> str:
"""检测 gh 是否在 PATH 中,返回可执行路径。"""
path = shutil.which("gh")
if not path:
print("未找到 gh请先安装https://cli.github.com/", file=sys.stderr)
sys.exit(127)
return path
def get_gh_version_line(gh: str) -> str:
"""获取 gh --version 的首行输出。"""
proc = subprocess.run(
[gh, "--version"],
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
)
if proc.returncode != 0:
print("gh --version 执行失败", file=sys.stderr)
sys.exit(proc.returncode)
first = (proc.stdout or "").splitlines()
return first[0].strip() if first else ""
def get_github_login(gh: str) -> str | None:
"""
仅查询当前登录用户名gh api避免打印 gh auth status 中的 token 行。
未登录或失败时返回 None。
"""
proc = subprocess.run(
[gh, "api", "user", "--jq", ".login"],
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
)
if proc.returncode != 0:
return None
login = (proc.stdout or "").strip()
return login or None
def print_auth_summary(gh: str) -> None:
"""输出登录摘要或警告到 stderr。"""
login = get_github_login(gh)
if login:
print(f"{GH_SKILL_PREFIX} 已登录 GitHub 用户: {login}")
else:
print(
"WARNING: gh 未登录或 token 无效,请执行 gh auth login",
file=sys.stderr,
)
def main() -> None:
"""入口:路径、版本、登录状态(不泄露 token"""
gh_path = resolve_gh_executable()
print(f"{GH_SKILL_PREFIX} gh 路径: {gh_path}")
print(f"{GH_SKILL_PREFIX} {get_gh_version_line(gh_path)}")
print_auth_summary(gh_path)
if __name__ == "__main__":
main()