From 4ac763403167331f215b9ad1ebcbe316794ec16a Mon Sep 17 00:00:00 2001 From: moshenglv Date: Thu, 14 Jan 2021 15:32:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=AD=A5=E9=AA=A4?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E3=80=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 78 +++------------------- app/controllers/ci/pipelines_controller.rb | 22 ++++++ config/routes.rb | 1 + 3 files changed, 34 insertions(+), 67 deletions(-) diff --git a/api_document.md b/api_document.md index b8376b32..3c612908 100644 --- a/api_document.md +++ b/api_document.md @@ -4383,72 +4383,16 @@ http://localhost:3000/api/ci/pipelines/1/2/steps.json | jq ------ -#### 流水线阶段步骤新增 +#### 流水线阶段步骤新增/更新 ``` -POST /api/ci/pipelines/{id}/{stage_id}/create_step +PUT /api/ci/pipelines/{id}/{stage_id}/stage_step ``` *示例* ```bash -curl --location --request POST 'http://localhost:3000/api/ci/pipelines/14/20/create_step.json' \ ---header 'Content-Type: application/json' \ ---data-raw ' {"steps":[{ - "step_name": "编译构建-gradle", - "show_index": 1, - "content": "xxxxxxxxxxx", - "template_id":1 -}, -{ - "step_name": "编译构建-maven", - "show_index": 1, - "content": "xxxxxxxxxxx", - "template_id":1 -} -] - }' -``` - -*请求参数说明:* - -| 参数名 | 必选 | 类型 | 说明 | -| ----------- | ---- | ------ | ------------------------- | -| steps | 是 | arr | 需要新增的步骤数组 | -| id | 是 | int | 流水线id | -| stage_id | 是 | int | 阶段id | -| step_name | 是 | string | 阶段名称(阶段名-模板名) | -| content | 是 | string | 步骤内容 | -| template_id | 是 | int | 模板id | - -*返回参数说明:* - -| 参数名 | 类型 | 说明 | -| ------- | ------ | ------------ | -| status | int | 状态码 0成功 | -| message | string | 返回消息 | - -返回值 - -```json -{ - "status": 0, - "message": "success" -} -``` - ------- - -#### 流水线阶段步骤更新 - -``` -PUT /api/ci/pipelines/{id}/{stage_id}/update_step -``` - -*示例* - -```bash -curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/2/update_step.json' \ +curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/2/stage_step.json' \ --header 'Content-Type: application/json' \ --data-raw ' {"steps":[{ "id":7, @@ -4470,14 +4414,14 @@ curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/2/update *请求参数说明:* -| 参数名 | 必选 | 类型 | 说明 | -| ----------- | ---- | ------ | ------------------------- | -| steps | 是 | arr | 需要更新step数组 | -| id | 是 | int | 流水线id | -| stage_id | 是 | int | 阶段id | -| step_name | 是 | string | 阶段名称(阶段名-模板名) | -| content | 是 | string | 步骤内容 | -| template_id | 是 | int | 模板id | +| 参数名 | 必选 | 类型 | 说明 | +| ----------- | ---- | ------ | -------------------------------- | +| steps | 是 | arr | 需要更新step数组 | +| id | 是 | int | 流水线id | +| step_id | 是 | int | 阶段id(存在则更新,不存在新增) | +| step_name | 是 | string | 阶段名称(阶段名-模板名) | +| content | 是 | string | 步骤内容 | +| template_id | 是 | int | 模板id | *返回参数说明:* diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 28b6029b..4cd7cf62 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -123,6 +123,28 @@ class Ci::PipelinesController < ApplicationController @pipeline_stage_steps = Ci::PipelineStageStep.where('stage_id=?', params[:stage_id]).order('show_index asc') end + def stage_step + ActiveRecord::Base.transaction do + steps = params[:steps] + unless steps.empty? + steps.each do |step| + 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]) + step.save! + else + pipeline_stage_step = Ci::PipelineStageStep.find(step[:id]) + pipeline_stage_step.update(step_name: step[:step_name], content: step[:content], + show_index: step[:show_index], template_id: step[:template_id]) + end + end + end + render_ok + end + rescue Exception => ex + render_error(ex.message) + end + def create_stage_step ActiveRecord::Base.transaction do steps = params[:steps] diff --git a/config/routes.rb b/config/routes.rb index 4de53af5..1281d16b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -50,6 +50,7 @@ Rails.application.routes.draw do put :update_stage, :path => ":stage_id/update_stage", to: 'pipelines#update_stage' get :stage_steps, :path => ":stage_id/steps", to: 'pipelines#steps' post :create_stage_step, :path => ":stage_id/create_step", to: 'pipelines#create_stage_step' + post :stage_step, :path => ":stage_id/stage_step", to: 'pipelines#stage_step' delete :delete_stage_step, :path => ":stage_id/:step_id/delete_step", to: 'pipelines#delete_stage_step' put :update_stage_step, :path => ":stage_id/update_step", to: 'pipelines#update_stage_step' end