github-automation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub Automation

GitHub自动化

This Skill helps you manage GitHub operations using the
gh
CLI, including repositories, issues, pull requests, releases, and GitHub Actions workflows.
本Skill帮助你使用
gh
CLI管理GitHub操作,包括仓库、Issue、Pull Request(PR)、发布版本和GitHub Actions工作流。

Capabilities

功能特性

  • Repositories: Create, clone, fork, view, and manage repos
  • Issues: Create, list, view, close, comment, and label issues
  • Pull Requests: Create, review, merge, list, and comment on PRs
  • Releases: Create releases and manage tags
  • Workflows: View and manage GitHub Actions
  • Gists: Create and manage gists
  • Search: Search repos, issues, PRs, code, and users
  • 仓库管理:创建、克隆、复刻、查看和管理仓库
  • Issue处理:创建、列出、查看、关闭、评论和标记Issue
  • 拉取请求(PR):创建、评审、合并、列出和评论PR
  • 版本发布:创建发布版本并管理标签
  • 工作流:查看和管理GitHub Actions
  • Gist管理:创建和管理Gist
  • 搜索功能:搜索仓库、Issue、PR、代码和用户

Authentication

认证方式

The
GITHUB_TOKEN
environment variable is pre-configured. Verify with:
bash
gh auth status
GITHUB_TOKEN
环境变量已预先配置。可通过以下命令验证:
bash
gh auth status

Instructions

操作步骤

Phase 1: Understand the Request

阶段1:理解需求

  1. Clarify what GitHub operation the user needs
  2. Identify the target repository (if not specified, ask)
  3. Confirm any destructive operations before executing
  1. 明确用户需要执行的GitHub操作
  2. 确定目标仓库(若未指定,需询问用户)
  3. 执行破坏性操作前需先确认

Phase 2: Execute the Operation

阶段2:执行操作

Use
gh
CLI commands. Common patterns:
Repository Operations
bash
gh repo view <owner>/<repo>
gh repo clone <owner>/<repo>
gh repo create <name> --public/--private
gh repo list <owner>
Issue Operations
bash
gh issue list --repo <owner>/<repo>
gh issue create --repo <owner>/<repo> --title "Title" --body "Body"
gh issue view <number> --repo <owner>/<repo>
gh issue close <number> --repo <owner>/<repo>
gh issue comment <number> --repo <owner>/<repo> --body "Comment"
Pull Request Operations
bash
gh pr list --repo <owner>/<repo>
gh pr create --repo <owner>/<repo> --title "Title" --body "Body"
gh pr view <number> --repo <owner>/<repo>
gh pr merge <number> --repo <owner>/<repo>
gh pr review <number> --repo <owner>/<repo> --approve/--comment/--request-changes
gh pr checks <number> --repo <owner>/<repo>
Search Operations
bash
gh search repos <query>
gh search issues <query>
gh search prs <query>
gh search code <query>
GitHub Actions
bash
gh run list --repo <owner>/<repo>
gh run view <run-id> --repo <owner>/<repo>
gh workflow list --repo <owner>/<repo>
Releases
bash
gh release list --repo <owner>/<repo>
gh release create <tag> --repo <owner>/<repo> --title "Title" --notes "Notes"
使用
gh
CLI命令。常见命令示例:
仓库操作
bash
gh repo view <owner>/<repo>
gh repo clone <owner>/<repo>
gh repo create <name> --public/--private
gh repo list <owner>
Issue操作
bash
gh issue list --repo <owner>/<repo>
gh issue create --repo <owner>/<repo> --title "Title" --body "Body"
gh issue view <number> --repo <owner>/<repo>
gh issue close <number> --repo <owner>/<repo>
gh issue comment <number> --repo <owner>/<repo> --body "Comment"
拉取请求(PR)操作
bash
gh pr list --repo <owner>/<repo>
gh pr create --repo <owner>/<repo> --title "Title" --body "Body"
gh pr view <number> --repo <owner>/<repo>
gh pr merge <number> --repo <owner>/<repo>
gh pr review <number> --repo <owner>/<repo> --approve/--comment/--request-changes
gh pr checks <number> --repo <owner>/<repo>
搜索操作
bash
gh search repos <query>
gh search issues <query>
gh search prs <query>
gh search code <query>
GitHub Actions操作
bash
gh run list --repo <owner>/<repo>
gh run view <run-id> --repo <owner>/<repo>
gh workflow list --repo <owner>/<repo>
版本发布操作
bash
gh release list --repo <owner>/<repo>
gh release create <tag> --repo <owner>/<repo> --title "Title" --notes "Notes"

