构建流水线yaml, 中文文件名

This commit is contained in:
xxq250 2024-05-23 11:26:59 +08:00
parent da831ec6e7
commit 790a7eeb8c
1 changed files with 7 additions and 7 deletions

View File

@ -19,7 +19,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
@pipeline.save!
sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch)
tip_exception("#{@pipeline.file_name}已存在") if sha
interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params)
interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create"))
tip_exception(interactor.error) unless interactor.success?
render_ok({ id: @pipeline.id })
end
@ -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.merge(sha: sha)) : 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("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create"))
tip_exception(interactor.error) unless interactor.success?
render_ok
end
@ -58,7 +58,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
@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))
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create").merge(sha: sha))
tip_exception(interactor.error) unless interactor.success?
render_ok
end
@ -66,7 +66,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
def destroy
@pipeline = Action::Pipeline.find(params[:id])
if pipeline
interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, content_params)
interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update"))
tip_exception(interactor.error) unless interactor.success?
@pipeline.destroy!
end
@ -147,13 +147,13 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
end
end
def content_params
def content_params(opt)
{
filepath: ".gitea/workflows/#{URI.parse(@pipeline.pipeline_name)}.yaml",
filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yaml",
branch: @pipeline.branch,
new_branch: @pipeline.branch,
content: Base64.encode64(@pipeline.yaml),
message: 'create pipeline',
message: "#{opt} pipeline",
committer: {
email: current_user.mail,
name: current_user.login