关于 new-issue
根据对话内容起草并创建 GitHub Issue 的技能。可指定仓库或从当前 Git 项目检测仓库,并要求用户确认草稿后再提交。
主要功能
- 01检查 gh 身份验证和仓库可用性
- 02指定仓库或自动检测仓库
- 03生成英文 Issue 标题和描述
- 04展示草稿以供确认和修改
- 05创建 Issue 并报告其 URL
适用场景
- 01根据对话内容提交缺陷报告
- 02将功能请求整理为结构化 GitHub Issue
- 03向指定仓库提交 Issue
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ tenfyzhong/ skills-hub --skill new-issue安装后在 Claude Code 中输入/new-issue确认已加载。
详细介绍
新建 Issue 技能
根据当前对话上下文创建 GitHub Issue。
前置条件检查(必须先验证)
模式检测:检查用户是否指定了目标仓库。
| 用户输入 | 模式 | 是否需要 Git 仓库 |
|---|---|---|
https://github.com/owner/repo | 显式指定 | 否 |
owner/repo | 显式指定 | 否 |
| 未指定仓库 | 自动检测 | 是 |
始终必需:
# Check if gh CLI is available and authenticated
gh auth status
如果 gh 未通过身份验证 → “请先运行 gh auth login。”
仅限自动检测模式(未指定仓库):
# Check if in a git repository
git rev-parse --is-inside-work-tree
# Get repository info
gh repo view --json owner,name,url
如果不在 Git 仓库中且未指定目标 → “请指定目标仓库(例如 owner/repo 或 GitHub URL),或切换到 Git 项目目录。”
输入
用户可以通过以下短语触发此技能:
- “新建 Issue”
- “创建 Issue”
- “提交 Issue”
- “报告此 Bug”
- “提交功能请求”
可选:用户可以指定目标仓库:
- 完整 URL:
https://github.com/owner/repo - 简写:
owner/repo
Issue 的上下文来源包括:
- 当前对话历史
- 用户对问题/功能的描述
- 讨论过的代码片段或错误消息
- 提及的任何相关文件路径
工作流
步骤 1:确定目标仓库
情况 A:用户指定了仓库
解析用户输入,提取 owner/repo:
# From URL: https://github.com/owner/repo or https://github.com/owner/repo/...
# Extract: owner/repo
# From short form: owner/repo
# Use directly
# Validate the repository exists and is accessible
gh repo view "$TARGET_REPO" --json owner,name,url
如果未找到仓库或无权访问 → “未找到仓库 '$TARGET_REPO',或你无权访问。”
情况 B:从当前 Git 仓库自动检测
# Get repository info and check if it's a fork
gh repo view --json owner,name,isFork,parent,url
# If it's a fork, get parent (upstream) info
IS_FORK=$(gh repo view --json isFork -q '.isFork')
if [ "$IS_FORK" = "true" ]; then
UPSTREAM_OWNER=$(gh repo view --json parent -q '.parent.owner.login')
UPSTREAM_NAME=$(gh repo view --json parent -q '.parent.name')
TARGET_REPO="$UPSTREAM_OWNER/$UPSTREAM_NAME"
else
# Use current repo as target
TARGET_REPO=$(gh repo view --json owner,name -q '.owner.login + "/" + .name')
fi
步骤 2:分析上下文并生成 Issue 内容
根据对话上下文生成:
语言要求:
- Issue 标题和所有描述内容都必须使用英文。
- 如果对话使用其他语言,则翻译/概述为英文。
标题生成规则:
- 保持简洁(少于 80 个字符)
- 如果类型明确,以 Issue 类型前缀开头:
[Bug]、[Feature]、[Enhancement]、[Question] - 清晰描述核心问题/请求
- 适当时使用祈使语气
- 仅使用英文
描述生成:
根据适用情况,使用以下章节组织描述:
## Description
[Clear explanation of the issue/feature request]
## Context
[Relevant background information from the conversation]
## Steps to Reproduce (for bugs)
1. [Step 1]
2. [Step 2]
3. [Expected vs Actual behavior]
## Proposed Solution (if discussed)
[Any solutions discussed in the conversation]
## Additional Information
- [Relevant code snippets]
- [Error messages]
- [Environment details if relevant]
步骤 3:向用户展示草稿以供审阅(关键)
必须使用 question 工具展示草稿并征求用户确认。
向用户展示生成的 Issue:
## Issue Draft
**Target Repository**: [TARGET_REPO]
**Title**: [Generated Title]
**Description**:
[Generated Description]
---
Please review the above issue draft.
使用 question 工具提问:
Options:
1. "Submit as-is" - Create the issue with current content
2. "Modify title" - Change the issue title
3. "Modify description" - Change the issue description
4. "Cancel" - Do not create the issue
步骤 4:处理用户修改
如果用户选择修改:
修改标题:
- 询问用户新标题
- 更新并展示修订后的草稿
- 返回步骤 3 进行确认
修改描述:
- 询问用户希望进行哪些更改
- 用户可以提供:
- 要添加/删除/更改的具体文本
- “缩短一些”或“补充关于 X 的更多细节”等常规指示
- 更新并展示修订后的草稿
- 返回步骤 3 进行确认
循环直到用户确认或取消。
步骤 5:创建 Issue
用户确认后,创建 Issue:
# Create issue on the target repository
gh issue create \
--repo "$TARGET_REPO" \
--title "$ISSUE_TITLE" \
--body "$ISSUE_BODY"
使用 HEREDOC 编写正文,以保留格式:
gh issue create --repo "$TARGET_REPO" --title "$ISSUE_TITLE" --body "$(cat <<'EOF'
## Description
[Description content here]
## Context
[Context content here]
EOF
)"
步骤 6:报告结果
Issue 创建后,提供:
# Get the created issue details
gh issue view --repo "$TARGET_REPO" <ISSUE_NUMBER> --json number,title,url,state
输出格式
Issue 创建成功
Issue:#[NUMBER] - [TITLE] 仓库:[TARGET_REPO] URL:[ISSUE_URL]
摘要
[简要确认已提交的内容]
错误处理
| 情况 | 操作 |
|---|---|
| 未提供上下文 | 请用户描述要创建的 Issue |
| 用户取消 | “Issue 创建已取消。未创建任何 Issue。” |
| API 错误 | 报告错误并建议检查权限 |
| 触发速率限制 | 告知用户并建议稍后再试 |
| 无写入权限 | “你无权在 [REPO] 上创建 Issue。请先考虑 Fork 仓库。” |
| 未指定仓库且不在 Git 仓库中 | 请用户指定目标仓库或切换到 Git 项目目录 |
| 仓库格式无效 | “仓库格式无效。请使用 'owner/repo' 或完整的 GitHub URL。” |
常见错误
- 使用非英语生成标题或描述
- 创建议题前未征求用户明确确认
- 在议题正文中包含机密或敏感数据
重要说明
- 务必确认:未经用户明确确认,绝不创建议题
- 保留上下文:在议题中包含相关对话上下文
- 灵活指定目标:接受明确指定的仓库(URL 或 owner/repo),或从 git 自动检测
- 注意 Fork:自动检测时,Fork 应以上游仓库为目标
- 格式:在议题正文中使用正确的 Markdown 格式
- 隐私:不要在议题中包含敏感信息(API 密钥、密码等)
- 反复修改:提交前允许多轮修改
评论
支持 Markdown