From da831ec6e75762a319c4235c538cbc3e0f5327f9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 May 2024 10:56:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E6=B0=B4=E7=BA=BFya?= =?UTF-8?q?ml=20=E6=9B=B4=E6=96=B0=E6=96=87=E4=BB=B6=E9=9C=80=E8=A6=81sha?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 6cd4bff67..fb5eee64d 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -33,7 +33,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @pipeline.yaml = pipeline_yaml sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) - interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params.merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) tip_exception(interactor.error) unless interactor.success? render_ok end @@ -49,8 +49,16 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def update @pipeline = Action::Pipeline.find(params[:id]) - @pipeline.update!(pipeline_name: params[:pipeline_name]) - interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params) + @pipeline.pipeline_name = params[:pipeline_name] + @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yaml" + @pipeline.branch = params[:branch] || @project.default_branch + @pipeline.json = params[:pipeline_json].to_json + pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) + tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? + @pipeline.yaml = pipeline_yaml + @pipeline.save + sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) + interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params.merge(sha: sha)) tip_exception(interactor.error) unless interactor.success? render_ok end