2026-03-12 17:23:08 +08:00

145 lines
4.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: gitea
description: 统一 Gitea 总入口,支持 issue 查询、issue 拆单创建、git push 和 PR 基础操作,优先从当前仓库 origin 自动识别目标仓库。
---
# Gitea - 统一入口
> **定位**:这是 Gitea 总入口。适合“看 issue”“拆 issue”“把提交 push 上去”“给当前分支开 PR”“在 PR 里留言”这类场景。
>
> `issue` 和 `issue-drive` 继续保留:`issue` 负责只读查看,`issue-drive` 负责拆单和创建工单;`gitea` 负责统一路由和 push / PR 能力。
当用户调用 `/gitea``$gitea`,或自然语言要求“处理 Gitea / push / PR / issue”时按以下规则执行。
## 1. 先路由意图
先从用户输入里判断目标动作:
- 包含“看 / 查 / list / open / closed / #123 / issue”且没有“拆 / 建 / 提 / 创建工单”语义:走 `issue`
- 包含“拆 issue / 提 issue / 创建工单 / 沉淀问题”语义:走 `issue-drive`
- 包含“push / 推送 / tag 推上去 / 推当前分支”语义:走 push 流程
- 包含“PR / pull request / 拉请求 / 合并请求 / 评论 PR”语义走 PR 流程
如果一句话里同时包含多个动作,先按用户描述顺序执行;默认不要自作主张串更多步骤。
## 2. 环境变量
统一使用:
- `GITEA_TOKEN`:必需
- `GITEA_BASE_URL`:可选;当传 `owner/repo` 或当前仓库 `origin` 是 SSH 地址时推荐配置
如果缺少 `GITEA_TOKEN`,先提示用户配置后停止,不继续执行 API、push fallback 或 PR 操作。
## 3. Issue 路由
如果判定为只读 issue
- 直接执行 `issue` skill 的流程
- 保持它的输入规则:当前仓库自动识别、支持 `owner/repo`、支持完整仓库 URL、支持单条 issue 编号
- 不在 `gitea` 里重复抄写 `issue` 的长说明
如果判定为 issue 拆单 / 创建:
- 直接执行 `issue-drive` 的流程
- 先整理事实和证据,再创建 issue
- 创建时统一使用 `GITEA_TOKEN`
## 4. Push 流程
Push 一律先跑预检,再决定是否执行:
```bash
# Codex
python3 .codex/skills/gitea/scripts/push_gitea.py
# Claude Code
python3 .claude/skills/gitea/scripts/push_gitea.py
```
规则:
- 默认推当前分支到同名远端分支
- `ahead=0` 时直接告诉用户“没有可推送提交”
- `dirty=true` 时明确提示“只会推送已提交内容”
- 分支 diverged 时停止,不自动 rebase也不自动 force
- 只有用户明确要求“强推 / force push”时才带 `--force`
真正执行时:
```bash
# Codex
python3 .codex/skills/gitea/scripts/push_gitea.py --execute
# Claude Code
python3 .claude/skills/gitea/scripts/push_gitea.py --execute
```
若用户明确要求强推:
```bash
python3 .codex/skills/gitea/scripts/push_gitea.py --execute --force
```
执行策略:
- 先尝试 `git push origin branch:branch`
- 若远端鉴权失败,再使用 `GITEA_TOKEN``/api/v1/user` 获取登录名,构造一次性 HTTPS token URL 进行 fallback
- 不改写本地 `origin`
## 5. PR 流程
PR 只做三件事:`list``create``comment`
### 5.1 看 PR
```bash
# Codex
python3 .codex/skills/gitea/scripts/pr_gitea.py list --state=open --limit=20
```
### 5.2 开 PR
```bash
# Codex
python3 .codex/skills/gitea/scripts/pr_gitea.py create --base main --title "标题" --body "正文"
```
规则:
- `head` 默认当前分支
- `base` 默认远端默认分支;识别不到时再显式传 `--base`
- 如果当前分支还没推送到远端,脚本会先走 push 流程,再创建 PR
- v1 只支持同仓库 PR不处理 fork 间 PR
### 5.3 在 PR 里留言
```bash
# Codex
python3 .codex/skills/gitea/scripts/pr_gitea.py comment 12 --body "已完成回归"
```
规则:
- PR 评论走 issue comment API因为 Gitea PR 底层复用 issue 线程
## 6. 输出要求
- issue 查询:沿用 `issue` skill 的固定 Markdown 输出
- issue 创建:沿用 `issue-drive` 的创建结果输出
- push输出预检 JSON 或执行结果 JSON至少包含 `status``branch``ahead/behind`、是否执行、执行方式
- PR输出 PR 列表或单条创建 / 评论结果 JSON至少包含编号、标题、URL、状态
## 7. 用法示例
```bash
/gitea 看当前仓库 open issues
/gitea 查 issue 17
/gitea 把这个 bug 拆成两张 issue
/gitea push
/gitea 推送当前分支到远端
/gitea 给当前分支开 PR 到 main
/gitea 看当前仓库 open PR
/gitea 在 PR 12 留言:已完成回归
```