From 77529319a15fd819a41f8ce97af266daa6451fde Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 12 Jan 2021 10:23:26 +0800 Subject: [PATCH 01/24] =?UTF-8?q?=E5=8F=AF=E8=A7=86=E5=8C=96=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=90=8E=E7=AB=AF=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 731 +++++++++++++++++- app/controllers/ci/pipelines_controller.rb | 175 +++++ app/controllers/ci/templates_controller.rb | 26 + app/models/ci/pipeline.rb | 19 + app/models/ci/pipeline_stage.rb | 24 + app/models/ci/pipeline_stage_step.rb | 22 + app/models/ci/template.rb | 22 + .../pipeline_stage_steps/_list.json.jbuilder | 9 + .../ci/pipeline_stages/_list.json.jbuilder | 8 + app/views/ci/pipelines/_list.json.jbuilder | 9 + app/views/ci/pipelines/content.json.jbuilder | 1 + app/views/ci/pipelines/list.json.jbuilder | 3 + app/views/ci/pipelines/stages.json.jbuilder | 3 + app/views/ci/pipelines/steps.json.jbuilder | 3 + app/views/ci/templates/_list.json.jbuilder | 8 + .../_templates_by_stage.json.jbuilder | 4 + app/views/ci/templates/list.json.jbuilder | 3 + .../templates_by_stage.json.jbuilder | 3 + config/routes.rb | 25 + .../20210108015318_create_ci_templates.rb | 14 + .../20210108055023_create_ci_pipelines.rb | 11 + ...0210108062016_create_ci_pipeline_stages.rb | 12 + ...11013512_create_ci_pipeline_stage_steps.rb | 13 + 23 files changed, 1147 insertions(+), 1 deletion(-) create mode 100644 app/controllers/ci/pipelines_controller.rb create mode 100644 app/controllers/ci/templates_controller.rb create mode 100644 app/models/ci/pipeline.rb create mode 100644 app/models/ci/pipeline_stage.rb create mode 100644 app/models/ci/pipeline_stage_step.rb create mode 100644 app/models/ci/template.rb create mode 100644 app/views/ci/pipeline_stage_steps/_list.json.jbuilder create mode 100644 app/views/ci/pipeline_stages/_list.json.jbuilder create mode 100644 app/views/ci/pipelines/_list.json.jbuilder create mode 100644 app/views/ci/pipelines/content.json.jbuilder create mode 100644 app/views/ci/pipelines/list.json.jbuilder create mode 100644 app/views/ci/pipelines/stages.json.jbuilder create mode 100644 app/views/ci/pipelines/steps.json.jbuilder create mode 100644 app/views/ci/templates/_list.json.jbuilder create mode 100644 app/views/ci/templates/_templates_by_stage.json.jbuilder create mode 100644 app/views/ci/templates/list.json.jbuilder create mode 100644 app/views/ci/templates/templates_by_stage.json.jbuilder create mode 100644 db/migrate/20210108015318_create_ci_templates.rb create mode 100644 db/migrate/20210108055023_create_ci_pipelines.rb create mode 100644 db/migrate/20210108062016_create_ci_pipeline_stages.rb create mode 100644 db/migrate/20210111013512_create_ci_pipeline_stage_steps.rb diff --git a/api_document.md b/api_document.md index 50a45573c..4d8a6d5ba 100644 --- a/api_document.md +++ b/api_document.md @@ -3865,6 +3865,48 @@ http://localhost:3000/api/users/ci/cloud_account | jq } } ``` +------ + +#### 绑定CI服务器-Trustie提供服务器 + +``` +POST /api/users/ci/cloud_account/trustie_bind +``` + +*示例* + +```bash +curl -X POST \ +-d "account=xx" \ +https://localhost:3000/api/users/ci/cloud_account/trustie_bind.json | jq +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| ------- | ---- | ------ | ---------- | +| account | 是 | string | 登录用户名 | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------------ | ------ | --------------------------------------- | +| step | int | 0: 未绑定;1: 未认证(已绑定),2: 已认证 | +| ip | string | ci服务器ip | +| redirect_url | string | 认证地址 | + +返回值 + +```json +{ + "step": 0, + "cloud_account": { + "ip": "xxx.xxx.xxx.x", + "redirect_url": "http://localhost:3000/login" + } +} +``` + --- #### 绑定CI服务器 @@ -3907,10 +3949,697 @@ https://localhost:3000/api/users/ci/cloud_account/bind.json | jq } } ``` +------ + +#### 流水线查询 + +``` +GET /api/ci/pipelines/list +``` + +*示例* + +```bash +curl -X GET \ +http://localhost:3000/api/ci/pipelines/list.json | jq +``` + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------------- | ------ | ---------------------------------------------- | +| id | int | 流水线id | +| pipeline_name | string | 流水线名称 | +| file_name | string | 流水线文件名 | +| created_at | string | 创建时间 | +| stages | arr | 流水线包含的阶段数组(字段详情看阶段查询接口) | + +返回值 + +```json +{ + "pipelines": [ + { + "id": 1, + "pipeline_name": "2020-01-08 流水线", + "file_name": ".trustie.pipeline.yaml", + "created_at": "2021-01-08 04:16:24", + "updated_at": "2021-01-08 04:16:24", + "stages": [ + { + "id": 1, + "stage_name": "初始化", + "stage_type": "init", + "pipeline_id": 1, + "show_index": 0, + "created_at": "2021-01-08 04:16:24", + "updated_at": "2021-01-08 04:16:24" + }, + { + "id": 2, + "stage_name": "编译构建", + "stage_type": "build", + "pipeline_id": 1, + "show_index": 1, + "created_at": "2021-01-08 04:16:24", + "updated_at": "2021-01-11 04:16:24" + } + ] + } + ] +} +``` + --- +#### 流水线新增 -### 解除CI服务器绑定 +点击"新增流水线"按钮时调用。 + +``` +POST /api/ci/pipelines +``` + +*示例* + +```bash +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" +}' +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| ------------- | ---- | ------ | ---------------------------------------------- | +| pipeline_name | 是 | string | 流水线名称(默认初始值:流水线 yyyy-mm-dd) | +| file_name | 是 | string | 文件名称(默认初始值:.trustie.pipeline.yaml) | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------- | ------ | ------------ | +| status | int | 状态码 0成功 | +| message | string | 返回消息 | + +返回值 + +```json +{ + "status": 0, + "message": "success" +} +``` + +------ + +#### 流水线更新 + +修改流水线名称时调用。 + +``` +PUT /api/ci/pipelines/{id} +``` + +*示例* + +```bash +curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/3' \ +--header 'Content-Type: application/json' \ +--data-raw ' { + "pipeline_name": "2020-01-11 流水线" +}' +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| ------------- | ---- | ------ | ---------- | +| id | 是 | id | 流水线id | +| pipeline_name | 是 | string | 流水线名称 | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------- | ------ | ------------ | +| status | int | 状态码 0成功 | +| message | string | 返回消息 | + +返回值 + +```json +{ + "status": 0, + "message": "success" +} +``` + +------ + +#### 流水线删除 + +``` +DELETE /api/ci/pipelines/{id} +``` + +*示例* + +```bash +curl -X DELETE \ +https://localhost:3000/api/ci/pipelines/1 | jq +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| ------ | ---- | ---- | -------- | +| id | 是 | int | 流水线id | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------- | ------ | ------------ | +| status | int | 状态码 0成功 | +| message | string | 返回消息 | + +返回值 + +```json +{ + "status": 0, + "message": "success" +} +``` + +------ + +#### 流水线阶段排序 + +当新增阶段或者删除阶段时重新给受影响的stage设置show_index。 + +``` +PUT /api/ci/pipelines/{id}/sort_stage +``` + +*示例* + +```bash +curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/sort_stage.json' \ +--header 'Content-Type: application/json' \ +--data-raw ' {"stage_index":[ + {"id": 1,"show_index": 0}, + {"id": 2,"show_index": 1}, + {"id": 3,"show_index": 2}, + {"id": 4,"show_index": 3}, + {"id": 7,"show_index": 4} + ] + }' +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| ----------- | ---- | ---- | ---------- | +| stage_index | 是 | arr | 参数数组 | +| id | 是 | int | 阶段id | +| show_index | 是 | int | 阶段的序号 | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------- | ------ | ------------ | +| status | int | 状态码 0成功 | +| message | string | 返回消息 | + +返回值 + +```json +{ + "status": 0, + "message": "success" +} +``` + +------ + +#### 确认阶段流水线内容查询 + +``` +GET /api/ci/pipelines/{id}/content +``` + +*示例* + +```bash +curl -X GET \ +http://localhost:3000/api/ci/pipelines/1/content.json | jq +``` + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------ | ---- | -------- | +| id | int | 流水线id | + +返回值 + +```json +{ + "content": "#pipeline \nkind: pipeline\r\nname: maven项目-镜像仓库\r\n\r\nplatform:\r\n os: linux\r\n arch: arm64\nsteps:\n- name: Maven编译\r\n image: arm64v8/maven\r\n commands:\r\n - mvn install\n- name: 编译镜像-推送到仓库\r\n image: plugins/docker\r\n settings:\r\n username: moshenglv\r\n password: RL9UB5P7Jtzukka\r\n repo: docker.io/moshenglv/demo\r\n tags: latest\n" +} +``` + +------ + +#### 流水线阶段新增 + +``` +POST /api/ci/pipelines/{id}/create_stage +``` + +*示例* + +```bash +curl --location --request POST 'http://localhost:3000/api/ci/pipelines/14/create_stage.json' \ +--header 'Content-Type: application/json' \ +--data-raw ' {"stages":[{ + "stage_name": "新阶段1", + "stage_type": "customize", + "show_index": 5 +}, +{ + "stage_name": "新阶段2", + "stage_type": "customize", + "show_index": 5 +} +] + }' +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| ---------- | ---- | ------ | -------------------------------- | +| stages | 是 | arr | 新增的阶段数组 | +| id | 是 | int | 流水线id | +| stage_name | 是 | string | 阶段名称(默认为 阶段名-模板名) | +| show_index | 是 | int | 阶段排序 | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------- | ------ | ------------ | +| status | int | 状态码 0成功 | +| message | string | 返回消息 | + +返回值 + +```json +{ + "status": 0, + "message": "success" +} +``` + +------ + +#### 流水线阶段更新 + +``` +PUT /api/ci/pipelines/{id}/update_stage +``` + +*示例* + +```bash +curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/5/update_stage.json' \ +--header 'Content-Type: application/json' \ +--data-raw ' { + "stage_name": "新阶段-更新", + "stage_type": "customize", + "show_index": 10 +}' +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| ---------- | ---- | ------ | -------------------------------- | +| id | 是 | int | 流水线id | +| stage_name | 是 | string | 阶段名称(默认为 阶段名-模板名) | +| show_index | 是 | int | 阶段排序 | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------- | ------ | ------------ | +| status | int | 状态码 0成功 | +| message | string | 返回消息 | + +返回值 + +```json +{ + "status": 0, + "message": "success" +} +``` + +------ + +#### 流水线阶段删除 + +``` +DELETE /api/ci/pipelines/{id}/{stage_id}/delete_stage +``` + +*示例* + +```bash +curl -X DELETE \ +https://localhost:3000/api/ci/pipelines/1/6/delete_stage.json | jq +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| -------- | ---- | ---- | -------- | +| id | 是 | int | 流水线id | +| stage_id | 是 | int | 阶段id | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------- | ------ | ------------ | +| status | int | 状态码 0成功 | +| message | string | 返回消息 | + +返回值 + +```json +{ + "status": 0, + "message": "success" +} +``` + +------ + +#### 流水线阶段步骤查询 + +``` +GET /api/ci/pipelines/{id}/{stage_id}/steps.json +``` + +*示例* + +```bash +curl -X GET \ +http://localhost:3000/api/ci/pipelines/1/2/steps.json | jq +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| -------- | ---- | ---- | -------- | +| id | 是 | int | 流水线id | +| stage_id | 是 | int | 阶段id | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ----------- | ------ | ---------- | +| id | int | 步骤id | +| step_name | string | 步骤名称 | +| stage_id | int | 所属阶段id | +| template_id | int | 模板id | +| show_index | int | 显示顺序 | +| content | String | 步骤内容 | + +返回值 + +```json +{ + "steps": [ + { + "id": 1, + "step_name": "编译构建-maven", + "stage_id": 2, + "template_id": null, + "show_index": 0, + "content": "xxxxxxxxxxx", + "created_at": "2021-01-11T09:57:17.000+08:00", + "updated_at": "2021-01-11T09:57:17.000+08:00" + }, + { + "id": 2, + "step_name": "编译构建-maven-更新", + "stage_id": 2, + "template_id": 2, + "show_index": 2, + "content": "xxxx====xxxxxxx", + "created_at": "2021-01-11T10:12:58.000+08:00", + "updated_at": "2021-01-11T10:40:54.000+08:00" + } + ] +} +``` + +------ + +#### 流水线阶段步骤新增 + +``` +POST /api/ci/pipelines/{id}/{stage_id}/create_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' \ +--header 'Content-Type: application/json' \ +--data-raw ' {"steps":[{ + "id":7, + "step_name": "编译构建11-gradle", + "show_index": 1, + "content": "xxxxxxxxxxx", + "template_id":2 +}, +{ + "id":8, + "step_name": "编译构建22-maven", + "show_index": 1, + "content": "xxxxxxxxxxx", + "template_id":2 +} +] + }' +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| ----------- | ---- | ------ | ------------------------- | +| steps | 是 | arr | 需要更新step数组 | +| 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" +} +``` + +------ + +#### 流水线阶段步骤删除 + +``` +DELETE /api/ci/pipelines/{id}/{stage_id}/{step_id}/delete_step +``` + +*示例* + +```bash +curl -X DELETE \ +https://localhost:3000/api/ci/pipelines/1/6/2/delete_stage.json | jq +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| -------- | ---- | ---- | -------- | +| id | 是 | int | 流水线id | +| stage_id | 是 | int | 阶段id | +| step_id | 是 | int | 步骤id | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------- | ------ | ------------ | +| status | int | 状态码 0成功 | +| message | string | 返回消息 | + +返回值 + +```json +{ + "status": 0, + "message": "success" +} +``` + +------ + +#### 阶段模板查询 + +``` +GET /api/ci/templates/templates_by_stage?stage_type={stage_type} +``` + +*示例* + +```bash +curl -X GET \ +http://localhost:3000/api/ci/templates/templates_by_stage.json?stage_type=build | jq +``` + +*请求参数说明:* + +| 参数名 | 必选 | 类型 | 说明 | +| ---------- | ---- | ------ | --------------------------------------------- | +| stage_type | 是 | string | 阶段类型:init/build/deploy/customize/confirm | + +*返回参数说明:* + +| 参数名 | 类型 | 说明 | +| ------------- | ------ | ---------------- | +| category | string | 分类名称 | +| templates | arr | 分类下的模板列表 | +| id | int | 模板id | +| template_name | string | 模板名称 | +| content | String | 模板内容 | + +返回值 + +```json +[ + { + "category": "java", + "templates": [ + { + "id": 3, + "template_name": "maven", + "stage_type": "build", + "category": "java", + "content": "#maven", + "created_at": "2021-01-11T17:28:34.000+08:00", + "updated_at": "2021-01-11T17:28:36.000+08:00" + }, + { + "id": 4, + "template_name": "gradle", + "stage_type": "build", + "category": "java", + "content": "#gradle", + "created_at": "2021-01-11T17:28:34.000+08:00", + "updated_at": "2021-01-11T17:28:36.000+08:00" + } + ] + }, + { + "category": "c++", + "templates": [ + { + "id": 5, + "template_name": "make", + "stage_type": "build", + "category": "c++", + "content": "#make", + "created_at": "2021-01-11T17:29:17.000+08:00", + "updated_at": "2021-01-11T17:29:18.000+08:00" + } + ] + } +] +``` + +------ + + +#### 解除CI服务器绑定 ``` DELETE /api/users/ci/cloud_account/unbind ``` diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb new file mode 100644 index 000000000..0ac53d80a --- /dev/null +++ b/app/controllers/ci/pipelines_controller.rb @@ -0,0 +1,175 @@ +class Ci::PipelinesController < ApplicationController + + # ======流水线相关接口========== # + def list + @pipelines = Ci::Pipeline.all + end + + def create + ActiveRecord::Base.transaction do + pipeline = Ci::Pipeline.new(pipeline_name: params[:pipeline_name], file_name: params[:file_name]) + pipeline.save! + + # 默认创建四个初始阶段 + init_stages = Ci::PipelineStage::INIT_STAGES + index = 0 + init_stages.each do |type, name| + pipeline.pipeline_stages.build( + stage_name: name, + stage_type: type, + show_index: index + ).save! + index += 1 + end + render_ok + end + rescue Exception => ex + render_error(ex.message) + end + + def update + pipeline = Ci::Pipeline.find(params[:id]) + if pipeline + pipeline.update!(pipeline_name: params[:pipeline_name]) + end + render_ok + rescue Exception => ex + render_error(ex.message) + end + + def destroy + pipeline = Ci::Pipeline.find(params[:id]) + if pipeline + pipeline.destroy! + end + render_ok + rescue Exception => ex + render_error(ex.message) + end + + def content + @yaml = "#pipeline \n" + stages = Ci::Pipeline.find(params[:id]).pipeline_stages + if stages && !stages.empty? + init_step = stages.first.pipeline_stage_steps.first + @yaml += init_step.content + "\n" + "steps:\n" + stages = stages.slice(1, stages.size - 1) + unless stages.empty? + stages.each do |stage| + steps = stage.pipeline_stage_steps + next unless steps && !steps.empty? + steps.each do |step| + @yaml += step.content + "\n" + end + end + end + end + end + + # =========阶段相关接口========= # + def stages + pipeline_id = params[:id] + @pipeline_stages = Ci::PipelineStage.where('pipeline_id=?', pipeline_id).order('show_index asc') + end + + def create_stage + ActiveRecord::Base.transaction do + stages = params[:stages] + unless stages.empty? + stages.each do |stage| + pipeline_stage = Ci::PipelineStage.new(stage_name: stage[:stage_name], + stage_type: stage[:stage_type].blank? ? 'customize' : stage[:stage_type], + pipeline_id: params[:id], show_index: stage[:show_index]) + pipeline_stage.save! + end + end + render_ok + end + rescue Exception => ex + render_error(ex.message) + end + + def update_stage + pipeline_stage = Ci::PipelineStage.find(params[:stage_id]) + if pipeline_stage + pipeline_stage.update!(stage_name: params[:stage_name], show_index: params[:show_index]) + end + render_ok + rescue Exception => ex + render_error(ex.message) + end + + def delete_stage + pipeline_stage = Ci::PipelineStage.find(params[:stage_id]) + if pipeline_stage + pipeline_stage.destroy! + end + render_ok + rescue Exception => ex + render_error(ex.message) + end + + def sort_stage + stages = params[:stage_index] + if stages && !stages.empty? + stages.each do |stage| + pipeline_stage = Ci::PipelineStage.find(stage[:id]) + if pipeline_stage + pipeline_stage.update!(show_index: stage[:show_index]) + end + end + end + render_ok + rescue Exception => ex + render_error(ex.message) + end + + # ========步骤相关接口========= # + def steps + @pipeline_stage_steps = Ci::PipelineStageStep.where('stage_id=?', params[:stage_id]).order('show_index asc') + end + + def create_stage_step + ActiveRecord::Base.transaction do + steps = params[:steps] + unless steps.empty? + steps.each do |step| + 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! + end + end + render_ok + end + rescue Exception => ex + render_error(ex.message) + end + + def update_stage_step + ActiveRecord::Base.transaction do + steps = params[:steps] + unless steps.empty? + steps.each do |step| + pipeline_stage_step = Ci::PipelineStageStep.find(step[:id]) + if pipeline_stage_step + 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 delete_stage_step + pipeline_stage_step = Ci::PipelineStageStep.find(params[:step_id]) + if pipeline_stage_step + pipeline_stage_step.destroy! + end + render_ok + rescue Exception => ex + render_error(ex.message) + end +end diff --git a/app/controllers/ci/templates_controller.rb b/app/controllers/ci/templates_controller.rb new file mode 100644 index 000000000..4423bb402 --- /dev/null +++ b/app/controllers/ci/templates_controller.rb @@ -0,0 +1,26 @@ +class Ci::TemplatesController < ApplicationController + + def list + @templates = Ci::Template.all + end + + def templates_by_stage + stage_type = params[:stage_type] + @templates = Ci::Template.where("stage_type = ?", stage_type) + #根据模板类别分组 + @category_templates = @templates.group_by{ |template| template.category } + end + + def create + template = Ci::Template.new(template_name: params[:template_name], + stage_type: params[:stage_type], + category: params[:category], + content: params[:content] + ) + template.save! + render_ok + rescue Exception => ex + render_error(ex.message) + end + +end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb new file mode 100644 index 000000000..f69b7e46d --- /dev/null +++ b/app/models/ci/pipeline.rb @@ -0,0 +1,19 @@ +# == Schema Information +# +# Table name: ci_pipelines +# +# id :integer not null, primary key +# pipeline_name :string(255) not null +# pipeline_status :integer default("0"), not null +# file_name :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# + +class Ci::Pipeline < Ci::LocalBase + validates :pipeline_name, presence: {message: "流水线名称不能为空"} + validates :file_name, presence: {message: "流水线文件名称不能为空"} + + has_many :pipeline_stages, -> { reorder(show_index: :asc) }, foreign_key: "pipeline_id", :class_name => 'Ci::PipelineStage', dependent: :destroy + +end diff --git a/app/models/ci/pipeline_stage.rb b/app/models/ci/pipeline_stage.rb new file mode 100644 index 000000000..3cf23ad99 --- /dev/null +++ b/app/models/ci/pipeline_stage.rb @@ -0,0 +1,24 @@ +# == Schema Information +# +# Table name: ci_pipeline_stages +# +# id :integer not null, primary key +# stage_name :string(255) not null +# stage_type :string(255) not null +# pipeline_id :integer not null +# show_index :integer default("0"), not null +# created_at :datetime not null +# updated_at :datetime not null +# + +class Ci::PipelineStage < Ci::LocalBase + + validates :stage_name, presence: {message: "阶段名称不能为空"} + validates :stage_type, presence: {message: "阶段类型不能为空"} + + belongs_to :pipeline, foreign_key: :pipeline_id, :class_name => 'Ci::Pipeline' + has_many :pipeline_stage_steps, -> { reorder(show_index: :asc) }, foreign_key: "stage_id", :class_name => 'Ci::PipelineStageStep', dependent: :destroy + + INIT_STAGES = {init:"初始化", build:"编译构建", deploy:"部署", confirm:"确认"}.freeze + +end diff --git a/app/models/ci/pipeline_stage_step.rb b/app/models/ci/pipeline_stage_step.rb new file mode 100644 index 000000000..2d7c8721b --- /dev/null +++ b/app/models/ci/pipeline_stage_step.rb @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: ci_pipeline_stage_steps +# +# id :integer not null, primary key +# step_name :string(255) not null +# stage_id :integer not null +# template_id :integer +# content :text(65535) +# show_index :integer +# created_at :datetime not null +# updated_at :datetime not null +# + +class Ci::PipelineStageStep < Ci::LocalBase + + validates :step_name, presence: {message: "步骤名称不能为空"} + validates :stage_id, presence: {message: "阶段id不能为空"} + + belongs_to :pipeline_stage, foreign_key: :stage_id, :class_name => 'Ci::PipelineStage' + has_one :template, :class_name => 'Ci::Template', foreign_key: :template_id +end diff --git a/app/models/ci/template.rb b/app/models/ci/template.rb new file mode 100644 index 000000000..34aab41df --- /dev/null +++ b/app/models/ci/template.rb @@ -0,0 +1,22 @@ +# == Schema Information +# +# Table name: ci_templates +# +# id :integer not null, primary key +# template_name :string(255) not null +# stage_type :string(255) not null +# category :string(255) not null +# content :text(65535) not null +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_ci_templates_on_stage_type (stage_type) +# + +class Ci::Template < Ci::LocalBase + validates :template_name, presence: {message: "模板名称不能为空"} + validates :stage_type, presence: {message: "阶段类型不能为空"} + validates :category, presence: {message: "模板类型不能为空"} +end diff --git a/app/views/ci/pipeline_stage_steps/_list.json.jbuilder b/app/views/ci/pipeline_stage_steps/_list.json.jbuilder new file mode 100644 index 000000000..a3d592fbd --- /dev/null +++ b/app/views/ci/pipeline_stage_steps/_list.json.jbuilder @@ -0,0 +1,9 @@ +json.id pipeline_stage_step.id +json.step_name pipeline_stage_step.step_name +json.stage_id pipeline_stage_step.stage_id +json.template_id pipeline_stage_step.template_id +json.show_index pipeline_stage_step.show_index +json.content pipeline_stage_step.content +json.created_at pipeline_stage_step.created_at +json.updated_at pipeline_stage_step.updated_at + diff --git a/app/views/ci/pipeline_stages/_list.json.jbuilder b/app/views/ci/pipeline_stages/_list.json.jbuilder new file mode 100644 index 000000000..1e782ee40 --- /dev/null +++ b/app/views/ci/pipeline_stages/_list.json.jbuilder @@ -0,0 +1,8 @@ +json.id pipeline_stage.id +json.stage_name pipeline_stage.stage_name +json.stage_type pipeline_stage.stage_type +json.pipeline_id pipeline_stage.pipeline_id +json.show_index pipeline_stage.show_index +json.created_at pipeline_stage.created_at +json.updated_at pipeline_stage.updated_at + diff --git a/app/views/ci/pipelines/_list.json.jbuilder b/app/views/ci/pipelines/_list.json.jbuilder new file mode 100644 index 000000000..aab9ce142 --- /dev/null +++ b/app/views/ci/pipelines/_list.json.jbuilder @@ -0,0 +1,9 @@ +json.id pipeline.id +json.pipeline_name pipeline.pipeline_name +json.pipeline_status pipeline.pipeline_status +json.file_name pipeline.file_name +json.created_at pipeline.created_at +json.updated_at pipeline.updated_at +json.stages pipeline.pipeline_stages do |pipeline_stage| + json.partial! "/ci/pipeline_stages/list", pipeline_stage: pipeline_stage +end diff --git a/app/views/ci/pipelines/content.json.jbuilder b/app/views/ci/pipelines/content.json.jbuilder new file mode 100644 index 000000000..f7237bd33 --- /dev/null +++ b/app/views/ci/pipelines/content.json.jbuilder @@ -0,0 +1 @@ +json.content @yaml \ No newline at end of file diff --git a/app/views/ci/pipelines/list.json.jbuilder b/app/views/ci/pipelines/list.json.jbuilder new file mode 100644 index 000000000..7cfbeb1a6 --- /dev/null +++ b/app/views/ci/pipelines/list.json.jbuilder @@ -0,0 +1,3 @@ +json.pipelines @pipelines do |pipeline| + json.partial! "/ci/pipelines/list", pipeline: pipeline +end \ No newline at end of file diff --git a/app/views/ci/pipelines/stages.json.jbuilder b/app/views/ci/pipelines/stages.json.jbuilder new file mode 100644 index 000000000..c7a65ecfe --- /dev/null +++ b/app/views/ci/pipelines/stages.json.jbuilder @@ -0,0 +1,3 @@ +json.stages @pipeline_stages do |pipeline_stage| + json.partial! "/ci/pipeline_stages/list", pipeline_stage: pipeline_stage +end \ No newline at end of file diff --git a/app/views/ci/pipelines/steps.json.jbuilder b/app/views/ci/pipelines/steps.json.jbuilder new file mode 100644 index 000000000..31e8ca6ac --- /dev/null +++ b/app/views/ci/pipelines/steps.json.jbuilder @@ -0,0 +1,3 @@ +json.steps @pipeline_stage_steps do |pipeline_stage_step| + json.partial! "/ci/pipeline_stage_steps/list", pipeline_stage_step: pipeline_stage_step +end \ No newline at end of file diff --git a/app/views/ci/templates/_list.json.jbuilder b/app/views/ci/templates/_list.json.jbuilder new file mode 100644 index 000000000..1aff25a43 --- /dev/null +++ b/app/views/ci/templates/_list.json.jbuilder @@ -0,0 +1,8 @@ +json.id template.id +json.template_name template.template_name +json.stage_type template.stage_type +json.category template.category +json.content template.content +json.created_at template.created_at +json.updated_at template.updated_at + diff --git a/app/views/ci/templates/_templates_by_stage.json.jbuilder b/app/views/ci/templates/_templates_by_stage.json.jbuilder new file mode 100644 index 000000000..141e8d5bd --- /dev/null +++ b/app/views/ci/templates/_templates_by_stage.json.jbuilder @@ -0,0 +1,4 @@ +json.category category +json.templates templates do |template| + json.partial! "/ci/templates/list", template: template +end \ No newline at end of file diff --git a/app/views/ci/templates/list.json.jbuilder b/app/views/ci/templates/list.json.jbuilder new file mode 100644 index 000000000..3b463057b --- /dev/null +++ b/app/views/ci/templates/list.json.jbuilder @@ -0,0 +1,3 @@ +json.templates @templates do |template| + json.partial! "/ci/templates/list", template: template +end \ No newline at end of file diff --git a/app/views/ci/templates/templates_by_stage.json.jbuilder b/app/views/ci/templates/templates_by_stage.json.jbuilder new file mode 100644 index 000000000..898207941 --- /dev/null +++ b/app/views/ci/templates/templates_by_stage.json.jbuilder @@ -0,0 +1,3 @@ +json.array! @category_templates do |category, templates| + json.partial! "/ci/templates/templates_by_stage", category: category, templates: templates +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index c6282581b..f72d0ead3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,6 +31,31 @@ Rails.application.routes.draw do end end + resources :templates, only: [:list,:templates_by_stage,:create] do + collection do + get :list + get :templates_by_stage + end + end + + resources :pipelines do + collection do + get :list + end + member do + get :content + get :stages + post :create_stage + put :sort_stage + delete :delete_stage, :path => ":stage_id/delete_stage", to: 'pipelines#delete_stage' + 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' + 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 + end + # resources :repos, only: :index do # collection do # get 'get_trustie_pipeline', to: 'builds#get_trustie_pipeline', as: 'get_trustie_pipeline' diff --git a/db/migrate/20210108015318_create_ci_templates.rb b/db/migrate/20210108015318_create_ci_templates.rb new file mode 100644 index 000000000..80594513b --- /dev/null +++ b/db/migrate/20210108015318_create_ci_templates.rb @@ -0,0 +1,14 @@ +class CreateCiTemplates < ActiveRecord::Migration[5.2] + def change + create_table :ci_templates do |t| + t.string :template_name, null: false, comment: '模板名称' + t.string :stage_type, null: false, comment: '模板所属阶段类型:init/build/deploy/customize/confirm' + t.string :category, null: false, comment: '模板分类' + t.text :content, null: false, comment: '模板yml内容' + + t.timestamps + end + add_index :ci_templates, [:stage_type] + end +end + diff --git a/db/migrate/20210108055023_create_ci_pipelines.rb b/db/migrate/20210108055023_create_ci_pipelines.rb new file mode 100644 index 000000000..d14278208 --- /dev/null +++ b/db/migrate/20210108055023_create_ci_pipelines.rb @@ -0,0 +1,11 @@ +class CreateCiPipelines < ActiveRecord::Migration[5.2] + def change + create_table :ci_pipelines do |t| + t.string :pipeline_name, null: false, comment: '流水线名称' + t.string :pipeline_status, null: false, comment: 'successed/failed/running/errored/pending/killed/unknown' , default: 'unknown' + t.string :file_name, null: false, comment: '文件名称' + + t.timestamps + end + end +end diff --git a/db/migrate/20210108062016_create_ci_pipeline_stages.rb b/db/migrate/20210108062016_create_ci_pipeline_stages.rb new file mode 100644 index 000000000..8f7365a8e --- /dev/null +++ b/db/migrate/20210108062016_create_ci_pipeline_stages.rb @@ -0,0 +1,12 @@ +class CreateCiPipelineStages < ActiveRecord::Migration[5.2] + def change + create_table :ci_pipeline_stages do |t| + t.string :stage_name, null: false, comment: '阶段名称' + t.string :stage_type, null: false, comment: '阶段类型:init/build/deploy/customize/confirm' + t.integer :pipeline_id, null: false, comment: '阶段所属流水线id' + t.integer :show_index, null: false, comment: '阶段排序', default: 0 + + t.timestamps + end + end +end diff --git a/db/migrate/20210111013512_create_ci_pipeline_stage_steps.rb b/db/migrate/20210111013512_create_ci_pipeline_stage_steps.rb new file mode 100644 index 000000000..a4e38e132 --- /dev/null +++ b/db/migrate/20210111013512_create_ci_pipeline_stage_steps.rb @@ -0,0 +1,13 @@ +class CreateCiPipelineStageSteps < ActiveRecord::Migration[5.2] + def change + create_table :ci_pipeline_stage_steps do |t| + t.string :step_name, null: false, comment: '步骤名称' + t.integer :stage_id, null: false, comment: '阶段id' + t.integer :template_id, comment: '模板id' + t.text :content + t.integer :show_index, null: false, comment: '阶段排序', default: 0 + + t.timestamps + end + end +end From bcb4e78829d02d6a12d615f3c0cc6514c1cd89a8 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 12 Jan 2021 13:54:11 +0800 Subject: [PATCH 02/24] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ci/templates_controller.rb | 36 +++++++++++++++++-- app/models/ci/pipeline.rb | 2 +- app/models/ci/pipeline_stage.rb | 3 +- app/models/ci/pipeline_stage_step.rb | 2 +- config/routes.rb | 2 +- ...516_add_parent_category_to_ci_templates.rb | 5 +++ 6 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20210112053516_add_parent_category_to_ci_templates.rb diff --git a/app/controllers/ci/templates_controller.rb b/app/controllers/ci/templates_controller.rb index 4423bb402..c77a91445 100644 --- a/app/controllers/ci/templates_controller.rb +++ b/app/controllers/ci/templates_controller.rb @@ -6,15 +6,22 @@ class Ci::TemplatesController < ApplicationController def templates_by_stage stage_type = params[:stage_type] - @templates = Ci::Template.where("stage_type = ?", stage_type) - #根据模板类别分组 - @category_templates = @templates.group_by{ |template| template.category } + if stage_type != Ci::PipelineStage::CUSTOMIZE_STAGE_TYPE + @templates = Ci::Template.where("stage_type = ?", stage_type) + # 根据模板类别分组 + @category_templates = @templates.group_by{ |template| template.category } + else + # 自定义阶段,按阶段分类分类返回模板列表 + @templates = Ci::Template.where("stage_type != ?", Ci::PipelineStage::INIT_STAGE_TYPE) + @category_templates = @templates.group_by{ |template| template.parent_category } + end end def create template = Ci::Template.new(template_name: params[:template_name], stage_type: params[:stage_type], category: params[:category], + parent_category: params[:parent_category], content: params[:content] ) template.save! @@ -23,4 +30,27 @@ class Ci::TemplatesController < ApplicationController render_error(ex.message) end + def update + template = Ci::Template.find(params[:id]) + template.update!(template_name: params[:template_name], + stage_type: params[:stage_type], + category: params[:category], + parent_category: params[:parent_category], + content: params[:content] + ) + render_ok + rescue Exception => ex + render_error(ex.message) + end + + def destroy + template = Ci::Template.find(params[:id]) + if template + template.destroy! + end + render_ok + rescue Exception => ex + render_error(ex.message) + end + end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index f69b7e46d..c0c15838f 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -4,10 +4,10 @@ # # id :integer not null, primary key # pipeline_name :string(255) not null -# pipeline_status :integer default("0"), not null # file_name :string(255) not null # created_at :datetime not null # updated_at :datetime not null +# pipeline_status :string(50) default("unknown"), not null # class Ci::Pipeline < Ci::LocalBase diff --git a/app/models/ci/pipeline_stage.rb b/app/models/ci/pipeline_stage.rb index 3cf23ad99..b34c3e71b 100644 --- a/app/models/ci/pipeline_stage.rb +++ b/app/models/ci/pipeline_stage.rb @@ -20,5 +20,6 @@ class Ci::PipelineStage < Ci::LocalBase has_many :pipeline_stage_steps, -> { reorder(show_index: :asc) }, foreign_key: "stage_id", :class_name => 'Ci::PipelineStageStep', dependent: :destroy INIT_STAGES = {init:"初始化", build:"编译构建", deploy:"部署", confirm:"确认"}.freeze - + CUSTOMIZE_STAGE_TYPE = 'customize' + INIT_STAGE_TYPE = 'init' end diff --git a/app/models/ci/pipeline_stage_step.rb b/app/models/ci/pipeline_stage_step.rb index 2d7c8721b..5925d9085 100644 --- a/app/models/ci/pipeline_stage_step.rb +++ b/app/models/ci/pipeline_stage_step.rb @@ -7,7 +7,7 @@ # stage_id :integer not null # template_id :integer # content :text(65535) -# show_index :integer +# show_index :integer default("0"), not null # created_at :datetime not null # updated_at :datetime not null # diff --git a/config/routes.rb b/config/routes.rb index f72d0ead3..9b2f09d24 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,7 +31,7 @@ Rails.application.routes.draw do end end - resources :templates, only: [:list,:templates_by_stage,:create] do + resources :templates, only: [:list,:templates_by_stage,:create,:update,:destroy] do collection do get :list get :templates_by_stage diff --git a/db/migrate/20210112053516_add_parent_category_to_ci_templates.rb b/db/migrate/20210112053516_add_parent_category_to_ci_templates.rb new file mode 100644 index 000000000..16bcb4636 --- /dev/null +++ b/db/migrate/20210112053516_add_parent_category_to_ci_templates.rb @@ -0,0 +1,5 @@ +class AddParentCategoryToCiTemplates < ActiveRecord::Migration[5.2] + def change + add_column :ci_templates, :parent_category, :string + end +end From cb6c4b1e3f5f9f2da78b5e5d3d7f7d1fc6483205 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 12 Jan 2021 17:40:42 +0800 Subject: [PATCH 03/24] =?UTF-8?q?=E9=98=B6=E6=AE=B5=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E3=80=81=E5=88=A0=E9=99=A4=E3=80=81=E6=9F=A5=E8=AF=A2=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 205 ++++++++---------- app/controllers/ci/pipelines_controller.rb | 48 ++-- app/models/ci/pipeline_stage_step.rb | 2 +- .../pipeline_stage_steps/_list.json.jbuilder | 4 +- config/routes.rb | 1 - 5 files changed, 114 insertions(+), 146 deletions(-) diff --git a/api_document.md b/api_document.md index 4d8a6d5ba..b8376b325 100644 --- a/api_document.md +++ b/api_document.md @@ -3966,13 +3966,12 @@ http://localhost:3000/api/ci/pipelines/list.json | jq *返回参数说明:* -| 参数名 | 类型 | 说明 | -| ------------- | ------ | ---------------------------------------------- | -| id | int | 流水线id | -| pipeline_name | string | 流水线名称 | -| file_name | string | 流水线文件名 | -| created_at | string | 创建时间 | -| stages | arr | 流水线包含的阶段数组(字段详情看阶段查询接口) | +| 参数名 | 类型 | 说明 | +| ------------- | ------ | ------------ | +| id | int | 流水线id | +| pipeline_name | string | 流水线名称 | +| file_name | string | 流水线文件名 | +| created_at | string | 创建时间 | 返回值 @@ -3984,27 +3983,7 @@ http://localhost:3000/api/ci/pipelines/list.json | jq "pipeline_name": "2020-01-08 流水线", "file_name": ".trustie.pipeline.yaml", "created_at": "2021-01-08 04:16:24", - "updated_at": "2021-01-08 04:16:24", - "stages": [ - { - "id": 1, - "stage_name": "初始化", - "stage_type": "init", - "pipeline_id": 1, - "show_index": 0, - "created_at": "2021-01-08 04:16:24", - "updated_at": "2021-01-08 04:16:24" - }, - { - "id": 2, - "stage_name": "编译构建", - "stage_type": "build", - "pipeline_id": 1, - "show_index": 1, - "created_at": "2021-01-08 04:16:24", - "updated_at": "2021-01-11 04:16:24" - } - ] + "updated_at": "2021-01-08 04:16:24" } ] } @@ -4014,8 +3993,6 @@ http://localhost:3000/api/ci/pipelines/list.json | jq #### 流水线新增 -点击"新增流水线"按钮时调用。 - ``` POST /api/ci/pipelines ``` @@ -4035,22 +4012,24 @@ curl --location --request POST 'http://localhost:3000/api/ci/pipelines' \ | 参数名 | 必选 | 类型 | 说明 | | ------------- | ---- | ------ | ---------------------------------------------- | -| pipeline_name | 是 | string | 流水线名称(默认初始值:流水线 yyyy-mm-dd) | +| pipeline_name | 是 | string | 流水线名称 | | file_name | 是 | string | 文件名称(默认初始值:.trustie.pipeline.yaml) | *返回参数说明:* -| 参数名 | 类型 | 说明 | -| ------- | ------ | ------------ | -| status | int | 状态码 0成功 | -| message | string | 返回消息 | +| 参数名 | 类型 | 说明 | +| ------- | ------ | -------------- | +| status | int | 状态码 0成功 | +| message | string | 返回消息 | +| id | int | 新增流水线的id | 返回值 ```json { "status": 0, - "message": "success" + "message": "success", + "id": 18 } ``` @@ -4136,56 +4115,64 @@ https://localhost:3000/api/ci/pipelines/1 | jq ------ -#### 流水线阶段排序 - -当新增阶段或者删除阶段时重新给受影响的stage设置show_index。 +#### 流水线的阶段查询 ``` -PUT /api/ci/pipelines/{id}/sort_stage +GET /api/ci/pipelines/{id}/stages ``` *示例* ```bash -curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/sort_stage.json' \ ---header 'Content-Type: application/json' \ ---data-raw ' {"stage_index":[ - {"id": 1,"show_index": 0}, - {"id": 2,"show_index": 1}, - {"id": 3,"show_index": 2}, - {"id": 4,"show_index": 3}, - {"id": 7,"show_index": 4} - ] - }' +curl --location --request GET 'http://localhost:3000/api/ci/pipelines/19/stages.json' ``` *请求参数说明:* -| 参数名 | 必选 | 类型 | 说明 | -| ----------- | ---- | ---- | ---------- | -| stage_index | 是 | arr | 参数数组 | -| id | 是 | int | 阶段id | -| show_index | 是 | int | 阶段的序号 | +| 参数名 | 必选 | 类型 | 说明 | +| ------ | ---- | ---- | -------- | +| id | 是 | int | 流水线id | *返回参数说明:* -| 参数名 | 类型 | 说明 | -| ------- | ------ | ------------ | -| status | int | 状态码 0成功 | -| message | string | 返回消息 | +| 参数名 | 类型 | 说明 | +| ----------- | ------ | -------- | +| stages | arr | 阶段数组 | +| stage_name | string | 阶段名称 | +| stage_type | string | 阶段类型 | +| pipeline_id | int | 流水线id | +| show_index | int | 排序 | 返回值 ```json { - "status": 0, - "message": "success" + "stages": [ + { + "id": 37, + "stage_name": "初始化", + "stage_type": "init", + "pipeline_id": 19, + "show_index": 1, + "created_at": "2021-01-12T15:18:00.000+08:00", + "updated_at": "2021-01-12T15:18:00.000+08:00" + }, + { + "id": 38, + "stage_name": "编译构建", + "stage_type": "build", + "pipeline_id": 19, + "show_index": 2, + "created_at": "2021-01-12T15:18:00.000+08:00", + "updated_at": "2021-01-12T15:18:00.000+08:00" + } + ] } ``` ------ -#### 确认阶段流水线内容查询 +#### 确认阶段流水线完整内容查询 ``` GET /api/ci/pipelines/{id}/content @@ -4223,30 +4210,21 @@ POST /api/ci/pipelines/{id}/create_stage *示例* ```bash -curl --location --request POST 'http://localhost:3000/api/ci/pipelines/14/create_stage.json' \ +curl --location --request POST 'http://localhost:3000/api/ci/pipelines/19/create_stage.json' \ --header 'Content-Type: application/json' \ ---data-raw ' {"stages":[{ - "stage_name": "新阶段1", - "stage_type": "customize", - "show_index": 5 -}, -{ +--data-raw '{ "stage_name": "新阶段2", - "stage_type": "customize", - "show_index": 5 -} -] - }' + "show_index": 2 +}' ``` *请求参数说明:* -| 参数名 | 必选 | 类型 | 说明 | -| ---------- | ---- | ------ | -------------------------------- | -| stages | 是 | arr | 新增的阶段数组 | -| id | 是 | int | 流水线id | -| stage_name | 是 | string | 阶段名称(默认为 阶段名-模板名) | -| show_index | 是 | int | 阶段排序 | +| 参数名 | 必选 | 类型 | 说明 | +| ---------- | ---- | ------ | -------- | +| id | 是 | int | 流水线id | +| show_index | 是 | int | 阶段排序 | +| stage_name | 是 | string | 阶段名称 | *返回参数说明:* @@ -4269,7 +4247,7 @@ curl --location --request POST 'http://localhost:3000/api/ci/pipelines/14/create #### 流水线阶段更新 ``` -PUT /api/ci/pipelines/{id}/update_stage +PUT /api/ci/pipelines/{id}/{stage_id}/update_stage ``` *示例* @@ -4278,9 +4256,7 @@ PUT /api/ci/pipelines/{id}/update_stage curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/5/update_stage.json' \ --header 'Content-Type: application/json' \ --data-raw ' { - "stage_name": "新阶段-更新", - "stage_type": "customize", - "show_index": 10 + "stage_name": "新阶段-更新" }' ``` @@ -4290,7 +4266,6 @@ curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/5/update | ---------- | ---- | ------ | -------------------------------- | | id | 是 | int | 流水线id | | stage_name | 是 | string | 阶段名称(默认为 阶段名-模板名) | -| show_index | 是 | int | 阶段排序 | *返回参数说明:* @@ -4313,22 +4288,22 @@ curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/5/update #### 流水线阶段删除 ``` -DELETE /api/ci/pipelines/{id}/{stage_id}/delete_stage +DELETE /api/ci/pipelines/{id}/{stage_id}/delete_stage?show_index={index} ``` *示例* ```bash -curl -X DELETE \ -https://localhost:3000/api/ci/pipelines/1/6/delete_stage.json | jq +curl --location --request DELETE 'http://localhost:3000/api/ci/pipelines/19/42/delete_stage.json?show_index=2' \ ``` *请求参数说明:* -| 参数名 | 必选 | 类型 | 说明 | -| -------- | ---- | ---- | -------- | -| id | 是 | int | 流水线id | -| stage_id | 是 | int | 阶段id | +| 参数名 | 必选 | 类型 | 说明 | +| ---------- | ---- | ---- | ---------------------- | +| id | 是 | int | 流水线id | +| stage_id | 是 | int | 阶段id | +| show_index | 是 | int | 被删除阶段的show_index | *返回参数说明:* @@ -4370,14 +4345,14 @@ http://localhost:3000/api/ci/pipelines/1/2/steps.json | jq *返回参数说明:* -| 参数名 | 类型 | 说明 | -| ----------- | ------ | ---------- | -| id | int | 步骤id | -| step_name | string | 步骤名称 | -| stage_id | int | 所属阶段id | -| template_id | int | 模板id | -| show_index | int | 显示顺序 | -| content | String | 步骤内容 | +| 参数名 | 类型 | 说明 | +| ---------- | ------ | ------------------ | +| id | int | 步骤id | +| step_name | string | 步骤名称 | +| stage_id | int | 所属阶段id | +| show_index | int | 显示顺序 | +| content | String | 步骤内容 | +| template | Object | 步骤对应的模板对象 | 返回值 @@ -4388,21 +4363,19 @@ http://localhost:3000/api/ci/pipelines/1/2/steps.json | jq "id": 1, "step_name": "编译构建-maven", "stage_id": 2, - "template_id": null, "show_index": 0, - "content": "xxxxxxxxxxx", + "content": "- name: Maven编译\r\n image: arm64v8/maven\r\n", "created_at": "2021-01-11T09:57:17.000+08:00", - "updated_at": "2021-01-11T09:57:17.000+08:00" - }, - { - "id": 2, - "step_name": "编译构建-maven-更新", - "stage_id": 2, - "template_id": 2, - "show_index": 2, - "content": "xxxx====xxxxxxx", - "created_at": "2021-01-11T10:12:58.000+08:00", - "updated_at": "2021-01-11T10:40:54.000+08:00" + "updated_at": "2021-01-11T09:57:17.000+08:00", + "template": { + "id": 3, + "template_name": "maven", + "stage_type": "build", + "category": "java", + "content": "- name: maven\r\n image: maven:3-jdk-10\r\n", + "created_at": "2021-01-11T17:28:34.000+08:00", + "updated_at": "2021-01-11T17:28:36.000+08:00" + } } ] } @@ -4578,9 +4551,9 @@ http://localhost:3000/api/ci/templates/templates_by_stage.json?stage_type=build *请求参数说明:* -| 参数名 | 必选 | 类型 | 说明 | -| ---------- | ---- | ------ | --------------------------------------------- | -| stage_type | 是 | string | 阶段类型:init/build/deploy/customize/confirm | +| 参数名 | 必选 | 类型 | 说明 | +| ---------- | ---- | ------ | ------------------------------------- | +| stage_type | 是 | string | 阶段类型:init/build/deploy/customize | *返回参数说明:* diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 0ac53d80a..28b6029b7 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -12,7 +12,7 @@ class Ci::PipelinesController < ApplicationController # 默认创建四个初始阶段 init_stages = Ci::PipelineStage::INIT_STAGES - index = 0 + index = 1 init_stages.each do |type, name| pipeline.pipeline_stages.build( stage_name: name, @@ -21,7 +21,7 @@ class Ci::PipelinesController < ApplicationController ).save! index += 1 end - render_ok + render_ok({id: pipeline.id}) end rescue Exception => ex render_error(ex.message) @@ -74,15 +74,12 @@ class Ci::PipelinesController < ApplicationController def create_stage ActiveRecord::Base.transaction do - stages = params[:stages] - unless stages.empty? - stages.each do |stage| - pipeline_stage = Ci::PipelineStage.new(stage_name: stage[:stage_name], - stage_type: stage[:stage_type].blank? ? 'customize' : stage[:stage_type], - pipeline_id: params[:id], show_index: stage[:show_index]) - pipeline_stage.save! - end - end + # 修改stage排序 + update_stage_index(params[:id], params[:show_index], 1) + pipeline_stage = Ci::PipelineStage.new(stage_name: params[:stage_name], + stage_type: params[:stage_type].blank? ? 'customize' : params[:stage_type], + pipeline_id: params[:id], show_index: params[:show_index]) + pipeline_stage.save! render_ok end rescue Exception => ex @@ -92,7 +89,7 @@ class Ci::PipelinesController < ApplicationController def update_stage pipeline_stage = Ci::PipelineStage.find(params[:stage_id]) if pipeline_stage - pipeline_stage.update!(stage_name: params[:stage_name], show_index: params[:show_index]) + pipeline_stage.update!(stage_name: params[:stage_name]) end render_ok rescue Exception => ex @@ -100,28 +97,25 @@ class Ci::PipelinesController < ApplicationController end def delete_stage - pipeline_stage = Ci::PipelineStage.find(params[:stage_id]) - if pipeline_stage - pipeline_stage.destroy! + ActiveRecord::Base.transaction do + update_stage_index(params[:id], params[:show_index].to_i, -1) + pipeline_stage = Ci::PipelineStage.find(params[:stage_id]) + if pipeline_stage + pipeline_stage.destroy! + end + render_ok end - render_ok rescue Exception => ex render_error(ex.message) end - def sort_stage - stages = params[:stage_index] - if stages && !stages.empty? - stages.each do |stage| - pipeline_stage = Ci::PipelineStage.find(stage[:id]) - if pipeline_stage - pipeline_stage.update!(show_index: stage[:show_index]) - end + def update_stage_index(pipeline_id, show_index, diff) + stages = Ci::Pipeline.find(pipeline_id).pipeline_stages + stages.each do |stage| + if stage.show_index >= show_index + stage.update!(show_index: stage.show_index + diff) end end - render_ok - rescue Exception => ex - render_error(ex.message) end # ========步骤相关接口========= # diff --git a/app/models/ci/pipeline_stage_step.rb b/app/models/ci/pipeline_stage_step.rb index 5925d9085..48a6b3324 100644 --- a/app/models/ci/pipeline_stage_step.rb +++ b/app/models/ci/pipeline_stage_step.rb @@ -18,5 +18,5 @@ class Ci::PipelineStageStep < Ci::LocalBase validates :stage_id, presence: {message: "阶段id不能为空"} belongs_to :pipeline_stage, foreign_key: :stage_id, :class_name => 'Ci::PipelineStage' - has_one :template, :class_name => 'Ci::Template', foreign_key: :template_id + end diff --git a/app/views/ci/pipeline_stage_steps/_list.json.jbuilder b/app/views/ci/pipeline_stage_steps/_list.json.jbuilder index a3d592fbd..98acdc527 100644 --- a/app/views/ci/pipeline_stage_steps/_list.json.jbuilder +++ b/app/views/ci/pipeline_stage_steps/_list.json.jbuilder @@ -1,9 +1,11 @@ json.id pipeline_stage_step.id json.step_name pipeline_stage_step.step_name json.stage_id pipeline_stage_step.stage_id -json.template_id pipeline_stage_step.template_id json.show_index pipeline_stage_step.show_index json.content pipeline_stage_step.content json.created_at pipeline_stage_step.created_at json.updated_at pipeline_stage_step.updated_at +json.template do + json.partial! "/ci/templates/list", template: Ci::Template.find(pipeline_stage_step.template_id) +end diff --git a/config/routes.rb b/config/routes.rb index 9b2f09d24..4de53af52 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,7 +46,6 @@ Rails.application.routes.draw do get :content get :stages post :create_stage - put :sort_stage delete :delete_stage, :path => ":stage_id/delete_stage", to: 'pipelines#delete_stage' put :update_stage, :path => ":stage_id/update_stage", to: 'pipelines#update_stage' get :stage_steps, :path => ":stage_id/steps", to: 'pipelines#steps' From da1a992670da01d92ebd56b892e1cc13910c4dd7 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Wed, 13 Jan 2021 15:10:24 +0800 Subject: [PATCH 04/24] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E8=BF=94=E5=9B=9E=E6=97=B6=E9=97=B4=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/ci/pipelines/_list.json.jbuilder | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/views/ci/pipelines/_list.json.jbuilder b/app/views/ci/pipelines/_list.json.jbuilder index aab9ce142..6e091bf28 100644 --- a/app/views/ci/pipelines/_list.json.jbuilder +++ b/app/views/ci/pipelines/_list.json.jbuilder @@ -2,8 +2,5 @@ json.id pipeline.id json.pipeline_name pipeline.pipeline_name json.pipeline_status pipeline.pipeline_status json.file_name pipeline.file_name -json.created_at pipeline.created_at -json.updated_at pipeline.updated_at -json.stages pipeline.pipeline_stages do |pipeline_stage| - json.partial! "/ci/pipeline_stages/list", pipeline_stage: pipeline_stage -end +json.created_at pipeline.created_at.strftime("%Y-%m-%d %H:%M:%S") +json.updated_at pipeline.updated_at.strftime("%Y-%m-%d %H:%M:%S") From 4ac763403167331f215b9ad1ebcbe316794ec16a Mon Sep 17 00:00:00 2001 From: moshenglv Date: Thu, 14 Jan 2021 15:32:49 +0800 Subject: [PATCH 05/24] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=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 b8376b325..3c6129086 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 28b6029b7..4cd7cf626 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 4de53af52..1281d16b9 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 From a71f0b05507351ffa3cdaeeb4ff79eab8121003c Mon Sep 17 00:00:00 2001 From: moshenglv Date: Thu, 14 Jan 2021 15:34:35 +0800 Subject: [PATCH 06/24] =?UTF-8?q?=E9=98=B6=E6=AE=B5=E6=AD=A5=E9=AA=A4?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/api_document.md b/api_document.md index 3c6129086..cd2841748 100644 --- a/api_document.md +++ b/api_document.md @@ -4386,13 +4386,13 @@ http://localhost:3000/api/ci/pipelines/1/2/steps.json | jq #### 流水线阶段步骤新增/更新 ``` -PUT /api/ci/pipelines/{id}/{stage_id}/stage_step +POST /api/ci/pipelines/{id}/{stage_id}/stage_step ``` *示例* ```bash -curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/2/stage_step.json' \ +curl --location --request POST 'http://localhost:3000/api/ci/pipelines/1/2/stage_step.json' \ --header 'Content-Type: application/json' \ --data-raw ' {"steps":[{ "id":7, @@ -4400,13 +4400,6 @@ curl --location --request PUT 'http://localhost:3000/api/ci/pipelines/1/2/stage_ "show_index": 1, "content": "xxxxxxxxxxx", "template_id":2 -}, -{ - "id":8, - "step_name": "编译构建22-maven", - "show_index": 1, - "content": "xxxxxxxxxxx", - "template_id":2 } ] }' From ac6858a20511a559a08f24e52cb1e5f66537b53a Mon Sep 17 00:00:00 2001 From: moshenglv Date: Thu, 14 Jan 2021 15:36:22 +0800 Subject: [PATCH 07/24] =?UTF-8?q?=E9=98=B6=E6=AE=B5=E6=AD=A5=E9=AA=A4?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/api_document.md b/api_document.md index cd2841748..db0789076 100644 --- a/api_document.md +++ b/api_document.md @@ -4407,14 +4407,15 @@ curl --location --request POST 'http://localhost:3000/api/ci/pipelines/1/2/stage *请求参数说明:* -| 参数名 | 必选 | 类型 | 说明 | -| ----------- | ---- | ------ | -------------------------------- | -| steps | 是 | arr | 需要更新step数组 | -| id | 是 | int | 流水线id | -| step_id | 是 | int | 阶段id(存在则更新,不存在新增) | -| step_name | 是 | string | 阶段名称(阶段名-模板名) | -| content | 是 | string | 步骤内容 | -| template_id | 是 | int | 模板id | +| 参数名 | 必选 | 类型 | 说明 | +| ---------------- | ---- | ------ | -------------------------------- | +| steps | 是 | arr | 需要更新step数组 | +| id | 是 | int | 流水线id | +| stage_id | 是 | int | 阶段id | +| id(数组中的id) | 否 | int | 步骤id(存在则更新,不存在新增) | +| step_name | 是 | string | 阶段名称(阶段名-模板名) | +| content | 是 | string | 步骤内容 | +| template_id | 是 | int | 模板id | *返回参数说明:* From 9af0ff4a718025875dcbe6a54b4b613fd76dc216 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Fri, 15 Jan 2021 11:05:38 +0800 Subject: [PATCH 08/24] =?UTF-8?q?=E6=AD=A5=E9=AA=A4=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E6=A8=A1=E6=9D=BF=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/ci/pipeline_stage_steps/_list.json.jbuilder | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/ci/pipeline_stage_steps/_list.json.jbuilder b/app/views/ci/pipeline_stage_steps/_list.json.jbuilder index 98acdc527..904df8341 100644 --- a/app/views/ci/pipeline_stage_steps/_list.json.jbuilder +++ b/app/views/ci/pipeline_stage_steps/_list.json.jbuilder @@ -3,9 +3,9 @@ json.step_name pipeline_stage_step.step_name json.stage_id pipeline_stage_step.stage_id json.show_index pipeline_stage_step.show_index json.content pipeline_stage_step.content +json.template_id pipeline_stage_step.template_id +json.category Ci::Template.find(pipeline_stage_step.template_id).category json.created_at pipeline_stage_step.created_at json.updated_at pipeline_stage_step.updated_at -json.template do - json.partial! "/ci/templates/list", template: Ci::Template.find(pipeline_stage_step.template_id) -end + From 2d99713cd0caa021dc3e00590358b29c7d850c4c Mon Sep 17 00:00:00 2001 From: moshenglv Date: Mon, 18 Jan 2021 09:32:23 +0800 Subject: [PATCH 09/24] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=94=A8=E6=88=B7=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ci/pipelines_controller.rb | 9 ++++++--- app/models/ci/pipeline.rb | 1 + app/models/ci/template.rb | 15 ++++++++------- .../20210118011710_add_login_to_ci_pipelines.rb | 5 +++++ 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20210118011710_add_login_to_ci_pipelines.rb diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 4cd7cf626..43b58e4c0 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -1,13 +1,16 @@ -class Ci::PipelinesController < ApplicationController +class Ci::PipelinesController < Ci::BaseController + + before_action :require_login, only: %i[list create] + skip_before_action :connect_to_ci_db # ======流水线相关接口========== # def list - @pipelines = Ci::Pipeline.all + @pipelines = Ci::Pipeline.where('login=?', current_user.login) end def create ActiveRecord::Base.transaction do - pipeline = Ci::Pipeline.new(pipeline_name: params[:pipeline_name], file_name: params[:file_name]) + pipeline = Ci::Pipeline.new(pipeline_name: params[:pipeline_name], file_name: params[:file_name], login: current_user.login) pipeline.save! # 默认创建四个初始阶段 diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index c0c15838f..842290d8c 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -8,6 +8,7 @@ # created_at :datetime not null # updated_at :datetime not null # pipeline_status :string(50) default("unknown"), not null +# login :string(255) # class Ci::Pipeline < Ci::LocalBase diff --git a/app/models/ci/template.rb b/app/models/ci/template.rb index 34aab41df..e7be34a3b 100644 --- a/app/models/ci/template.rb +++ b/app/models/ci/template.rb @@ -2,13 +2,14 @@ # # Table name: ci_templates # -# id :integer not null, primary key -# template_name :string(255) not null -# stage_type :string(255) not null -# category :string(255) not null -# content :text(65535) not null -# created_at :datetime not null -# updated_at :datetime not null +# id :integer not null, primary key +# template_name :string(255) not null +# stage_type :string(255) not null +# category :string(255) not null +# content :text(65535) not null +# created_at :datetime not null +# updated_at :datetime not null +# parent_category :string(255) # # Indexes # diff --git a/db/migrate/20210118011710_add_login_to_ci_pipelines.rb b/db/migrate/20210118011710_add_login_to_ci_pipelines.rb new file mode 100644 index 000000000..e1e914e5e --- /dev/null +++ b/db/migrate/20210118011710_add_login_to_ci_pipelines.rb @@ -0,0 +1,5 @@ +class AddLoginToCiPipelines < ActiveRecord::Migration[5.2] + def change + add_column :ci_pipelines, :login, :string + end +end From c6aeecb33cab9001885c8792c364a60fd7e03b55 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Mon, 18 Jan 2021 09:58:33 +0800 Subject: [PATCH 10/24] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=98=B6=E6=AE=B5?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ci/pipelines_controller.rb | 4 ++-- app/views/ci/pipeline_stages/_list.json.jbuilder | 1 + app/views/ci/pipelines/stages.json.jbuilder | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 43b58e4c0..253d399d0 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -72,6 +72,7 @@ class Ci::PipelinesController < Ci::BaseController # =========阶段相关接口========= # def stages pipeline_id = params[:id] + @pipeline_name = Ci::Pipeline.find(pipeline_id).pipeline_name @pipeline_stages = Ci::PipelineStage.where('pipeline_id=?', pipeline_id).order('show_index asc') end @@ -171,8 +172,7 @@ class Ci::PipelinesController < Ci::BaseController steps.each do |step| pipeline_stage_step = Ci::PipelineStageStep.find(step[:id]) if pipeline_stage_step - pipeline_stage_step.update(step_name: step[:step_name], content: step[:content], - show_index: step[:show_index], template_id: step[:template_id]) + pipeline_stage_step.update(step_name: step[:step_name], content: step[:content], template_id: step[:template_id]) end end end diff --git a/app/views/ci/pipeline_stages/_list.json.jbuilder b/app/views/ci/pipeline_stages/_list.json.jbuilder index 1e782ee40..a0c8b314f 100644 --- a/app/views/ci/pipeline_stages/_list.json.jbuilder +++ b/app/views/ci/pipeline_stages/_list.json.jbuilder @@ -2,6 +2,7 @@ json.id pipeline_stage.id json.stage_name pipeline_stage.stage_name json.stage_type pipeline_stage.stage_type json.pipeline_id pipeline_stage.pipeline_id +json.pipeline_name pipeline_name json.show_index pipeline_stage.show_index json.created_at pipeline_stage.created_at json.updated_at pipeline_stage.updated_at diff --git a/app/views/ci/pipelines/stages.json.jbuilder b/app/views/ci/pipelines/stages.json.jbuilder index c7a65ecfe..74f27358a 100644 --- a/app/views/ci/pipelines/stages.json.jbuilder +++ b/app/views/ci/pipelines/stages.json.jbuilder @@ -1,3 +1,3 @@ json.stages @pipeline_stages do |pipeline_stage| - json.partial! "/ci/pipeline_stages/list", pipeline_stage: pipeline_stage + json.partial! "/ci/pipeline_stages/list", pipeline_stage: pipeline_stage, pipeline_name: @pipeline_name end \ No newline at end of file From 5e0cdba1f9f80334609c2a544f489ace8fd7306a Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 11:03:27 +0800 Subject: [PATCH 11/24] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E4=B8=8E?= =?UTF-8?q?=E9=A1=B9=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 From 05416339e5c1d26fef598edffcf93edef8e2c3f1 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 11:10:47 +0800 Subject: [PATCH 12/24] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E8=BF=94=E5=9B=9E=E5=AD=97=E6=AE=B5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/ci/pipeline.rb | 2 ++ app/views/ci/pipelines/_list.json.jbuilder | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 842290d8c..ffbb42ebe 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -9,6 +9,8 @@ # updated_at :datetime not null # pipeline_status :string(50) default("unknown"), not null # login :string(255) +# sync :integer default("0"), not null +# project_id :integer # class Ci::Pipeline < Ci::LocalBase diff --git a/app/views/ci/pipelines/_list.json.jbuilder b/app/views/ci/pipelines/_list.json.jbuilder index 6e091bf28..c59e925f3 100644 --- a/app/views/ci/pipelines/_list.json.jbuilder +++ b/app/views/ci/pipelines/_list.json.jbuilder @@ -2,5 +2,7 @@ json.id pipeline.id json.pipeline_name pipeline.pipeline_name json.pipeline_status pipeline.pipeline_status json.file_name pipeline.file_name +json.sync pipeline.sync +json.project_id pipeline.project_id json.created_at pipeline.created_at.strftime("%Y-%m-%d %H:%M:%S") json.updated_at pipeline.updated_at.strftime("%Y-%m-%d %H:%M:%S") From f90bc0897bf898b4acccb890527087afc21605bf Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 11:52:29 +0800 Subject: [PATCH 13/24] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=85=B3?= =?UTF-8?q?=E8=81=94=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 12 ++++++------ app/controllers/ci/pipelines_controller.rb | 4 ++-- app/controllers/ci/projects_controller.rb | 8 -------- app/controllers/repositories_controller.rb | 11 +++++++++++ app/views/ci/pipelines/_list.json.jbuilder | 2 +- ...025745_add_sync_and_project_id_to_ci_pipelines.rb | 2 +- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/api_document.md b/api_document.md index 50d9ec584..3b35c82a2 100644 --- a/api_document.md +++ b/api_document.md @@ -3283,9 +3283,10 @@ http://localhost:3000/api/jasder/forge/get_trustie_pipeline.json | jq #### 更新'.trustie-pipeline.yml'文件 ``` -PUT /api/:owner/:repo/update_trustie_pipeline?pipeline_id={pipeline_id} +PUT /api/:owner/:repo/update_trustie_pipeline ``` *示例* + ```bash curl -X GET \ http://localhost:3000/api/jasder/forge/update_trustie_pipeline.json?pipeline_id=1 | jq @@ -3305,7 +3306,6 @@ http://localhost:3000/api/jasder/forge/update_trustie_pipeline.json?pipeline_id= |branch |否|string |分支名称, branch和new_branch必须存在一个,且只能存在一个 | |new_branch |否|string |新的分支名称 | |ci_language_id |否|string |新的分支名称 | -|pipeline_id |是|int |流水线id | *返回参数说明:* @@ -3955,14 +3955,14 @@ https://localhost:3000/api/users/ci/cloud_account/bind.json | jq #### 流水线查询 ``` -GET /api/ci/pipelines/list?project_id={project_id} +GET /api/ci/pipelines/list?identifier={identifier} ``` *示例* ```bash curl -X GET \ -http://localhost:3000/api/ci/pipelines/list.json?project_id=1 | jq +http://localhost:3000/api/ci/pipelines/list.json?identifier="xxx" | jq ``` *返回参数说明:* @@ -4007,7 +4007,7 @@ curl --location --request POST 'http://localhost:3000/api/ci/pipelines' \ --data-raw ' { "pipeline_name": "流水线 2021-01-12", "file_name": ".trustie.pipeline.yaml", - "project_id": 1 + "identifier": "xxx" }' ``` @@ -4017,7 +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 | +| identifier | 是 | string | 项目identifier | *返回参数说明:* diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index b6abecb44..27641448c 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=? and project_id=?', current_user.login, params[:project_id]) + @pipelines = Ci::Pipeline.where('login=? and identifier=?', current_user.login, params[:identifier]) 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, project_id: params[:project_id]) + pipeline = Ci::Pipeline.new(pipeline_name: params[:pipeline_name], file_name: params[:file_name], login: current_user.login, identifier: params[:identifier]) pipeline.save! # 默认创建四个初始阶段 diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index 55645ed44..c7b7338f1 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -28,20 +28,12 @@ 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/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index b4d142282..c189bf24c 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -94,11 +94,22 @@ class RepositoriesController < ApplicationController if interactor.success? @file = interactor.result # create_new_pr(params) + #如果是更新流水线文件 + if params[:pipeline_id] + update_pipeline(params[:pipeline_id]) + end 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 update_file interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, params.merge(identifier: @project.identifier)) if interactor.success? diff --git a/app/views/ci/pipelines/_list.json.jbuilder b/app/views/ci/pipelines/_list.json.jbuilder index c59e925f3..0113da58d 100644 --- a/app/views/ci/pipelines/_list.json.jbuilder +++ b/app/views/ci/pipelines/_list.json.jbuilder @@ -3,6 +3,6 @@ json.pipeline_name pipeline.pipeline_name json.pipeline_status pipeline.pipeline_status json.file_name pipeline.file_name json.sync pipeline.sync -json.project_id pipeline.project_id +json.identifier pipeline.identifier json.created_at pipeline.created_at.strftime("%Y-%m-%d %H:%M:%S") json.updated_at pipeline.updated_at.strftime("%Y-%m-%d %H:%M:%S") 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 index 617731ac2..e0d0d2503 100644 --- 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 @@ -1,6 +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 + add_column :ci_pipelines, :identifier, :string end end \ No newline at end of file From 703be3f9a15f0905a89f6b4e7a1f8c2cf56d9ffa Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 13:59:55 +0800 Subject: [PATCH 14/24] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E5=86=85=E5=AE=B9=E5=90=8C=E6=AD=A5=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 10 ++++++---- app/controllers/ci/pipelines_controller.rb | 4 +++- app/views/ci/pipelines/content.json.jbuilder | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/api_document.md b/api_document.md index 3b35c82a2..f58f6f1ff 100644 --- a/api_document.md +++ b/api_document.md @@ -4191,15 +4191,17 @@ http://localhost:3000/api/ci/pipelines/1/content.json | jq *返回参数说明:* -| 参数名 | 类型 | 说明 | -| ------ | ---- | -------- | -| id | int | 流水线id | +| 参数名 | 类型 | 说明 | +| ------- | ------ | ---------- | +| content | String | 流水线内容 | +| sync | int | 同步状态 | 返回值 ```json { - "content": "#pipeline \nkind: pipeline\r\nname: maven项目-镜像仓库\r\n\r\nplatform:\r\n os: linux\r\n arch: arm64\nsteps:\n- name: Maven编译\r\n image: arm64v8/maven\r\n commands:\r\n - mvn install\n- name: 编译镜像-推送到仓库\r\n image: plugins/docker\r\n settings:\r\n username: moshenglv\r\n password: RL9UB5P7Jtzukka\r\n repo: docker.io/moshenglv/demo\r\n tags: latest\n" + "content": "#pipeline \nkind: pipeline\r\nname: maven项目-镜像仓库\r\n\r\nplatform:\r\n os: linux\r\n arch: arm64\nsteps:\n- name: Maven编译\r\n image: arm64v8/maven\r\n commands:\r\n - mvn install\n- name: 编译镜像-推送到仓库\r\n image: plugins/docker\r\n settings:\r\n username: moshenglv\r\n password: RL9UB5P7Jtzukka\r\n repo: docker.io/moshenglv/demo\r\n tags: latest\n", + "sync": 1 } ``` diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 27641448c..9add4cb45 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -52,7 +52,9 @@ class Ci::PipelinesController < Ci::BaseController def content @yaml = "#pipeline \n" - stages = Ci::Pipeline.find(params[:id]).pipeline_stages + pipeline = Ci::Pipeline.find(params[:id]) + @sync = pipeline.sync + stages = pipeline.pipeline_stages if stages && !stages.empty? init_step = stages.first.pipeline_stage_steps.first @yaml += init_step.content + "\n" + "steps:\n" diff --git a/app/views/ci/pipelines/content.json.jbuilder b/app/views/ci/pipelines/content.json.jbuilder index f7237bd33..e532dd57c 100644 --- a/app/views/ci/pipelines/content.json.jbuilder +++ b/app/views/ci/pipelines/content.json.jbuilder @@ -1 +1,2 @@ -json.content @yaml \ No newline at end of file +json.content @yaml +json.sync @sync \ No newline at end of file From 1001d10017daa636728a17517351b8b85da69c44 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 14:00:22 +0800 Subject: [PATCH 15/24] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/ci/pipeline.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index ffbb42ebe..9448512b7 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -16,6 +16,7 @@ class Ci::Pipeline < Ci::LocalBase validates :pipeline_name, presence: {message: "流水线名称不能为空"} validates :file_name, presence: {message: "流水线文件名称不能为空"} + validates :identifier, presence: {message: "项目identifier不能为空"} has_many :pipeline_stages, -> { reorder(show_index: :asc) }, foreign_key: "pipeline_id", :class_name => 'Ci::PipelineStage', dependent: :destroy From 7e9acd18503acd8f58c384042a193990e5104d4f Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 14:19:06 +0800 Subject: [PATCH 16/24] =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E6=96=87=E4=BB=B6sha?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 14 ++++++++------ app/controllers/ci/pipelines_controller.rb | 13 +++++++++++++ app/views/ci/pipelines/content.json.jbuilder | 3 ++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/api_document.md b/api_document.md index f58f6f1ff..3c6c90fd1 100644 --- a/api_document.md +++ b/api_document.md @@ -4179,22 +4179,24 @@ curl --location --request GET 'http://localhost:3000/api/ci/pipelines/19/stages. #### 确认阶段流水线完整内容查询 ``` -GET /api/ci/pipelines/{id}/content +GET /api/ci/pipelines/{id}/content?owner={owner}&repo={repo} ``` *示例* ```bash curl -X GET \ -http://localhost:3000/api/ci/pipelines/1/content.json | jq +http://localhost:3000/api/ci/pipelines/1/content.json?owner=xx&repo=xx | jq ``` *返回参数说明:* -| 参数名 | 类型 | 说明 | -| ------- | ------ | ---------- | -| content | String | 流水线内容 | -| sync | int | 同步状态 | +| 参数名 | 类型 | 说明 | +| ------- | ------ | ---------------- | +| content | String | 流水线内容 | +| sync | int | 同步状态 | +| owner | string | 用户登录名 | +| repo | string | 项目的identifier | 返回值 diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 9add4cb45..371f062b6 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -2,6 +2,7 @@ class Ci::PipelinesController < Ci::BaseController before_action :require_login, only: %i[list create] skip_before_action :connect_to_ci_db + before_action :load_project, only: %i[content] # ======流水线相关接口========== # def list @@ -54,6 +55,7 @@ class Ci::PipelinesController < Ci::BaseController @yaml = "#pipeline \n" pipeline = Ci::Pipeline.find(params[:id]) @sync = pipeline.sync + @sha = '' stages = pipeline.pipeline_stages if stages && !stages.empty? init_step = stages.first.pipeline_stage_steps.first @@ -69,8 +71,19 @@ class Ci::PipelinesController < Ci::BaseController end end end + if @sync == 1 + @sha = get_pipeline_file_sha(pipeline.file_name) + end end + def get_pipeline_file_sha(file_name) + file_path_uri = URI.parse(file_name) + interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: params[:ref] || "master") + if interactor.success? + file = interactor.result + return file['sha'] + end + end # =========阶段相关接口========= # def stages pipeline_id = params[:id] diff --git a/app/views/ci/pipelines/content.json.jbuilder b/app/views/ci/pipelines/content.json.jbuilder index e532dd57c..60d211b94 100644 --- a/app/views/ci/pipelines/content.json.jbuilder +++ b/app/views/ci/pipelines/content.json.jbuilder @@ -1,2 +1,3 @@ json.content @yaml -json.sync @sync \ No newline at end of file +json.sync @sync +json.sha @sha \ No newline at end of file From 0d6ddad0130623ba238ce95686cc5e855cc714bc Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 16:23:19 +0800 Subject: [PATCH 17/24] =?UTF-8?q?=E6=9F=A5=E8=AF=A2steps=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ci/pipelines_controller.rb | 1 + app/views/ci/pipeline_stage_steps/_list.json.jbuilder | 2 +- app/views/ci/pipelines/steps.json.jbuilder | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 371f062b6..bb5bcc0a7 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -139,6 +139,7 @@ class Ci::PipelinesController < Ci::BaseController # ========步骤相关接口========= # def steps + @stage_type = Ci::PipelineStage.find(params[:stage_id]).stage_type @pipeline_stage_steps = Ci::PipelineStageStep.where('stage_id=?', params[:stage_id]).order('show_index asc') end diff --git a/app/views/ci/pipeline_stage_steps/_list.json.jbuilder b/app/views/ci/pipeline_stage_steps/_list.json.jbuilder index 904df8341..133783972 100644 --- a/app/views/ci/pipeline_stage_steps/_list.json.jbuilder +++ b/app/views/ci/pipeline_stage_steps/_list.json.jbuilder @@ -4,7 +4,7 @@ json.stage_id pipeline_stage_step.stage_id json.show_index pipeline_stage_step.show_index json.content pipeline_stage_step.content json.template_id pipeline_stage_step.template_id -json.category Ci::Template.find(pipeline_stage_step.template_id).category +json.category stage_type == 'customize' ? Ci::Template.find(pipeline_stage_step.template_id).parent_category : Ci::Template.find(pipeline_stage_step.template_id).category json.created_at pipeline_stage_step.created_at json.updated_at pipeline_stage_step.updated_at diff --git a/app/views/ci/pipelines/steps.json.jbuilder b/app/views/ci/pipelines/steps.json.jbuilder index 31e8ca6ac..e2421e2ae 100644 --- a/app/views/ci/pipelines/steps.json.jbuilder +++ b/app/views/ci/pipelines/steps.json.jbuilder @@ -1,3 +1,3 @@ json.steps @pipeline_stage_steps do |pipeline_stage_step| - json.partial! "/ci/pipeline_stage_steps/list", pipeline_stage_step: pipeline_stage_step + json.partial! "/ci/pipeline_stage_steps/list", pipeline_stage_step: pipeline_stage_step, stage_type: @stage_type end \ No newline at end of file From 3946c7116bf900b116e081028df039856be36549 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 18:11:00 +0800 Subject: [PATCH 18/24] =?UTF-8?q?=E5=88=9B=E5=BB=BApipeline=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 3 +- app/controllers/ci/pipelines_controller.rb | 44 +++++++++++++++++++++- config/routes.rb | 1 + 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/api_document.md b/api_document.md index 3c6c90fd1..35618f799 100644 --- a/api_document.md +++ b/api_document.md @@ -4203,7 +4203,8 @@ http://localhost:3000/api/ci/pipelines/1/content.json?owner=xx&repo=xx | jq ```json { "content": "#pipeline \nkind: pipeline\r\nname: maven项目-镜像仓库\r\n\r\nplatform:\r\n os: linux\r\n arch: arm64\nsteps:\n- name: Maven编译\r\n image: arm64v8/maven\r\n commands:\r\n - mvn install\n- name: 编译镜像-推送到仓库\r\n image: plugins/docker\r\n settings:\r\n username: moshenglv\r\n password: RL9UB5P7Jtzukka\r\n repo: docker.io/moshenglv/demo\r\n tags: latest\n", - "sync": 1 + "sync": 1, + "sha":"xxxxx" } ``` diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index bb5bcc0a7..dd1fe989e 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -2,7 +2,8 @@ class Ci::PipelinesController < Ci::BaseController before_action :require_login, only: %i[list create] skip_before_action :connect_to_ci_db - before_action :load_project, only: %i[content] + before_action :load_project, only: %i[content, create_trustie_pipeline] + before_action :load_repository, only: %i[create_trustie_pipeline] # ======流水线相关接口========== # def list @@ -84,6 +85,47 @@ class Ci::PipelinesController < Ci::BaseController return file['sha'] end end + + def create_trustie_pipeline + pipeline = Ci::Pipeline.find(params[:id]) + sha = get_pipeline_file_sha(pipeline.file_name) + if sha + pipeline.update!(sync: 1) + return update_trustie_pipeline(sha) + else + interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + if interactor.success? + pipeline.update!(sync: 1) + else + render_error(interactor.error) + end + end + end + + def update_trustie_pipeline(sha) + interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, params[:owner], params.merge(identifier: @project.identifier,sha: sha)) + if interactor.success? + return render_ok("更新成功") + else + return render_error(interactor.error) + end + end + + def content_params + { + filepath: params[:filepath], + branch: params[:branch], + new_branch: params[:new_branch], + content: params[:content], + message: params[:message], + committer: { + email: current_user.mail, + name: current_user.login + }, + identifier: @project.identifier + } + end + # =========阶段相关接口========= # def stages pipeline_id = params[:id] diff --git a/config/routes.rb b/config/routes.rb index 1281d16b9..058dfec02 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -46,6 +46,7 @@ Rails.application.routes.draw do get :content get :stages post :create_stage + post :create_trustie_pipeline delete :delete_stage, :path => ":stage_id/delete_stage", to: 'pipelines#delete_stage' put :update_stage, :path => ":stage_id/update_stage", to: 'pipelines#update_stage' get :stage_steps, :path => ":stage_id/steps", to: 'pipelines#steps' From efdbc6fd4e251194c5c55a04bf8d3493583e6cb9 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 18:23:28 +0800 Subject: [PATCH 19/24] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E6=96=87=E4=BB=B6=E6=96=B0=E5=A2=9E=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=86=85=E5=AE=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ci/pipelines_controller.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index dd1fe989e..888d8a054 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -91,26 +91,23 @@ class Ci::PipelinesController < Ci::BaseController sha = get_pipeline_file_sha(pipeline.file_name) if sha pipeline.update!(sync: 1) - return update_trustie_pipeline(sha) + interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, params[:owner], params.merge(identifier: @project.identifier,sha: sha)) + if interactor.success? + render_ok + else + render_error(interactor.error) + end else interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) if interactor.success? pipeline.update!(sync: 1) + render_ok else render_error(interactor.error) end end end - def update_trustie_pipeline(sha) - interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, params[:owner], params.merge(identifier: @project.identifier,sha: sha)) - if interactor.success? - return render_ok("更新成功") - else - return render_error(interactor.error) - end - end - def content_params { filepath: params[:filepath], From 69c6e2ac3f5d7683b1e1d0155511465ab001c38e Mon Sep 17 00:00:00 2001 From: moshenglv Date: Tue, 19 Jan 2021 18:39:57 +0800 Subject: [PATCH 20/24] =?UTF-8?q?cotent=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ci/pipelines_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 888d8a054..0df7945e8 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -2,7 +2,7 @@ class Ci::PipelinesController < Ci::BaseController before_action :require_login, only: %i[list create] skip_before_action :connect_to_ci_db - before_action :load_project, only: %i[content, create_trustie_pipeline] + before_action :load_project, only: %i[content create_trustie_pipeline] before_action :load_repository, only: %i[create_trustie_pipeline] # ======流水线相关接口========== # From ab3242569d0768582f683fffa76770a07bb97440 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Wed, 20 Jan 2021 11:54:10 +0800 Subject: [PATCH 21/24] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ci/pipelines_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/ci/pipelines_controller.rb b/app/controllers/ci/pipelines_controller.rb index 0df7945e8..19460fde9 100644 --- a/app/controllers/ci/pipelines_controller.rb +++ b/app/controllers/ci/pipelines_controller.rb @@ -7,7 +7,7 @@ class Ci::PipelinesController < Ci::BaseController # ======流水线相关接口========== # def list - @pipelines = Ci::Pipeline.where('login=? and identifier=?', current_user.login, params[:identifier]) + @pipelines = Ci::Pipeline.where('identifier=?', params[:identifier]) end def create From ab4af170fbb8675a882e916143a08d8de8901d3b Mon Sep 17 00:00:00 2001 From: moshenglv Date: Wed, 20 Jan 2021 13:52:30 +0800 Subject: [PATCH 22/24] =?UTF-8?q?=E8=BF=9E=E6=8E=A5ci=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=90=8D=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?repo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ci/base_controller.rb | 1 + app/controllers/concerns/ci/db_connectable.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/ci/base_controller.rb b/app/controllers/ci/base_controller.rb index c17105cd6..5aedbddbf 100644 --- a/app/controllers/ci/base_controller.rb +++ b/app/controllers/ci/base_controller.rb @@ -63,6 +63,7 @@ class Ci::BaseController < ApplicationController if current.ci_cloud_account.server_type == Ci::CloudAccount::SERVER_TYPE_TRUSTIE connect_to_trustie_ci_database(options) else + options = options.merge(db_name: current.login) connect_to_ci_database(options) end diff --git a/app/controllers/concerns/ci/db_connectable.rb b/app/controllers/concerns/ci/db_connectable.rb index 559384a59..e2c8ffefd 100644 --- a/app/controllers/concerns/ci/db_connectable.rb +++ b/app/controllers/concerns/ci/db_connectable.rb @@ -17,7 +17,8 @@ module Ci::DbConnectable password: db_config[:password], port: db_config[:port] } - req_params = req_params.merge(database: "#{current_user.login}_#{db_config[:database]}") unless master_db === true + db_name = options[:db_name].blank? ? current_user.login : options[:db_name] + req_params = req_params.merge(database: "#{db_name}_#{db_config[:database]}") unless master_db === true db_params = Ci::Database.get_connection_params(req_params) @connection = Ci::Database.set_connection(db_params).connection From f2efed0f1f6ae4c8b8f9d4ef1a98d6ef3583d0b3 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Wed, 20 Jan 2021 14:03:08 +0800 Subject: [PATCH 23/24] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/structure.sql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/db/structure.sql b/db/structure.sql index 353407a4c..ae8666bfa 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3445,4 +3445,12 @@ INSERT INTO `roles` (`id`, `name`, `position`, `assignable`, `builtin`, `permiss (15, 'Contestant', 13, 1, 0, '---\n- :add_project\n- :projects_attachments_download\n- :add_course\n- :course_attachments_download\n- :view_course_files\n- :select_contest_modules\n- :quote_project\n- :contest_attachments_download\n- :notificationcomment_contestnotifications\n- :add_messages\n- :edit_own_messages\n- :delete_own_messages\n- :view_calendar\n- :manage_files\n- :view_files\n- :view_gantt\n- :view_issues\n- :save_queries\n- :browse_repository\n- :view_changesets\n', 'default'); COMMIT; +-- ---------------------------- +-- Records of ci_templates +-- ---------------------------- +BEGIN; +INSERT INTO `ci_templates` VALUES (2,'linux/amd64','init','初始化','kind: pipeline\r\ntype: docker\r\nname: default\r\nplatform:\r\n os: linux\r\n arch: amd64','2021-01-12 02:44:23','2021-01-12 02:44:23',NULL),(3,'linux/arm64','init','初始化','kind: pipeline\r\ntype: docker\r\nname: default\r\nplatform:\r\n os: linux\r\n arch: arm64','2021-01-12 02:45:17','2021-01-12 02:45:17',NULL),(4,'maven','build','Java','- name: maven\r\n image: maven:3-jdk-10\r\n commands:\r\n - mvn install -DskipTests=true','2021-01-12 02:53:29','2021-01-12 02:53:29','编译构建'),(7,'golang编译','build','Golang','- name: golang编译\r\n image: golang\r\n commands:\r\n - go build','2021-01-12 03:03:35','2021-01-12 03:03:35','编译构建'),(8,'gradle','build','Java','- name: gradle\r\n image: gradle:jdk10\r\n commands:\r\n - gradle build -x test','2021-01-12 03:05:33','2021-01-12 03:05:33','编译构建'),(10,'远程主机部署','deploy','部署','# 根据实际情况修改主机ip、账号、密码\r\n# 需要将软件包与部署脚本提前上传到远程主机(见文件上传模板)\r\n\r\n- name: 远程主机部署\r\n image: appleboy/drone-ssh\r\n settings:\r\n host: 192.168.1.1\r\n username: username\r\n password: \'pasword\'\r\n port: 22\r\n commands:\r\n - chmod +x /home/deploy.sh\r\n - ./home/deploy.sh','2021-01-12 03:32:46','2021-01-12 03:32:46','部署'),(11,'远程命令','customize','工具','- name: 远程命令\r\n image: appleboy/drone-ssh\r\n settings:\r\n host: 192.168.0.1\r\n username: username\r\n password: \'pwd\'\r\n port: 22\r\n script:\r\n - echo \'hello world!\'','2021-01-12 03:40:38','2021-01-12 03:40:38','其他'),(12,'上传文件','customize','工具','# 修改目标服务器的ip、账号密码以及上传路径\r\n# 本模板示例为上传软件包和部署脚本到home目录\r\n\r\n- name: 上传文件\r\n image: appleboy/drone-scp\r\n settings:\r\n host: 192.168.1.1\r\n username: username\r\n password: \'password\'\r\n port: 22\r\n target: /home\r\n source: \r\n - target/*.jar\r\n - deploy.sh','2021-01-12 03:40:55','2021-01-12 03:40:55','其他'),(17,'make-c','build','C语言','- name: 编译\r\n image: gcc\r\n commands:\r\n - ./configure\r\n - make','2021-01-15 01:19:38','2021-01-15 01:19:38','编译构建'),(19,'make-c++','build','C++','- name: 编译构建\r\n image: gcc\r\n commands:\r\n - ./configure\r\n - make','2021-01-15 01:21:05','2021-01-15 01:21:05','编译构建'),(20,'python','build','Python','- name: 编译构建\r\n image: python\r\n commands:\r\n - pip install -r requirements.txt','2021-01-15 01:22:36','2021-01-15 01:22:36','编译构建'),(21,'Docker镜像构建','build','Docker镜像构建','# 构建Docker镜像并推送到仓库\r\n# 定义镜像Hub路径以及账号密码\r\n- name: Docker镜像构建\r\n image: plugins/docker\r\n settings:\r\n username: username\r\n password: pwd\r\n repo: repoUrl\r\n tags: latest','2021-01-15 01:23:16','2021-01-15 01:23:16','编译构建'),(22,'空白模板','customize','customize','','2021-01-15 02:53:02','2021-01-15 02:53:02','其他'),(23,'空白模板','build','自定义','','2021-01-15 03:27:33','2021-01-15 03:27:33','编译构建'); +COMMIT; + + SET FOREIGN_KEY_CHECKS = 1; From f4dc82f7d596aab47395aec378242ceac846c135 Mon Sep 17 00:00:00 2001 From: moshenglv Date: Wed, 20 Jan 2021 14:21:16 +0800 Subject: [PATCH 24/24] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/structure.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/structure.sql b/db/structure.sql index ae8666bfa..dd8544fd4 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3449,7 +3449,7 @@ COMMIT; -- Records of ci_templates -- ---------------------------- BEGIN; -INSERT INTO `ci_templates` VALUES (2,'linux/amd64','init','初始化','kind: pipeline\r\ntype: docker\r\nname: default\r\nplatform:\r\n os: linux\r\n arch: amd64','2021-01-12 02:44:23','2021-01-12 02:44:23',NULL),(3,'linux/arm64','init','初始化','kind: pipeline\r\ntype: docker\r\nname: default\r\nplatform:\r\n os: linux\r\n arch: arm64','2021-01-12 02:45:17','2021-01-12 02:45:17',NULL),(4,'maven','build','Java','- name: maven\r\n image: maven:3-jdk-10\r\n commands:\r\n - mvn install -DskipTests=true','2021-01-12 02:53:29','2021-01-12 02:53:29','编译构建'),(7,'golang编译','build','Golang','- name: golang编译\r\n image: golang\r\n commands:\r\n - go build','2021-01-12 03:03:35','2021-01-12 03:03:35','编译构建'),(8,'gradle','build','Java','- name: gradle\r\n image: gradle:jdk10\r\n commands:\r\n - gradle build -x test','2021-01-12 03:05:33','2021-01-12 03:05:33','编译构建'),(10,'远程主机部署','deploy','部署','# 根据实际情况修改主机ip、账号、密码\r\n# 需要将软件包与部署脚本提前上传到远程主机(见文件上传模板)\r\n\r\n- name: 远程主机部署\r\n image: appleboy/drone-ssh\r\n settings:\r\n host: 192.168.1.1\r\n username: username\r\n password: \'pasword\'\r\n port: 22\r\n commands:\r\n - chmod +x /home/deploy.sh\r\n - ./home/deploy.sh','2021-01-12 03:32:46','2021-01-12 03:32:46','部署'),(11,'远程命令','customize','工具','- name: 远程命令\r\n image: appleboy/drone-ssh\r\n settings:\r\n host: 192.168.0.1\r\n username: username\r\n password: \'pwd\'\r\n port: 22\r\n script:\r\n - echo \'hello world!\'','2021-01-12 03:40:38','2021-01-12 03:40:38','其他'),(12,'上传文件','customize','工具','# 修改目标服务器的ip、账号密码以及上传路径\r\n# 本模板示例为上传软件包和部署脚本到home目录\r\n\r\n- name: 上传文件\r\n image: appleboy/drone-scp\r\n settings:\r\n host: 192.168.1.1\r\n username: username\r\n password: \'password\'\r\n port: 22\r\n target: /home\r\n source: \r\n - target/*.jar\r\n - deploy.sh','2021-01-12 03:40:55','2021-01-12 03:40:55','其他'),(17,'make-c','build','C语言','- name: 编译\r\n image: gcc\r\n commands:\r\n - ./configure\r\n - make','2021-01-15 01:19:38','2021-01-15 01:19:38','编译构建'),(19,'make-c++','build','C++','- name: 编译构建\r\n image: gcc\r\n commands:\r\n - ./configure\r\n - make','2021-01-15 01:21:05','2021-01-15 01:21:05','编译构建'),(20,'python','build','Python','- name: 编译构建\r\n image: python\r\n commands:\r\n - pip install -r requirements.txt','2021-01-15 01:22:36','2021-01-15 01:22:36','编译构建'),(21,'Docker镜像构建','build','Docker镜像构建','# 构建Docker镜像并推送到仓库\r\n# 定义镜像Hub路径以及账号密码\r\n- name: Docker镜像构建\r\n image: plugins/docker\r\n settings:\r\n username: username\r\n password: pwd\r\n repo: repoUrl\r\n tags: latest','2021-01-15 01:23:16','2021-01-15 01:23:16','编译构建'),(22,'空白模板','customize','customize','','2021-01-15 02:53:02','2021-01-15 02:53:02','其他'),(23,'空白模板','build','自定义','','2021-01-15 03:27:33','2021-01-15 03:27:33','编译构建'); +INSERT INTO `ci_templates` VALUES (2,'linux/amd64','init','初始化','kind: pipeline\r\ntype: docker\r\nname: default\r\nplatform:\r\n os: linux\r\n arch: amd64','2021-01-12 02:44:23','2021-01-12 02:44:23',NULL),(3,'linux/arm64','init','初始化','kind: pipeline\r\ntype: docker\r\nname: default\r\nplatform:\r\n os: linux\r\n arch: arm64','2021-01-12 02:45:17','2021-01-12 02:45:17',NULL),(4,'maven','build','Java','- name: maven\r\n image: maven:3-jdk-10\r\n commands:\r\n - mvn install -DskipTests=true','2021-01-12 02:53:29','2021-01-12 02:53:29','编译构建'),(5,'maven单元测试','customize','Java','- name: maven\r\n image: maven:3-jdk-10\r\n commands:\r\n - mvn test','2021-01-12 02:53:29','2021-01-12 02:53:29','单元测试'),(6,'golang单元测试','customize','Golang','- name: golang单元测试\r\n image: golang\r\n commands:\r\n - go test','2021-01-12 03:03:35','2021-01-12 03:03:35','单元测试'),(9,'gradle单元测试','customize','Java','- name: gradle\r\n image: gradle:jdk10\r\n commands:\r\n - gradle test','2021-01-12 03:05:33','2021-01-12 03:05:33','单元测试'),(7,'golang编译','build','Golang','- name: golang编译\r\n image: golang\r\n commands:\r\n - go build','2021-01-12 03:03:35','2021-01-12 03:03:35','编译构建'),(8,'gradle','build','Java','- name: gradle\r\n image: gradle:jdk10\r\n commands:\r\n - gradle build -x test','2021-01-12 03:05:33','2021-01-12 03:05:33','编译构建'),(10,'远程主机部署','deploy','部署','# 根据实际情况修改主机ip、账号、密码\r\n# 需要将软件包与部署脚本提前上传到远程主机(见文件上传模板)\r\n\r\n- name: 远程主机部署\r\n image: appleboy/drone-ssh\r\n settings:\r\n host: 192.168.1.1\r\n username: username\r\n password: \'pasword\'\r\n port: 22\r\n commands:\r\n - chmod +x /home/deploy.sh\r\n - ./home/deploy.sh','2021-01-12 03:32:46','2021-01-12 03:32:46','部署'),(11,'远程命令','customize','工具','- name: 远程命令\r\n image: appleboy/drone-ssh\r\n settings:\r\n host: 192.168.0.1\r\n username: username\r\n password: \'pwd\'\r\n port: 22\r\n script:\r\n - echo \'hello world!\'','2021-01-12 03:40:38','2021-01-12 03:40:38','其他'),(12,'上传文件','customize','工具','# 修改目标服务器的ip、账号密码以及上传路径\r\n# 本模板示例为上传软件包和部署脚本到home目录\r\n\r\n- name: 上传文件\r\n image: appleboy/drone-scp\r\n settings:\r\n host: 192.168.1.1\r\n username: username\r\n password: \'password\'\r\n port: 22\r\n target: /home\r\n source: \r\n - target/*.jar\r\n - deploy.sh','2021-01-12 03:40:55','2021-01-12 03:40:55','其他'),(17,'make-c','build','C语言','- name: 编译\r\n image: gcc\r\n commands:\r\n - ./configure\r\n - make','2021-01-15 01:19:38','2021-01-15 01:19:38','编译构建'),(19,'make-c++','build','C++','- name: 编译构建\r\n image: gcc\r\n commands:\r\n - ./configure\r\n - make','2021-01-15 01:21:05','2021-01-15 01:21:05','编译构建'),(20,'python','build','Python','- name: 编译构建\r\n image: python\r\n commands:\r\n - pip install -r requirements.txt','2021-01-15 01:22:36','2021-01-15 01:22:36','编译构建'),(21,'Docker镜像构建','build','Docker镜像构建','# 构建Docker镜像并推送到仓库\r\n# 定义镜像Hub路径以及账号密码\r\n- name: Docker镜像构建\r\n image: plugins/docker\r\n settings:\r\n username: username\r\n password: pwd\r\n repo: repoUrl\r\n tags: latest','2021-01-15 01:23:16','2021-01-15 01:23:16','编译构建'),(22,'空白模板','customize','customize','','2021-01-15 02:53:02','2021-01-15 02:53:02','其他'),(23,'空白模板','build','自定义','','2021-01-15 03:27:33','2021-01-15 03:27:33','编译构建'); COMMIT;