fixed 组织流水线中多仓库按文件查询

This commit is contained in:
xxq250 2025-04-21 15:28:36 +08:00
parent 44396e444b
commit d3bc799263
2 changed files with 48 additions and 45 deletions

View File

@ -16,56 +16,59 @@ 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?
unless db_files.include?(".gitea/workflows/#{file}") files = $gitea_client.get_repos_contents_by_owner_repo_filepath(project&.owner&.login, project&.identifier, ".gitea/workflows") rescue []
pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""), files.map { |i| i['name'] }.each do |file|
file_name: ".gitea/workflows/#{file}", unless db_files.include?(".gitea/workflows/#{file}")
branch: project.default_branch, pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""),
is_graphic_design: false, file_name: ".gitea/workflows/#{file}",
disable: false, branch: project.default_branch,
project_id: project.id) is_graphic_design: false,
interactor = Repositories::EntriesInteractor.call(@owner, project.identifier, ".gitea/workflows/#{file}", ref: project.default_branch) disable: false,
if interactor.success? project_id: project.id)
pipeline.yaml = decode64_content(interactor.result, @owner, project.repository, project.default_branch, nil) 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
# 导入的流水线统一先禁用
$gitea_hat_client.post_repos_actions_disable(project&.owner&.login, project&.identifier, {query: {workflow: file}}) rescue nil
end end
pipeline.user_id = current_user.id last_action_run = action_runs.where(repo_id: project.gpid).where(workflow_id: file).order(updated: :desc).first
pipeline.save last_action_run_json = last_action_run.present? ? {
# 导入的流水线统一先禁用 id: last_action_run.id,
$gitea_hat_client.post_repos_actions_disable(project&.owner&.login, project&.identifier, {query: {workflow: file}}) rescue nil schedule: last_action_run.schedule_id > 0,
end title: last_action_run.title,
last_action_run = action_runs.where(repo_id: project.gpid).where(workflow_id: file).order(updated: :desc).first index: last_action_run.index,
last_action_run_json = last_action_run.present? ? { status: last_action_run.status,
id: last_action_run.id, started: last_action_run.started,
schedule: last_action_run.schedule_id > 0, stopped: last_action_run.stopped,
title: last_action_run.title, length: last_action_run.stopped-last_action_run.started,
index: last_action_run.index, created: last_action_run.created,
status: last_action_run.status, updated: last_action_run.updated,
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 total = 0
success = 0 success = 0
failure = 0 failure = 0
group_data.each do |k,v| group_data.each do |k,v|
total += v if k[0] == file total += v if k[0] == file
success += v if k[0] == file && k[1] == 1 success += v if k[0] == file && k[1] == 1
failure += v if k[0] == file && k[1] == 2 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
@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")
@pipelines = Action::Pipeline.where(project_id: @project_ids).order(updated_at: :desc) @pipelines = Action::Pipeline.where(project_id: @project_ids).order(updated_at: :desc)
@pipelines = @pipelines.where("pipeline_name like ?", "%#{params[:pipeline_name]}%") if params[:pipeline_name].present? @pipelines = @pipelines.where("pipeline_name like ?", "%#{params[:pipeline_name]}%") if params[:pipeline_name].present?

View File

@ -55,7 +55,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
failure: failure failure: failure
}.merge(last_action_run_json) }.merge(last_action_run_json)
end end
Rails.logger.info("@run_result======#{@run_result}") # Rails.logger.info("@run_result======#{@run_result}")
disabled_config = Gitea::RepoUnit.where(repo_id: @project.gpid, type: 10)&.first&.config disabled_config = Gitea::RepoUnit.where(repo_id: @project.gpid, type: 10)&.first&.config
@disabled_workflows = disabled_config.present? ? JSON.parse(disabled_config)["DisabledWorkflows"] : [] @disabled_workflows = disabled_config.present? ? JSON.parse(disabled_config)["DisabledWorkflows"] : []
@pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc) @pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc)