fixed 重命名的新文件存在时,直接修改新文件new_file_sha, 同时删除老文件

This commit is contained in:
xxq250 2025-11-05 09:59:45 +08:00
parent a0c8207986
commit df032c5343
1 changed files with 5 additions and 3 deletions

View File

@ -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