feat: 实现环境变量预设功能 & 移除稀疏检出

## 后端改动
- 添加 Project.envPresets 字段(JSON 格式)
- 移除 Deployment.env 字段,统一使用 envVars
- 更新部署 DTO,支持 envVars (Record<string, string>)
- pipeline-runner 支持解析并注入 envVars 到环境
- 移除稀疏检出模板和相关环境变量
- 优化代码格式(Biome lint & format)

## 前端改动
- 新增 EnvPresetsEditor 组件(支持单选/多选/输入框类型)
- 项目创建/编辑界面集成环境预设编辑器
- 部署界面基于预设动态生成环境变量表单
- 移除稀疏检出表单项
- 项目详情页添加环境变量预设配置 tab
- 优化部署界面布局(基本参数 & 环境变量分区)

## 文档
- 添加完整文档目录结构(docs/)
- 创建设计文档 design-0005(部署流程重构)
- 添加 API 文档、架构设计文档等

## 数据库
- 执行 prisma db push 同步 schema 变更
This commit is contained in:
2026-01-03 22:59:20 +08:00
parent c40532c757
commit d22fdc9618
71 changed files with 9611 additions and 5849 deletions

14
docs/api/README.md Normal file
View File

@@ -0,0 +1,14 @@
---
title: API 文档
summary: 本目录存放 OpenAPI 定义与 API 使用说明。
tags: [api]
owners:
- team: backend
status: stable
---
# API 文档
本目录包含 OpenAPI 规范与示例。可使用 Swagger UI 或 Redoc 渲染 `openapi.yaml`
- OpenAPI: `openapi.yaml`

78
docs/api/endpoints.md Normal file
View File

@@ -0,0 +1,78 @@
---
title: API 端点总览
summary: 基于 `apps/server` 控制器实现的主要 REST API 端点汇总。
owners:
- team: backend
status: stable
---
# API 端点总览
基础前缀:`/api`
下面列出当前实现的主要控制器与常用端点。
## Projects (`/api/projects`)
- GET `/api/projects` : 列表(支持分页与按 name 搜索)
- GET `/api/projects/:id` : 获取单个项目(包含 workspace 状态)
- POST `/api/projects` : 创建项目body: `name`, `repository`, `projectDir` 等)
- PUT `/api/projects/:id` : 更新项目
- DELETE `/api/projects/:id` : 软删除(将 `valid` 置为 0
示例:
```http
GET /api/projects?page=1&limit=10
```
## User (`/api/user`)
- GET `/api/user/list` : 模拟用户列表
- GET `/api/user/detail/:id` : 用户详情
- POST `/api/user` : 创建用户
- PUT `/api/user/:id` : 更新用户
- DELETE `/api/user/:id` : 删除用户
- GET `/api/user/search` : 搜索用户
## Auth (`/api/auth`)
- GET `/api/auth/url` : 获取 Gitea OAuth 授权 URL
- POST `/api/auth/login` : 使用 OAuth code 登录(返回 session
- GET `/api/auth/logout` : 登出
- GET `/api/auth/info` : 当前会话用户信息
注意:需要配置 `GITEA_URL``GITEA_CLIENT_ID``GITEA_REDIRECT_URI`
## Deployments (`/api/deployments`)
- GET `/api/deployments` : 列表(支持 projectId 过滤)
- POST `/api/deployments` : 创建部署(会将任务加入执行队列)
- POST `/api/deployments/:id/retry` : 重新执行某次部署(复制记录并 requeue
## Pipelines (`/api/pipelines`)
- GET `/api/pipelines` : 列表(含 steps
- GET `/api/pipelines/templates` : 获取可用流水线模板
- GET `/api/pipelines/:id` : 单个流水线(含步骤)
- POST `/api/pipelines` : 创建流水线
- POST `/api/pipelines/from-template` : 基于模板创建流水线
- PUT `/api/pipelines/:id` : 更新流水线
- DELETE `/api/pipelines/:id` : 软删除
## Steps (`/api/steps`)
- GET `/api/steps` : 列表(支持 pipelineId 过滤)
- GET `/api/steps/:id` : 单个步骤
- POST `/api/steps` : 创建步骤(包含 `script` 字段)
- PUT `/api/steps/:id` : 更新步骤
- DELETE `/api/steps/:id` : 软删除
## Git (`/api/git`)
- GET `/api/git/commits?projectId=&branch=` : 获取指定项目的提交列表(调用 Gitea
- GET `/api/git/branches?projectId=` : 获取分支列表
---
想要更详细的示例(请求 body、响应 schema我可以为每个端点基于 `dto.ts` 自动生成示例请求/响应片段。是否需要我继续生成?

28
docs/api/openapi.yaml Normal file
View File

@@ -0,0 +1,28 @@
openapi: 3.0.1
info:
title: Foka-CI 示例 API
version: '1.0.0'
paths:
/health:
get:
summary: 健康检查
responses:
'200':
description: OK
/projects:
get:
summary: 列出项目
responses:
'200':
description: 项目列表
content:
application/json:
schema:
type: array
items:
type: object
properties:
id:
type: string
name:
type: string