From 5e0cdba1f9f80334609c2a544f489ace8fd7306a Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 11:03:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E4=B8=8E=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 26 +++++++++++-------- app/controllers/ci/pipelines_controller.rb | 8 ++++-- app/controllers/ci/projects_controller.rb | 8 ++++++ ...add_sync_and_project_id_to_ci_pipelines.rb | 6 +++++ 4 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20210119025745_add_sync_and_project_id_to_ci_pipelines.rb diff --git a/api_document.md b/api_document.md index db0789076..50d9ec584 100644 --- a/api_document.md +++ b/api_document.md @@ -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 | 创建时间 | +| 参数名 | 类型 | 说明 | +| ------------- | ------ | --------------- | +| 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 | *返回参数说明:* diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 253d399d0..b6abecb44 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -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]) diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index c7b7338f1..55645ed44 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -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? diff --git a/db/migrate/20210119025745_add_sync_and_project_id_to_ci_pipelines.rb b/db/migrate/20210119025745_add_sync_and_project_id_to_ci_pipelines.rb new file mode 100644 index 000000000..617731ac2 --- /dev/null +++ b/db/migrate/20210119025745_add_sync_and_project_id_to_ci_pipelines.rb @@ -0,0 +1,6 @@ +class AddSyncAndProjectIdToCiPipelines < ActiveRecord::Migration[5.2] + def change + add_column :ci_pipelines, :sync, :integer, null: false, comment: '0 未同步到gitea,1 已同步', default: 0 + add_column :ci_pipelines, :project_id, :integer + end +end \ No newline at end of file