fixed 组织流水线运行数据控制
This commit is contained in:
parent
d3bc799263
commit
88415e256d
|
@ -16,57 +16,54 @@ class Api::Pm::PipelinesController < Api::Pm::BaseController
|
||||||
db_files = pipelines.pluck(:file_name)
|
db_files = pipelines.pluck(:file_name)
|
||||||
@run_result = []
|
@run_result = []
|
||||||
run_files.each do |file_info|
|
run_files.each do |file_info|
|
||||||
# file = file_info.workflow_id
|
file = file_info.workflow_id
|
||||||
project = Project.find_by(gpid: file_info.repo_id)
|
project = Project.find_by(gpid: file_info.repo_id)
|
||||||
next if project.blank?
|
next if project.blank?
|
||||||
files = $gitea_client.get_repos_contents_by_owner_repo_filepath(project&.owner&.login, project&.identifier, ".gitea/workflows") rescue []
|
unless db_files.include?(".gitea/workflows/#{file}")
|
||||||
files.map { |i| i['name'] }.each do |file|
|
pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""),
|
||||||
unless db_files.include?(".gitea/workflows/#{file}")
|
file_name: ".gitea/workflows/#{file}",
|
||||||
pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""),
|
branch: project.default_branch,
|
||||||
file_name: ".gitea/workflows/#{file}",
|
is_graphic_design: false,
|
||||||
branch: project.default_branch,
|
disable: false,
|
||||||
is_graphic_design: false,
|
project_id: project.id)
|
||||||
disable: false,
|
interactor = Repositories::EntriesInteractor.call(@owner, project.identifier, ".gitea/workflows/#{file}", ref: project.default_branch)
|
||||||
project_id: project.id)
|
if interactor.success?
|
||||||
interactor = Repositories::EntriesInteractor.call(@owner, project.identifier, ".gitea/workflows/#{file}", ref: project.default_branch)
|
pipeline.yaml = decode64_content(interactor.result, @owner, project.repository, project.default_branch, nil)
|
||||||
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
|
|
||||||
# 导入的流水线统一先禁用
|
|
||||||
$gitea_hat_client.post_repos_actions_disable(project&.owner&.login, project&.identifier, {query: {workflow: file}}) rescue nil
|
|
||||||
end
|
end
|
||||||
last_action_run = action_runs.where(repo_id: project.gpid).where(workflow_id: file).order(updated: :desc).first
|
pipeline.user_id = current_user.id
|
||||||
last_action_run_json = last_action_run.present? ? {
|
pipeline.save
|
||||||
id: last_action_run.id,
|
# 导入的流水线统一先禁用
|
||||||
schedule: last_action_run.schedule_id > 0,
|
$gitea_hat_client.post_repos_actions_disable(project&.owner&.login, project&.identifier, {query: {workflow: file}}) rescue nil
|
||||||
title: last_action_run.title,
|
|
||||||
index: last_action_run.index,
|
|
||||||
status: last_action_run.status,
|
|
||||||
started: last_action_run.started,
|
|
||||||
stopped: last_action_run.stopped,
|
|
||||||
length: last_action_run.stopped-last_action_run.started,
|
|
||||||
created: last_action_run.created,
|
|
||||||
updated: last_action_run.updated,
|
|
||||||
} : {}
|
|
||||||
|
|
||||||
total = 0
|
|
||||||
success = 0
|
|
||||||
failure = 0
|
|
||||||
group_data.each do |k,v|
|
|
||||||
total += v if k[0] == file
|
|
||||||
success += v if k[0] == file && k[1] == 1
|
|
||||||
failure += v if k[0] == file && k[1] == 2
|
|
||||||
end
|
|
||||||
@run_result << {
|
|
||||||
repo_id: last_action_run.repo_id,
|
|
||||||
filename: ".gitea/workflows/#{file}",
|
|
||||||
total: total,
|
|
||||||
success: success,
|
|
||||||
failure: failure
|
|
||||||
}.merge(last_action_run_json)
|
|
||||||
end
|
end
|
||||||
|
last_action_run = action_runs.where(repo_id: project.gpid).where(workflow_id: file).order(updated: :desc).first
|
||||||
|
last_action_run_json = last_action_run.present? ? {
|
||||||
|
id: last_action_run.id,
|
||||||
|
schedule: last_action_run.schedule_id > 0,
|
||||||
|
title: last_action_run.title,
|
||||||
|
index: last_action_run.index,
|
||||||
|
status: last_action_run.status,
|
||||||
|
started: last_action_run.started,
|
||||||
|
stopped: last_action_run.stopped,
|
||||||
|
length: last_action_run.stopped-last_action_run.started,
|
||||||
|
created: last_action_run.created,
|
||||||
|
updated: last_action_run.updated,
|
||||||
|
} : {}
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
success = 0
|
||||||
|
failure = 0
|
||||||
|
group_data.each do |k,v|
|
||||||
|
total += v if k[0] == file
|
||||||
|
success += v if k[0] == file && k[1] == 1
|
||||||
|
failure += v if k[0] == file && k[1] == 2
|
||||||
|
end
|
||||||
|
@run_result << {
|
||||||
|
repo_id: last_action_run.repo_id,
|
||||||
|
filename: ".gitea/workflows/#{file}",
|
||||||
|
total: total,
|
||||||
|
success: success,
|
||||||
|
failure: failure
|
||||||
|
}.merge(last_action_run_json)
|
||||||
end
|
end
|
||||||
# Rails.logger.info("@run_result======#{@run_result}")
|
# Rails.logger.info("@run_result======#{@run_result}")
|
||||||
@disabled_workflows = Gitea::RepoUnit.where(repo_id: project_gpids, type: 10).where("config is not null")
|
@disabled_workflows = Gitea::RepoUnit.where(repo_id: project_gpids, type: 10).where("config is not null")
|
||||||
|
|
|
@ -19,7 +19,11 @@ json.projects @pipelines.map(&:project_id).uniq.each do |project_id|
|
||||||
json.disable pipeline.disable
|
json.disable pipeline.disable
|
||||||
end
|
end
|
||||||
json.pipeline_type pipeline.pipeline_type
|
json.pipeline_type pipeline.pipeline_type
|
||||||
json.run_data @run_result.select { |result| result[:repo_id] == project.gpid && result[:filename] == pipeline.file_name}.first
|
if pipeline.json.blank? && pipeline.yaml.blank?
|
||||||
|
json.run_data nil
|
||||||
|
else
|
||||||
|
json.run_data @run_result.select { |result| result[:repo_id] == project.gpid && result[:filename] == pipeline.file_name}.first
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue