流水线初始化
This commit is contained in:
parent
f738dbed24
commit
001f90aede
|
@ -2,6 +2,24 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
|
|||
before_action :require_operate_above, except: [:upload_results, :run_results]
|
||||
|
||||
def index
|
||||
pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc)
|
||||
@files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue []
|
||||
db_files = pipelines.pluck(:file_name)
|
||||
@files.map { |i| i['name'] }.each do |file|
|
||||
unless db_files.include?(".gitea/workflows/#{file}")
|
||||
pipeline = Action::Pipeline.new(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""),
|
||||
file_name: ".gitea/workflows/#{file}",
|
||||
branch: @project.default_branch,
|
||||
is_graphic_design: false,
|
||||
project_id: @project.id)
|
||||
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, ".gitea/workflows/#{file}", ref: @project.default_branch)
|
||||
if interactor.success?
|
||||
pipeline.yaml = decode64_content(interactor.result, @owner, @project.repository, @project.default_branch, nil)
|
||||
end
|
||||
pipeline.user_id = current_user.id
|
||||
pipeline.save
|
||||
end
|
||||
end
|
||||
@pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc)
|
||||
@pipelines = paginate @pipelines
|
||||
end
|
||||
|
@ -88,7 +106,6 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
|
|||
render_ok
|
||||
end
|
||||
|
||||
|
||||
def upload_results
|
||||
tip_exception("参数错误") if params[:owner].blank? || params[:repo].blank? || params[:run_id].blank?
|
||||
@project, @owner = Project.find_with_namespace(params[:owner], params[:repo])
|
||||
|
@ -109,7 +126,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
|
|||
tip_exception("参数错误") if params[:owner].blank? || params[:repo].blank? || params[:run_id].blank?
|
||||
@project, @owner = Project.find_with_namespace(params[:owner], params[:repo])
|
||||
tip_exception("项目不存在") if @project.blank?
|
||||
results = Action::PipelineResult.where(run_id: params[:run_id], project_id: @project.id)
|
||||
results = Action::PipelineResult.where(run_id: params[:run_id], project_id: @project.id)
|
||||
render_ok(run_results: results.as_json(only: %i[id run_id job_name job_show_type job_result]))
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue