# API 文档
本文档介绍 Git Manage Service 的 HTTP API 接口。
# API 概览
- Base URL:
http://localhost:38080/api/v1 - Content-Type:
application/json - 认证方式: 无(内部服务)
# 通用响应格式
# 成功响应
{
"code": 0,
"message": "success",
"data": { ... }
}
1
2
3
4
5
2
3
4
5
# 错误响应
{
"code": 400,
"message": "错误描述",
"data": null
}
1
2
3
4
5
2
3
4
5
# HTTP 状态码
| 状态码 | 说明 |
|---|---|
| 200 | 成功 |
| 400 | 请求参数错误 |
| 404 | 资源不存在 |
| 500 | 服务器内部错误 |
# 仓库管理
# 获取仓库列表
GET /api/v1/repos
1
响应示例:
{
"code": 0,
"data": {
"repos": [
{
"id": 1,
"name": "my-project",
"path": "/home/git/repos/my-project",
"current_branch": "main",
"created_at": "2024-01-01T00:00:00Z"
}
],
"total": 1
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 获取仓库详情
GET /api/v1/repos/:id
1
路径参数:
| 参数 | 类型 | 说明 |
|---|---|---|
| id | int | 仓库 ID |
# 创建仓库(注册)
POST /api/v1/repos
1
请求体:
{
"name": "my-project",
"path": "/home/git/repos/my-project",
"ssh_key_id": 1
}
1
2
3
4
5
2
3
4
5
# 删除仓库
DELETE /api/v1/repos/:id
1
# 分支管理
# 获取分支列表
GET /api/v1/repos/:id/branches
1
查询参数:
| 参数 | 类型 | 说明 |
|---|---|---|
| type | string | 分支类型:local/remote/all |
响应示例:
{
"code": 0,
"data": {
"branches": [
{
"name": "main",
"type": "local",
"is_current": true,
"last_commit": "abc123"
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 切换分支
POST /api/v1/repos/:id/branches/checkout
1
请求体:
{
"branch": "develop"
}
1
2
3
2
3
# 创建分支
POST /api/v1/repos/:id/branches
1
请求体:
{
"name": "feature/new-feature",
"base_branch": "main"
}
1
2
3
4
2
3
4
# 删除分支
DELETE /api/v1/repos/:id/branches/:branch
1
# 同步任务
# 获取任务列表
GET /api/v1/sync/tasks
1
# 获取任务详情
GET /api/v1/sync/tasks/:id
1
# 创建同步任务
POST /api/v1/sync/tasks
1
请求体:
{
"name": "main-to-backup",
"repo_id": 1,
"source_remote": "origin",
"source_branch": "main",
"target_remote": "backup",
"target_branch": "main",
"cron_expression": "0 */2 * * *",
"enabled": true
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 执行同步任务
POST /api/v1/sync/tasks/:id/run
1
# 更新同步任务
PUT /api/v1/sync/tasks/:id
1
# 删除同步任务
DELETE /api/v1/sync/tasks/:id
1
# Webhook
# 触发同步
POST /api/webhooks/task-sync
1
请求头:
| Header | 说明 |
|---|---|
| Content-Type | application/json |
| X-Hub-Signature-256 | HMAC-SHA256 签名 |
请求体:
{
"task_id": 1
}
1
2
3
2
3
详见 Webhook 文档
# SSH 密钥
# 获取密钥列表
GET /api/v1/ssh-keys
1
# 创建密钥
POST /api/v1/ssh-keys
1
请求体:
{
"name": "github-deploy-key",
"type": "rsa",
"private_key": "-----BEGIN RSA PRIVATE KEY-----\n...",
"description": "用于访问 GitHub 仓库"
}
1
2
3
4
5
6
2
3
4
5
6
# 删除密钥
DELETE /api/v1/ssh-keys/:id
1
# 测试密钥
POST /api/v1/ssh-keys/:id/test
1
请求体:
{
"repo_url": "git@github.com:org/repo.git"
}
1
2
3
2
3
# 通知渠道
# 获取渠道列表
GET /api/v1/notification/channels
1
# 创建通知渠道
POST /api/v1/notification/channels
1
请求体:
{
"type": "dingtalk",
"name": "开发群通知",
"config": {
"webhook": "https://oapi.dingtalk.com/robot/send?access_token=xxx",
"secret": "SECxxx"
},
"events": ["sync_success", "sync_failure"],
"template": "【同步状态】任务: 任务标识"
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 测试通知
POST /api/v1/notification/channels/:id/test
1
# 审计日志
# 获取日志列表
GET /api/v1/audit/logs
1
查询参数:
| 参数 | 类型 | 说明 |
|---|---|---|
| type | string | 操作类型 |
| object_type | string | 对象类型 |
| start_time | string | 开始时间 |
| end_time | string | 结束时间 |
| page | int | 页码 |
| page_size | int | 每页数量 |
# 系统信息
# 健康检查
GET /api/health
1
响应示例:
{
"status": "ok"
}
1
2
3
2
3
# 获取版本信息
GET /api/v1/system/version
1
响应示例:
{
"code": 0,
"data": {
"version": "v0.7.2",
"build_time": "2024-01-01T00:00:00Z",
"git_commit": "abc123"
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 错误码
| 错误码 | 说明 |
|---|---|
| 0 | 成功 |
| 400 | 请求参数错误 |
| 401 | 未授权 |
| 403 | 禁止访问 |
| 404 | 资源不存在 |
| 409 | 资源冲突 |
| 500 | 服务器内部错误 |
# 分页
列表接口支持分页:
GET /api/v1/repos?page=1&page_size=20
1
响应格式:
{
"code": 0,
"data": {
"items": [...],
"total": 100,
"page": 1,
"page_size": 20
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# 下一步
- Webhook 集成 - 外部触发同步
- 配置参考 - 服务配置
← 配置参考