2.5 KiB
2.5 KiB
Gitea API 使用指南
Token 位置
~/.config/gitea/token
创建 Issue(工单)
步骤 1: 准备 JSON 文件(避免转义问题)
cat > /tmp/issue.json << 'EOF'
{
"title": "[API-REQ] 简要描述所需接口",
"body": "## 接口地址\n\nPUT /xxx/xxx\n\n## 功能描述\n\n描述需要什么功能\n\n## 期望行为\n\n1. ...\n2. ...\n\n## 当前问题\n\n- ...\n\n## 前端使用场景\n\n描述为什么需要这个接口\n\n## 优先级\n\n高/中/低"
}
EOF
步骤 2: 调用 Gitea API 创建 Issue
TOKEN=$(cat ~/.config/gitea/token)
curl -s -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
-d @/tmp/issue.json \
"https://git.dev.vifo.cc/api/v1/repos/{owner}/{repo}/issues"
示例(提交到 rui-framework 仓库):
TOKEN=$(cat ~/.config/gitea/token)
curl -s -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
-d @/tmp/issue.json \
"https://git.dev.vifo.cc/api/v1/repos/rui/rui-framework/issues"
返回示例:
{
"id": 7,
"number": 2,
"title": "[API-REQ] 用户编辑接口密码字段处理优化",
"html_url": "https://git.dev.vifo.cc/rui/rui-framework/issues/2",
"state": "open"
}
获取 Issue
TOKEN=$(cat ~/.config/gitea/token)
curl -s -H "Authorization: token ${TOKEN}" \
"https://git.dev.vifo.cc/api/v1/repos/{owner}/{repo}/issues/{id}"
回复 Issue 评论
TOKEN=$(cat ~/.config/gitea/token)
curl -s -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
-d '{"body": "✅ 已完成\n\n完成内容..."}' \
"https://git.dev.vifo.cc/api/v1/repos/{owner}/{repo}/issues/{id}/comments"
常用端点
| 操作 | 方法 | 端点 |
|---|---|---|
| 创建 Issue | POST | /api/v1/repos/{owner}/{repo}/issues |
| 获取 Issue | GET | /api/v1/repos/{owner}/{repo}/issues/{id} |
| 创建评论 | POST | /api/v1/repos/{owner}/{repo}/issues/{id}/comments |
| 获取仓库 | GET | /api/v1/repos/{owner}/{repo} |
Git 远程地址
gitea ssh://git@git.dev.vifo.cc:222/rui/{repo}.git
推送命令: git push gitea main(注意不是 origin)
注意事项
- JSON 内容: 建议使用文件方式(
-d @file.json)避免转义问题 - Labels: 创建 Issue 时 labels 参数需要传入 ID 数组,不是字符串数组
- 返回字段:
number是 Issue 编号,id是内部 ID - 仓库映射:
- rui-framework:
/system/*,/user/* - rui-cashier:
/cashier/*
- rui-framework: