通过 RESTful API 集成 GitShip,实现自动化上传和仓库管理
所有 API 请求需要在 HTTP Header 中携带 Bearer Token 进行认证。Token 可以在用户仪表盘中创建 API 密钥获取。
Authorization: Bearer <your-api-token>
示例请求头:
GET /api/config HTTP/1.1
Host: your-domain.com
Authorization: Bearer gup_xxxxxxxxxxxxxxxxxxxx
Content-Type: application/json
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
file | File | 必填 | ZIP 格式的代码包文件 |
repoId | String | 必填 | 目标仓库 ID |
preview | Boolean | 可选 | 设为 true 时仅预览不上传,默认 false |
batchRepos | String | 可选 | 批量上传到多个仓库,逗号分隔仓库 ID |
commitMsg | String | 可选 | 自定义 Git 提交信息,默认自动生成 |
curl -X POST https://your-domain.com/api/upload \
-H "Authorization: Bearer gup_xxxxxxxxxx" \
-F "file=@my-project.zip" \
-F "repoId=repo_abc123" \
-F "commitMsg=feat: add new module"
{
"ok": true,
"url": "https://github.com/user/repo/commit/abc123",
"sha": "abc123def456",
"message": "上传成功",
"files": 12,
"size": 1024000
}
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| 无 | - | - | 使用 Token 自动获取对应用户的仓库列表 |
curl -X GET https://your-domain.com/api/config \
-H "Authorization: Bearer gup_xxxxxxxxxx"
{
"ok": true,
"repos": [
{
"id": "repo_abc123",
"name": "生产仓库",
"repo": "user/production-repo",
"branch": "main"
},
{
"id": "repo_def456",
"name": "测试仓库",
"repo": "user/test-repo",
"branch": "develop"
}
]
}
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
action | String | 必填 | 操作类型:add / update / delete |
repoId | String | 必填 | 仓库 ID(update/delete 时需要) |
name | String | 可选 | 仓库显示名称 |
repo | String | 可选 | GitHub 仓库路径,如 user/repo |
branch | String | 可选 | 目标分支,默认 main |
curl -X POST https://your-domain.com/api/config \
-H "Authorization: Bearer gup_xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"action":"add","name":"生产仓库","repo":"user/prod","branch":"main"}'
{
"ok": true,
"message": "仓库已添加",
"repo": {
"id": "repo_new001",
"name": "生产仓库",
"repo": "user/prod",
"branch": "main"
}
}
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
page | Number | 可选 | 页码,默认 1 |
limit | Number | 可选 | 每页条数,默认 20 |
curl -X GET "https://your-domain.com/api/history?page=1&limit=10" \
-H "Authorization: Bearer gup_xxxxxxxxxx"
{
"ok": true,
"records": [
{
"id": "hist_001",
"time": "2024-12-01T10:30:00Z",
"fileName": "project-v2.zip",
"fileCount": 15,
"size": 2048000,
"repo": "user/prod",
"branch": "main",
"status": "success",
"commitSha": "abc123"
}
],
"total": 42,
"page": 1,
"limit": 10
}
返回当前 Token 对应的用户信息、套餐和用量情况。无额外参数。
curl -X GET https://your-domain.com/api/auth/me \
-H "Authorization: Bearer gup_xxxxxxxxxx"
{
"ok": true,
"user": {
"id": "user_abc",
"username": "developer",
"brandName": "MyBrand",
"plan": "pro",
"email": "dev@example.com",
"createdAt": "2024-01-15T00:00:00Z"
}
}
返回当前用户的套餐信息、用量配额和到期时间。
curl -X GET https://your-domain.com/api/auth/plan \
-H "Authorization: Bearer gup_xxxxxxxxxx"
{
"ok": true,
"plan": {
"name": "专业版",
"type": "pro",
"uploadsLimit": 500,
"reposLimit": 20,
"maxZipSize": 52428800,
"expiresAt": "2025-01-15T00:00:00Z",
"usage": {
"uploads": 128,
"files": 1520,
"size": 104857600
}
}
}
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
name | String | 可选 | 密钥名称/备注,如 "CI/CD" 或 "自动化脚本" |
expiresIn | Number | 可选 | 有效期天数,默认 90 天 |
curl -X POST https://your-domain.com/api/auth/api-keys \
-H "Authorization: Bearer gup_xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"name":"CI/CD","expiresIn":180}'
{
"ok": true,
"key": {
"id": "key_abc123",
"name": "CI/CD",
"token": "gup_xxxxxxxxxxxxxxxxxxxx",
"createdAt": "2024-12-01T00:00:00Z",
"expiresAt": "2025-05-30T00:00:00Z"
},
"message": "请妥善保存此 Token,创建后将无法再次查看"
}
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| 无 | - | - | 使用当前 Token 关联的账号生成 GitHub OAuth 授权链接 |
curl -X GET https://your-domain.com/api/oauth/auth-url \
-H "Authorization: Bearer gup_xxxxxxxxxx"
{
"ok": true,
"url": "https://github.com/login/oauth/authorize?client_id=xxx&state=yyy&scope=repo",
"state": "random_state_string"
}
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
url | String | 必填 | Webhook 回调地址(HTTPS) |
events | Array | 可选 | 监听事件类型,如 ["upload"],默认监听所有 |
secret | String | 可选 | 签名密钥,用于验证回调来源 |
curl -X POST https://your-domain.com/api/webhook/create \
-H "Authorization: Bearer gup_xxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"url":"https://my-server.com/webhook","events":["upload"],"secret":"my_secret"}'
{
"ok": true,
"webhook": {
"id": "wh_abc123",
"url": "https://my-server.com/webhook",
"events": ["upload"],
"createdAt": "2024-12-01T00:00:00Z"
}
}
GitShip API 文档 · 如有疑问请联系管理员