6.4 KiB
6.4 KiB
| name | description |
|---|---|
| issue | 查看当前仓库或任意 Gitea 仓库的 issue 列表和单条详情,支持自动识别 git origin、用户指定仓库、状态筛选和格式化输出。 |
Issue - 通用 Gitea Issue 查看
定位:这是只读 skill。用于查看当前仓库或指定仓库的 issue 列表、单条详情和评论,不负责拆单、创建工单、push 或 PR。
如果用户要做的是“把问题拆成 issue 并实际创建工单”,改用
issue-drive。如果用户想用统一入口处理 Gitea 相关任务,改用gitea。
当用户调用 /issue、$issue,或自然语言要求“查看当前仓库 issue”“看某个 Gitea 仓库的 issue”“查 issue #17”时,执行以下步骤。
1. 解析输入
支持以下几种目标仓库写法:
- 不传仓库参数:默认使用当前项目的
git remote get-url origin - 完整仓库 URL:
https://git.example.com/owner/repo - 仓库简写:
owner/repo - 当前仓库 + 单条 issue:
/issue 17 - 指定仓库 + 单条 issue:
/issue owner/repo 17或/issue https://git.example.com/owner/repo 17
同时支持:
--state=open|closed|all,默认open--limit=<N>,默认50
解析规则:
- 第二个位置参数如果是纯数字,视为
issue-number,进入详情模式 - 如果第一个位置参数是纯数字,则视为“当前仓库的 issue 编号”
owner/repo这种简写依赖GITEA_BASE_URL- 如果没有显式仓库参数,就读取当前仓库的
origin
规范化仓库目标时,接受以下输入:
https://host[/prefix]/owner/repogit@host:owner/repo.gitgit@host:prefix/owner/repo.gitssh://git@host/owner/repo.gitowner/repo
提取结果必须包含:
origin:例如https://git.example.com,如果 Gitea 部署在子路径下,保留前缀,例如https://git.example.com/giteaownerreporepo_path:owner/repo
如果无法从参数或当前仓库推断出目标仓库,明确提示:
❌ 无法确定目标仓库
请显式传入:
/issue https://git.example.com/owner/repo
或先配置:
export GITEA_BASE_URL=https://git.example.com
2. 检查环境变量
先读取环境变量:
GITEA_TOKEN:必需,读取 issue 时使用GITEA_BASE_URL:可选;当仓库参数是owner/repo,或当前仓库origin是 SSH 地址时推荐配置
如果缺少 GITEA_TOKEN,输出:
❌ 缺少 GITEA_TOKEN
请先在当前 shell 或 .env 中配置:
export GITEA_TOKEN=your_gitea_token
然后停止,不继续请求 API。
3. 解析当前仓库 origin
当没有显式传仓库参数时,执行:
git remote get-url origin
处理规则:
- 如果是
https://host[/prefix]/owner/repo(.git),直接使用 - 如果是
git@host:owner/repo(.git)或ssh://git@host/owner/repo(.git):- 优先用
GITEA_BASE_URL作为 API/Web 基地址 - 否则退回
https://host
- 优先用
- 如果当前目录不是 git 仓库,或没有
origin,停止并提示用户显式传仓库
不要为了查 issue 再向用户追问仓库 URL;只有在当前项目和参数都无法推断时才提示。
4. 调用 Gitea API
不要调用仓库元信息接口,避免依赖额外 scope。仓库标题直接使用 repo_path。
4.1 列表模式
请求:
curl -sS -o /tmp/gitea_issues.json -w "%{http_code}" \
-H "Authorization: token ${GITEA_TOKEN}" \
"${origin}/api/v1/repos/${owner}/${repo}/issues?state=${state}&limit=${limit}"
4.2 详情模式
先请求 issue 详情:
curl -sS -o /tmp/gitea_issue_detail.json -w "%{http_code}" \
-H "Authorization: token ${GITEA_TOKEN}" \
"${origin}/api/v1/repos/${owner}/${repo}/issues/${issue_number}"
再请求评论:
curl -sS -o /tmp/gitea_issue_comments.json -w "%{http_code}" \
-H "Authorization: token ${GITEA_TOKEN}" \
"${origin}/api/v1/repos/${owner}/${repo}/issues/${issue_number}/comments"
4.3 错误处理
根据 HTTP 状态码给出简短、直接的提示:
401:GITEA_TOKEN无效或未生效403:token scope 不足,或当前用户无权访问该仓库 / issue404:仓库不存在,或该 issue 编号不存在- 其他非
2xx:输出状态码和响应中的message
如果列表接口返回项里存在 pull_request 且非空,排除这些项,只保留 issue。
5. 格式化输出
优先使用 jq 解析 JSON;如果环境没有 jq,再退回模型手工整理,但输出结构保持一致。
5.1 列表模式
输出结构固定为:
📋 {repo_path} Issues
状态: {state} | 数量: {count} | 限制: {limit}
| # | 标题 | 优先级 | 标签 | 状态 | 提出人 |
|---|------|--------|------|------|--------|
| 35 | 小红书笔记状态查询 | P:紧急 | P:紧急, 需求 | open | zhangsan |
字段规则:
优先级:从 labels 中提取首个匹配^P[::]的 label,没有则填-标签:保留全部 label 原文,用,连接;没有则填-提出人:优先显示user.full_name,没有则显示user.login状态:直接显示open或closed
如果过滤后没有任何 issue,明确输出“无符合条件的 issue”。
5.2 详情模式
输出结构固定为:
## #{number} {title}
- 仓库: {repo_path}
- 状态: {state}
- 标签: {labels}
- 提出人: {author}
- 创建时间: {created_at}
- 更新时间: {updated_at}
### 正文
{body 或 “无正文”}
### 评论
- {author} | {created_at} | {1-2 句摘要}
规则:
- 正文为空时写“无正文”
- 评论按时间顺序输出
- 每条评论只保留 1 到 2 句摘要;不要整段照抄超长评论
- 没有评论时明确写“无评论”
6. 行为边界
- 默认只做列表和单条详情,不主动做主题归纳、epic 合并、优先级建议
- 用户后续如果要求摘要、优先级排序、相似 issue 合并,再基于已拉取的数据继续分析
- 不要求用户额外配置固定仓库 URL;优先从当前项目推断
- 当前仓库 origin 与 Web 域名不一致时,再使用
GITEA_BASE_URL
7. 用法示例
/issue
/issue 17
/issue owner/repo
/issue owner/repo --state=all --limit=20
/issue https://git.example.com/owner/repo
/issue https://git.example.com/owner/repo 17
$issue
$issue 17
$issue owner/repo
$issue owner/repo --state=all --limit=20
$issue https://git.example.com/owner/repo
$issue https://git.example.com/owner/repo 17