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