Guidelines

操作指南

  • Always specify
    --repo <owner>/<repo>
    when not in a cloned repository
  • For destructive operations (delete, close, merge), confirm with user first
  • Use
    --json
    flag when you need to parse output programmatically
  • Handle errors gracefully and suggest fixes
  • When creating issues/PRs, use clear titles and descriptive bodies
  • 若未在已克隆的仓库目录下,执行命令时需指定
    --repo <owner>/<repo>
    参数
  • 执行破坏性操作(删除、关闭、合并)前,需先征得用户确认
  • 若需以编程方式解析输出结果,使用
    --json
    参数
  • 优雅处理错误并给出修复建议
  • 创建Issue/PR时,使用清晰的标题和描述性内容

Phase 3: Report Results

阶段3:结果反馈

  • Summarize what was done
  • Provide relevant links (PR URLs, issue numbers, etc.)
  • Suggest next steps if applicable
  • 总结已执行的操作
  • 提供相关链接(PR地址、Issue编号等)
  • 若适用,给出后续操作建议

Output Format

输出格式

When listing items, format clearly:
#123 - Issue title (open/closed) - @author
#456 - PR title (open/merged/closed) - @author
When creating items, always report:
  • The created item's number/ID
  • Direct URL to the item
  • Any relevant status information
列出内容时,需清晰格式化:
#123 - Issue标题 (open/closed) - @作者
#456 - PR标题 (open/merged/closed) - @作者
创建内容后,需反馈以下信息:
  • 已创建内容的编号/ID
  • 内容的直接访问链接
  • 相关状态信息

Examples

示例

Create an issue:
bash
gh issue create --repo <owner>/<repo> --title "Bug: Login fails" --body "Steps to reproduce..."
List open PRs awaiting review:
bash
gh pr list --repo <owner>/<repo> --state open --search "review:required"
Get PR details as JSON:
bash
gh pr view <number> --repo <owner>/<repo> --json title,state,reviews,checks
创建Issue:
bash
gh issue create --repo <owner>/<repo> --title "Bug: Login fails" --body "Steps to reproduce..."
列出待评审的开放PR:
bash
gh pr list --repo <owner>/<repo> --state open --search "review:required"
以JSON格式获取PR详情:
bash
gh pr view <number> --repo <owner>/<repo> --json title,state,reviews,checks

Prerequisites

前置条件

This Skill requires the GitHub CLI (
gh
) to be installed and authenticated:
bash
gh auth status
If not authenticated, run:
bash
gh auth login
Alternatively, set the
GITHUB_TOKEN
environment variable with a personal access token.
Important: When using environment variables in commands with pipes, wrap the command in
bash -c '...'
to avoid variable substitution issues:
bash
bash -c 'gh pr view <number> --repo $OWNER/$REPO --json title,state' | jq '.title'
Without environment variables, the pipe is fine:
bash
gh pr view <number> --repo <owner>/<repo> --json title,state | jq '.title'
使用本Skill需预先安装并认证GitHub CLI (
gh
):
bash
gh auth status
若未完成认证,执行以下命令:
bash
gh auth login
或者,使用个人访问令牌设置
GITHUB_TOKEN
环境变量。
重要提示:在包含管道的命令中使用环境变量时,需将命令包裹在
bash -c '...'
中,以避免变量替换问题:
bash
bash -c 'gh pr view <number> --repo $OWNER/$REPO --json title,state' | jq '.title'
不使用环境变量时,管道可正常使用:
bash
gh pr view <number> --repo <owner>/<repo> --json title,state | jq '.title'