gitea
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitea (REST API)
Gitea (REST API)
Operate Gitea by sending HTTP requests to authenticated
by . This skill does NOT depend on any MCP server — every
operation is a direct call.
$GITEA_URL/api/v1/...$GITEA_TOKENcurlKeep this entry file small. Load only the reference pack the current turn needs.
通过向发送HTTP请求并使用认证来操作Gitea。本技能不依赖任何MCP服务器——所有操作都是直接的调用。
$GITEA_URL/api/v1/...$GITEA_TOKENcurl保持此入口文件简洁。仅加载当前任务所需的参考包。
Always-On Rules
始终生效的规则
- Forced forge routing. Before any forge work, run and parse the host. If the host is
git remote get-url origin, this skill does not apply — usegithub.com, including for internal GitHub organizations. For any other host, treat it as a Gitea candidate: deriveghas the probe base URL, runhttps://<host>, and use this skill only if HTTP 200 returns JSON with acurl -fsS --max-time 5 "https://<host>/api/v1/version"field. If the probe fails or times out, ask the user; do not guess another forge.version - Resolve +
$GITEA_URLfrom named env pairs, not from the user. Each instance is exported as$GITEA_TOKEN+GITEA_<ALIAS>_URL(e.g.GITEA_<ALIAS>_TOKEN+GITEA_ORGA_URL). CallGITEA_ORGA_TOKEN(defined in setup.md) to auto-pick the pair whose URL host matches the current repo'sgitea_auto; falls back to the unaliasedorigin/GITEA_URL, then to gitea-mcp legacyGITEA_TOKEN/GITEA_HOST, then asks the user.GITEA_ACCESS_TOKENis always the base URL without the$GITEA_URLsuffix./api - Send on every request. Never put the token in the query string (
Authorization: token $GITEA_TOKEN) — it would be logged.?token= - Prefer piped to
curl -sso results are easy to inspect. Always includejq(or-o /dev/null -w '%{http_code}\n') when verifying success on write/delete calls — Gitea returns success bodies on 2xx and a--fail-with-bodyerror envelope on 4xx/5xx.{ "message": "...", "url": "..." } - Respect destructiveness. Any against
DELETE,/branches,/contents,/releases, labels, milestones, packages, secrets, variables, or wiki pages is irreversible. State exactly what will be removed and confirm with the user unless explicitly authorized./tags - Pagination: most list endpoints take (default
?page=N&limit=M,page=1, server max usually 50). A few older endpoints acceptlimit=30as an alias. Loop pages until the response is empty orper_page=is absent.Link: rel="next" - (create/update file):
PUT /repos/{owner}/{repo}/contents/{path}must be base64-encoded. Omitcontentto create; pass the current fileshato update.sha - Endpoint responses are the resource directly — Gitea does not wrap them in . Errors come back with HTTP 4xx/5xx plus
{ success, data }.{ "message": "...", "url": "..." }
- 强制代码托管平台路由。在进行任何代码托管平台操作之前,运行并解析主机地址。如果主机是
git remote get-url origin,则本技能不适用——请使用github.com工具,包括针对内部GitHub组织的操作。对于其他任何主机,将其视为Gitea候选实例:推导gh作为探测基础URL,运行https://<host>,仅当返回HTTP 200状态码且响应JSON包含curl -fsS --max-time 5 "https://<host>/api/v1/version"字段时,才使用本技能。如果探测失败或超时,请询问用户;不要猜测其他代码托管平台。version - 从命名环境变量对中解析+
$GITEA_URL,而非向用户索要。每个实例以$GITEA_TOKEN+GITEA_<ALIAS>_URL的形式导出(例如GITEA_<ALIAS>_TOKEN+GITEA_ORGA_URL)。调用GITEA_ORGA_TOKEN(定义于setup.md)自动选择URL主机与当前仓库gitea_auto匹配的变量对;如果没有匹配项,则回退到未加别名的origin/GITEA_URL,再回退到gitea-mcp旧版的GITEA_TOKEN/GITEA_HOST,最后询问用户。GITEA_ACCESS_TOKEN始终是不带$GITEA_URL后缀的基础URL。/api - 每个请求都要发送。绝不要将令牌放在查询字符串中(
Authorization: token $GITEA_TOKEN)——这会被记录下来。?token= - 优先使用管道到
curl -s,以便于检查结果。在验证写入/删除操作是否成功时,始终包含jq(或-o /dev/null -w '%{http_code}\n')——Gitea在2xx状态码时返回成功响应体,在4xx/5xx状态码时返回包含--fail-with-body的错误包。{ "message": "...", "url": "..." } - 注意破坏性操作。任何针对、
/branches、/contents、/releases、标签、里程碑、包、密钥、变量或维基页面的/tags操作都是不可逆的。除非获得明确授权,否则要准确说明将删除的内容并与用户确认。DELETE - 分页处理:大多数列表端点支持参数(默认
?page=N&limit=M,page=1,服务器通常最大为50)。少数旧端点接受limit=30作为别名。循环获取页面,直到响应为空或不存在per_page=头部。Link: rel="next" - (创建/更新文件):
PUT /repos/{owner}/{repo}/contents/{path}必须经过base64编码。创建时省略content参数;更新时传入当前文件的sha值。sha - 端点响应直接返回资源——Gitea不会将其包装在中。错误会伴随HTTP 4xx/5xx状态码返回,同时包含
{ success, data }。{ "message": "...", "url": "..." }
Core Workflow
核心工作流程
Environment
环境配置
Credentials live in named pairs — + — one pair per Gitea instance. matches the current repo's host to one of the URLs and loads that pair into + . Full discovery order and inline helper code: setup.md.
GITEA_<ALIAS>_URLGITEA_<ALIAS>_TOKENgitea_autoorigin$GITEA_URL$GITEA_TOKENbash
undefined凭证以命名变量对的形式存在—— + ——每个Gitea实例对应一对。会将当前仓库的主机与其中一个URL匹配,并将对应的变量对加载到 + 中。完整的发现顺序和内联辅助代码:setup.md。
GITEA_<ALIAS>_URLGITEA_<ALIAS>_TOKENgitea_autoorigin$GITEA_URL$GITEA_TOKENbash
undefinedExample user-side ~/.bashrc:
用户端~/.bashrc示例:
export GITEA_ORGA_URL=https://git.orga.com GITEA_ORGA_TOKEN=...
export GITEA_ORGA_URL=https://git.orga.com GITEA_ORGA_TOKEN=...
export GITEA_ORGB_URL=https://git.orgb.local GITEA_ORGB_TOKEN=...
export GITEA_ORGB_URL=https://git.orgb.local GITEA_ORGB_TOKEN=...
export GITEA_URL=https://gitea.com GITEA_TOKEN=...
export GITEA_URL=https://gitea.com GITEA_TOKEN=...
Per-session bootstrap (define the helpers from setup.md or source them):
会话引导(定义setup.md中的辅助函数或直接引入):
gitea_list_aliases() { env | grep -oE '^GITEA_[A-Z0-9][A-Z0-9_]URL=' | sed -E 's/^GITEA(.+)URL=$/\1/' | sort -u; }
gitea_use() { local a="$1" u="GITEA${1}URL" t="GITEA${1}TOKEN" f="GITEA${1}_TOKEN_FILE"
[ -n "${!u:-}" ] || { echo "no $u" >&2; return 1; }
if [ -n "${!t:-}" ]; then GITEA_TOKEN="${!t}"
elif [ -n "${!f:-}" ] && [ -r "${!f}" ]; then GITEA_TOKEN="$(cat "${!f}")"
else echo "no $t or ${t}_FILE" >&2; return 1; fi
GITEA_URL="${!u}"; export GITEA_URL GITEA_TOKEN; }
gitea_auto() { local src o h a u uh
if [ -n "${GITEA_URL:-}" ]; then src="$GITEA_URL"
else o=$(git remote get-url origin 2>/dev/null) || o=""; src="$o"; fi
case "$src" in
git@:) h="${src#git@}"; h="${h%%:}";;
ssh://) h="${src#ssh://}"; h="${h#@}"; h="${h%%/}"; h="${h%%:}";;
http*://) h="${src#http://}"; h="${h%%/}"; h="${h%%:}";;
esac
if [ -n "${h:-}" ]; then
for a in $(gitea_list_aliases); do
u="GITEA_${a}_URL"; uh="${!u#http*://}"; uh="${uh%%/}"; uh="${uh%%:}"
[ "$h" = "$uh" ] && { gitea_use "$a"; return 0; }
done
fi
[ -n "${GITEA_URL:-}" ] && [ -n "${GITEA_TOKEN:-}" ] && { export GITEA_URL GITEA_TOKEN; return 0; }
[ -n "${GITEA_HOST:-}" ] && [ -n "${GITEA_ACCESS_TOKEN:-}" ] && {
GITEA_URL="$GITEA_HOST"; GITEA_TOKEN="$GITEA_ACCESS_TOKEN"; export GITEA_URL GITEA_TOKEN; return 0; }
return 1; }
gitea_auto || { echo "no Gitea credentials (set GITEA_<ALIAS>URL + GITEA<ALIAS>_TOKEN, or GITEA_URL + GITEA_TOKEN)" >&2; return 1; }
AUTH=(-H "Authorization: token $GITEA_TOKEN")
JSON=(-H 'Content-Type: application/json')
Two usage patterns:
- **Inside a repo**, no env set: `gitea_auto` parses `origin` and finds the alias whose `GITEA_<ALIAS>_URL` host matches.
- **Outside a repo, or targeting a different instance**: `export GITEA_URL=https://git.aaa.com` first, then `gitea_auto` will match `git.aaa.com` against the configured aliases and pull the right token. No need to remember which alias corresponds to which host.
Hard override: `gitea_use ORGA` activates the `ORGA` pair regardless of URL.gitea_list_aliases() { env | grep -oE '^GITEA_[A-Z0-9][A-Z0-9_]URL=' | sed -E 's/^GITEA(.+)URL=$/\1/' | sort -u; }
gitea_use() { local a="$1" u="GITEA${1}URL" t="GITEA${1}TOKEN" f="GITEA${1}_TOKEN_FILE"
[ -n "${!u:-}" ] || { echo "no $u" >&2; return 1; }
if [ -n "${!t:-}" ]; then GITEA_TOKEN="${!t}"
elif [ -n "${!f:-}" ] && [ -r "${!f}" ]; then GITEA_TOKEN="$(cat "${!f}")"
else echo "no $t or ${t}_FILE" >&2; return 1; fi
GITEA_URL="${!u}"; export GITEA_URL GITEA_TOKEN; }
gitea_auto() { local src o h a u uh
if [ -n "${GITEA_URL:-}" ]; then src="$GITEA_URL"
else o=$(git remote get-url origin 2>/dev/null) || o=""; src="$o"; fi
case "$src" in
git@:) h="${src#git@}"; h="${h%%:}";;
ssh://) h="${src#ssh://}"; h="${h#@}"; h="${h%%/}"; h="${h%%:}";;
http*://) h="${src#http://}"; h="${h%%/}"; h="${h%%:}";;
esac
if [ -n "${h:-}" ]; then
for a in $(gitea_list_aliases); do
u="GITEA_${a}_URL"; uh="${!u#http*://}"; uh="${uh%%/}"; uh="${uh%%:}"
[ "$h" = "$uh" ] && { gitea_use "$a"; return 0; }
done
fi
[ -n "${GITEA_URL:-}" ] && [ -n "${GITEA_TOKEN:-}" ] && { export GITEA_URL GITEA_TOKEN; return 0; }
[ -n "${GITEA_HOST:-}" ] && [ -n "${GITEA_ACCESS_TOKEN:-}" ] && {
GITEA_URL="$GITEA_HOST"; GITEA_TOKEN="$GITEA_ACCESS_TOKEN"; export GITEA_URL GITEA_TOKEN; return 0; }
return 1; }
gitea_auto || { echo "no Gitea credentials (set GITEA_<ALIAS>URL + GITEA<ALIAS>_TOKEN, or GITEA_URL + GITEA_TOKEN)" >&2; return 1; }
AUTH=(-H "Authorization: token $GITEA_TOKEN")
JSON=(-H 'Content-Type: application/json')
两种使用模式:
- **在仓库内**,未设置环境变量:`gitea_auto`解析`origin`并找到`GITEA_<ALIAS>_URL`主机匹配的别名。
- **在仓库外,或针对不同实例**:先执行`export GITEA_URL=https://git.aaa.com`,然后`gitea_auto`会将`git.aaa.com`与配置的别名匹配并获取正确的令牌。无需记住哪个别名对应哪个主机。
强制覆盖:`gitea_use ORGA`会激活`ORGA`对应的变量对,无论URL如何。gitea
helper
giteagitea
辅助函数
giteaAfter resolving env, source the wrapper from
setup.md. Every
example assumes it is in scope:
giteaapi-*.mdbash
gitea GET /version # health
gitea GET /user # token identity
gitea GET '/repos/foo/bar/issues?state=closed&limit=50' # list with query
gitea POST /repos/foo/bar/issues -d '{"title":"x"}' # write
gitea DELETE /repos/foo/bar/releases/42 # destructiveThe helper auto-injects , the auth header, and
; surfaces HTTP 4xx/5xx with the
envelope on stderr and returns 1; pretty-prints success
bodies via .
$GITEA_URL/api/v1Content-Type: application/json{message, url}jq解析完环境变量后,引入setup.md中的包装器。每个示例都假设该函数已在作用域内:
giteaapi-*.mdbash
gitea GET /version # 健康检查
gitea GET /user # 令牌身份验证
gitea GET '/repos/foo/bar/issues?state=closed&limit=50' # 带查询参数的列表查询
gitea POST /repos/foo/bar/issues -d '{"title":"x"}' # 写入操作
gitea DELETE /repos/foo/bar/releases/42 # 破坏性操作该辅助函数会自动注入、认证头和;在stderr输出HTTP 4xx/5xx状态码对应的错误包并返回1;通过格式化打印成功响应体。
$GITEA_URL/api/v1Content-Type: application/json{message, url}jqSingle issue create + comment (canonical write flow)
创建单个议题并添加评论(标准写入流程)
bash
ISSUE=$(gitea POST /repos/{owner}/{repo}/issues \
-d '{"title":"fix auth bug","body":"Steps to reproduce..."}') || return 1
NUM=$(echo "$ISSUE" | jq -r '.number')
gitea POST "/repos/{owner}/{repo}/issues/$NUM/comments" \
-d '{"body":"PR will land tomorrow"}'bash
ISSUE=$(gitea POST /repos/{owner}/{repo}/issues \
-d '{"title":"fix auth bug","body":"Steps to reproduce..."}') || return 1
NUM=$(echo "$ISSUE" | jq -r '.number')
gitea POST "/repos/{owner}/{repo}/issues/$NUM/comments" \
-d '{"body":"PR will land tomorrow"}'Reference Packs
参考包
Load only the pack that covers the task at hand. Each pack lists every
endpoint with method, path, key params, and a curl example.
- Env vars, auth, /api/v1/version probe, PAT scopes, pagination, error envelope, common gotchas.
references/setup.md - — ~23 operations Repos & forks, branches, tags, commits, repo tree, file contents (read / create / update / delete), releases.
references/api-repo.md - — issue + PR endpoints
references/api-issues-prs.md, comments, labels-on-issue; PRlist/get/create/update issues; review submit/dismiss.list/get/diff/files/status/reviews/create/update/close/merge/update-branch/add-reviewers - — labels, milestones, time tracking, wiki Repo & org labels (CRUD), milestones (CRUD), stopwatches + tracked time entries, wiki pages + revisions.
references/api-project.md - — users, orgs, search, notifications, version
references/api-discovery.md,/user,/user/orgs,/users/search,/orgs/{org}/teams/search,/repos/search, notifications list/get/mark-read,/repos/issues/search./version - — actions & packages Workflows + runs + jobs + logs, dispatch/cancel/rerun runs, repo/org Actions secrets + variables CRUD, packages list/versions/get/delete.
references/api-cicd.md
仅加载与当前任务相关的参考包。每个包都列出了所有端点的方法、路径、关键参数和curl示例。
- 环境变量、认证、/api/v1/version探测、PAT权限范围、分页、错误包、常见注意事项。
references/setup.md - — 约23项操作 仓库与复刻、分支、标签、提交、仓库目录、文件内容(读取/创建/更新/删除)、发布版本。
references/api-repo.md - — 议题 + PR端点 议题的列表/获取/创建/更新、评论、议题标签;PR的列表/获取/差异/文件/状态/评审/创建/更新/关闭/合并/更新分支/添加评审人;评审提交/驳回。
references/api-issues-prs.md - — 标签、里程碑、时间跟踪、维基 仓库与组织标签(增删改查)、里程碑(增删改查)、计时器 + 跟踪时间条目、维基页面 + 修订版本。
references/api-project.md - — 用户、组织、搜索、通知、版本
references/api-discovery.md、/user、/user/orgs、/users/search、/orgs/{org}/teams/search、/repos/search、通知列表/获取/标记已读、/repos/issues/search。/version - — Actions与包 工作流 + 运行实例 + 任务 + 日志、触发/取消/重新运行实例、仓库/组织Actions密钥 + 变量增删改查、包列表/版本/获取/删除。
references/api-cicd.md
Quick Routing
快速路由指引
- Connection refused, 401, 403, missing token, PAT scopes: .
references/setup.md - Clone / fork / create repo, read or commit a file, branch / tag, release: .
references/api-repo.md - File issues, comment, manage PRs, request/submit reviews, merge: .
references/api-issues-prs.md - Labels, milestones, time tracking, wiki pages: .
references/api-project.md - "Who am I", search repos/users/issues, org list, notifications: .
references/api-discovery.md - CI runs/workflows, secrets/variables, packages: .
references/api-cicd.md
- 连接被拒绝、401、403、令牌缺失、PAT权限范围问题:查看。
references/setup.md - 克隆/复刻/创建仓库、读取或提交文件、分支/标签、发布版本:查看。
references/api-repo.md - 创建议题、添加评论、管理PR、请求/提交评审、合并:查看。
references/api-issues-prs.md - 标签、里程碑、时间跟踪、维基页面:查看。
references/api-project.md - “我是谁”、搜索仓库/用户/议题、组织列表、通知:查看。
references/api-discovery.md - CI运行/工作流、密钥/变量、包:查看。
references/api-cicd.md
When to Use Another Forge
何时使用其他代码托管平台工具
- host is
git remote get-url origin-> usegithub.cominstead; this skill does not apply.gh - probe fails -> the host is probably not a Gitea instance. Ask the user; do not guess another forge.
/api/v1/version
- 的主机是
git remote get-url origin-> 改用github.com工具;本技能不适用。gh - 探测失败 -> 该主机可能不是Gitea实例。请询问用户;不要猜测其他代码托管平台。
/api/v1/version