fixed pipeline 分支错误导致保存失败

This commit is contained in:
xxq250 2025-04-09 08:42:19 +08:00
parent 4d22889ba9
commit ef214af00a
1 changed files with 3 additions and 3 deletions

View File

@ -94,15 +94,15 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
def save_yaml def save_yaml
@pipeline = params[:id].present? ? Action::Pipeline.find(params[:id]) : Action::Pipeline.find_or_initialize_by(pipeline_name: params[:pipeline_name], project_id: @project.id) @pipeline = params[:id].present? ? Action::Pipeline.find(params[:id]) : Action::Pipeline.find_or_initialize_by(pipeline_name: params[:pipeline_name], project_id: @project.id)
@pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml" @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml"
@pipeline.branch = params[:branch] || @project.default_branch @pipeline.branch = params[:branch].to_json if params[:branch].present?
@pipeline.json = params[:pipeline_json].to_json if params[:pipeline_json].present? @pipeline.json = params[:pipeline_json].to_json if params[:pipeline_json].present?
@pipeline.pipeline_name = params[:pipeline_name] if params[:pipeline_name].present? @pipeline.pipeline_name = params[:pipeline_name] if params[:pipeline_name].present?
pipeline_yaml = params[:pipeline_yaml].present? ? params[:pipeline_yaml] : build_pipeline_yaml_new(@pipeline.pipeline_name, params[:pipeline_json]) pipeline_yaml = params[:pipeline_yaml].present? ? params[:pipeline_yaml] : build_pipeline_yaml_new(@pipeline.pipeline_name, params[:pipeline_json])
tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank?
@pipeline.yaml = pipeline_yaml @pipeline.yaml = pipeline_yaml
Rails.logger.info "pipeline_yaml base64=========================#{Base64.encode64(@pipeline.yaml).gsub(/\n/, '')}" #Rails.logger.info "pipeline_yaml base64=========================#{Base64.encode64(@pipeline.yaml).gsub(/\n/, '')}"
sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch)
Rails.logger.info "content_params=========#{content_params("create")}" #Rails.logger.info "content_params=========#{content_params("create")}"
interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create"))
tip_exception(interactor.error) unless interactor.success? tip_exception(interactor.error) unless interactor.success?
file = interactor.result file = interactor.result