流水线与项目关联

This commit is contained in:
moshenglv 2021-01-19 11:03:27 +08:00
parent c6aeecb33c
commit 5e0cdba1f9
4 changed files with 35 additions and 13 deletions

View File

@ -3283,12 +3283,12 @@ http://localhost:3000/api/jasder/forge/get_trustie_pipeline.json | jq
#### 更新'.trustie-pipeline.yml'文件
```
PUT /api/:owner/:repo/update_trustie_pipeline
PUT /api/:owner/:repo/update_trustie_pipeline?pipeline_id={pipeline_id}
```
*示例*
```bash
curl -X GET \
http://localhost:3000/api/jasder/forge/update_trustie_pipeline.json | jq
http://localhost:3000/api/jasder/forge/update_trustie_pipeline.json?pipeline_id=1 | jq
```
*请求参数说明:*
@ -3305,6 +3305,7 @@ http://localhost:3000/api/jasder/forge/update_trustie_pipeline.json | jq
|branch |否|string |分支名称, branch和new_branch必须存在一个,且只能存在一个 |
|new_branch |否|string |新的分支名称 |
|ci_language_id |否|string |新的分支名称 |
|pipeline_id |是|int |流水线id |
*返回参数说明:*
@ -3954,24 +3955,25 @@ https://localhost:3000/api/users/ci/cloud_account/bind.json | jq
#### 流水线查询
```
GET /api/ci/pipelines/list
GET /api/ci/pipelines/list?project_id={project_id}
```
*示例*
```bash
curl -X GET \
http://localhost:3000/api/ci/pipelines/list.json | jq
http://localhost:3000/api/ci/pipelines/list.json?project_id=1 | jq
```
*返回参数说明:*
| 参数名 | 类型 | 说明 |
| ------------- | ------ | ------------ |
| ------------- | ------ | --------------- |
| id | int | 流水线id |
| pipeline_name | string | 流水线名称 |
| file_name | string | 流水线文件名 |
| created_at | string | 创建时间 |
| sync | int | 是否同步到gitea |
返回值
@ -4004,7 +4006,8 @@ curl --location --request POST 'http://localhost:3000/api/ci/pipelines' \
--header 'Content-Type: application/json' \
--data-raw ' {
"pipeline_name": "流水线 2021-01-12",
"file_name": ".trustie.pipeline.yaml"
"file_name": ".trustie.pipeline.yaml",
"project_id": 1
}'
```
@ -4014,6 +4017,7 @@ curl --location --request POST 'http://localhost:3000/api/ci/pipelines' \
| ------------- | ---- | ------ | ---------------------------------------------- |
| pipeline_name | 是 | string | 流水线名称 |
| file_name | 是 | string | 文件名称(默认初始值:.trustie.pipeline.yaml |
| project_id | 是 | int | 项目id |
*返回参数说明:*

View File

@ -5,12 +5,12 @@ class Ci::PipelinesController < Ci::BaseController
# ======流水线相关接口========== #
def list
@pipelines = Ci::Pipeline.where('login=?', current_user.login)
@pipelines = Ci::Pipeline.where('login=? and project_id=?', current_user.login, params[:project_id])
end
def create
ActiveRecord::Base.transaction do
pipeline = Ci::Pipeline.new(pipeline_name: params[:pipeline_name], file_name: params[:file_name], login: current_user.login)
pipeline = Ci::Pipeline.new(pipeline_name: params[:pipeline_name], file_name: params[:file_name], login: current_user.login, project_id: params[:project_id])
pipeline.save!
# 默认创建四个初始阶段
@ -132,6 +132,10 @@ class Ci::PipelinesController < Ci::BaseController
steps = params[:steps]
unless steps.empty?
steps.each do |step|
unless step[:template_id]
render_error("请选择模板!")
return
end
if !step[:id]
step = Ci::PipelineStageStep.new(step_name: step[:step_name], stage_id: params[:stage_id],
template_id: step[:template_id], content: step[:content], show_index: step[:show_index])

View File

@ -28,12 +28,20 @@ class Ci::ProjectsController < Ci::BaseController
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, params[:owner], params.merge(identifier: @project.identifier))
if interactor.success?
@file = interactor.result
update_pipeline(params[:pipeline_id])
render_result(1, "更新成功")
else
render_error(interactor.error)
end
end
def update_pipeline(pipeline_id)
pipeline = Ci::Pipeline.find(pipeline_id)
if pipeline
pipeline.update!(sync: 1)
end
end
def activate
return render_error('你还未认证') unless current_user.ci_certification?

View File

@ -0,0 +1,6 @@
class AddSyncAndProjectIdToCiPipelines < ActiveRecord::Migration[5.2]
def change
add_column :ci_pipelines, :sync, :integer, null: false, comment: '0 未同步到gitea1 已同步', default: 0
add_column :ci_pipelines, :project_id, :integer
end
end