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