流水线名称保存支持重名文件
This commit is contained in:
parent
e50a14595d
commit
ffa4c6e870
|
@ -71,9 +71,19 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
|
|||
end
|
||||
|
||||
def create
|
||||
size = Action::Pipeline.where(pipeline_name: params[:pipeline_name], project_id: @project.id).size
|
||||
tip_exception("已经存在#{params[:pipeline_name]}流水线!") if size > 0
|
||||
@pipeline = Action::Pipeline.new(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)
|
||||
if @pipeline.pipeline_name != params[:pipeline_name]
|
||||
has_pipeline = Action::Pipeline.where(pipeline_name: params[:pipeline_name], project_id: @project.id).where.not(id: @pipeline.id)
|
||||
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?
|
||||
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update", params[:pipeline_name]).merge(sha: sha, from_path: "#{@pipeline.pipeline_name}"))
|
||||
tip_exception(interactor.error) unless interactor.success?
|
||||
end
|
||||
end
|
||||
end
|
||||
@pipeline.pipeline_name = params[:pipeline_name]
|
||||
@pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml"
|
||||
@pipeline.branch = params[:branch] || @project.default_branch
|
||||
@pipeline.is_graphic_design = params[:pipeline_type] == 2 ? true : false
|
||||
|
@ -93,6 +103,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
|
|||
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?
|
||||
file = interactor.result
|
||||
@pipeline.pipeline_type = @pipeline.json.present? ? 2 : 1
|
||||
@pipeline.save
|
||||
render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: sha.present? ? sha : file['content']['sha'] })
|
||||
end
|
||||
|
@ -203,9 +214,9 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
|
|||
end
|
||||
end
|
||||
|
||||
def content_params(opt)
|
||||
def content_params(opt, rename_file=nil)
|
||||
{
|
||||
filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yml",
|
||||
filepath: ".gitea/workflows/#{rename_file.present? ? rename_file : @pipeline.pipeline_name}.yml",
|
||||
branch: @pipeline.branch,
|
||||
new_branch: @pipeline.branch,
|
||||
content: opt == "create" ? Base64.encode64(@pipeline.yaml).gsub(/\n/, '') : @pipeline.yaml,
|
||||
|
|
Loading…
Reference in New Issue