From df032c5343ed2d26ca72718df1f76765b3a33146 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 5 Nov 2025 09:59:45 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E9=87=8D=E5=91=BD=E5=90=8D=E7=9A=84?= =?UTF-8?q?=E6=96=B0=E6=96=87=E4=BB=B6=E5=AD=98=E5=9C=A8=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BF=AE=E6=94=B9=E6=96=B0=E6=96=87=E4=BB=B6?= =?UTF-8?q?new=5Ffile=5Fsha,=20=E5=90=8C=E6=97=B6=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=80=81=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index a0f2c5609..8a2d09a28 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -81,11 +81,13 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController if @pipeline.yaml.present? sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) new_file_sha = get_pipeline_file_sha(".gitea/workflows/#{params[:pipeline_name]}.yml", @pipeline.branch) - # 重命名的新文件存在时,直接修改新文件new_file_sha + # 重命名的新文件存在时,直接修改新文件new_file_sha, 同时删除老文件 if sha.present? && new_file_sha.present? - interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update", params[:pipeline_name]).merge(sha: new_file_sha, from_path: ".gitea/workflows/#{@pipeline.pipeline_name}.yml")) + interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update", params[:pipeline_name]).merge(sha: new_file_sha, from_path: ".gitea/workflows/#{params[:pipeline_name]}.yml")) tip_exception(interactor.error) unless interactor.success? - else + del_interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, del_content_params(sha).merge(identifier: @project.identifier)) + tip_exception(del_interactor.error) unless del_interactor.success? + elsif sha.present? && new_file_sha.blank? interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update", params[:pipeline_name]).merge(sha: sha, from_path: ".gitea/workflows/#{@pipeline.pipeline_name}.yml")) tip_exception(interactor.error) unless interactor.success? end