99 lines
2.5 KiB
Markdown
99 lines
2.5 KiB
Markdown
# Gitea API 使用指南
|
||
|
||
## Token 位置
|
||
|
||
```
|
||
~/.config/gitea/token
|
||
```
|
||
|
||
## 创建 Issue(工单)
|
||
|
||
**步骤 1**: 准备 JSON 文件(避免转义问题)
|
||
|
||
```bash
|
||
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
|
||
|
||
```bash
|
||
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 仓库):
|
||
|
||
```bash
|
||
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"
|
||
```
|
||
|
||
**返回示例**:
|
||
```json
|
||
{
|
||
"id": 7,
|
||
"number": 2,
|
||
"title": "[API-REQ] 用户编辑接口密码字段处理优化",
|
||
"html_url": "https://git.dev.vifo.cc/rui/rui-framework/issues/2",
|
||
"state": "open"
|
||
}
|
||
```
|
||
|
||
## 获取 Issue
|
||
|
||
```bash
|
||
TOKEN=$(cat ~/.config/gitea/token)
|
||
curl -s -H "Authorization: token ${TOKEN}" \
|
||
"https://git.dev.vifo.cc/api/v1/repos/{owner}/{repo}/issues/{id}"
|
||
```
|
||
|
||
## 回复 Issue 评论
|
||
|
||
```bash
|
||
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)
|
||
|
||
## 注意事项
|
||
|
||
1. **JSON 内容**: 建议使用文件方式(`-d @file.json`)避免转义问题
|
||
2. **Labels**: 创建 Issue 时 labels 参数需要传入 ID 数组,不是字符串数组
|
||
3. **返回字段**: `number` 是 Issue 编号,`id` 是内部 ID
|
||
4. **仓库映射**:
|
||
- rui-framework: `/system/*`, `/user/*`
|
||
- rui-cashier: `/cashier/*`
|