diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 9b2bedd06..da9e29e7b 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -80,7 +80,12 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController tip_exception("已经存在#{params[:pipeline_name]}流水线!") if has_pipeline.present? if @pipeline.yaml.present? sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) - if sha.present? + new_file_sha = get_pipeline_file_sha(params[:pipeline_name], @pipeline.branch) + # 重命名的新文件存在时,直接修改新文件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")) + tip_exception(interactor.error) unless interactor.success? + else 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