From aed452e144a5996100eccbce64943d2e1a51b821 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 17 Apr 2025 10:25:27 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E7=BB=84=E7=BB=87=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3,=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E5=86=85=E6=89=80=E6=9C=89=E4=BB=93=E5=BA=93,?= =?UTF-8?q?=E5=88=86=E7=BB=84=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/pipelines_controller.rb | 5 +-- .../api/pm/pipelines/index.json.jbuilder | 31 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/controllers/api/pm/pipelines_controller.rb b/app/controllers/api/pm/pipelines_controller.rb index af8f6d75d..f6691e184 100644 --- a/app/controllers/api/pm/pipelines_controller.rb +++ b/app/controllers/api/pm/pipelines_controller.rb @@ -5,7 +5,7 @@ class Api::Pm::PipelinesController < Api::Pm::BaseController def index @owner = Owner.find_by(login: params[:owner_id].to_s) || Owner.find_by(id: params[:owner_id].to_s) tip_exception('组织未找到') if @owner.blank? - project_ids = @owner.projects.ids + @project_ids = @owner.projects.ids project_gpids = @owner.projects.pluck(:gpid) action_runs = Gitea::ActionRun.where(owner_id: @owner.gitea_uid) group_data = action_runs.where(status: [1,2]).group(:workflow_id, :status).count @@ -64,7 +64,8 @@ class Api::Pm::PipelinesController < Api::Pm::BaseController end Rails.logger.info("@run_result======#{@run_result}") @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 @pipelines = paginate @pipelines end diff --git a/app/views/api/pm/pipelines/index.json.jbuilder b/app/views/api/pm/pipelines/index.json.jbuilder index 1f9201334..60a71e880 100644 --- a/app/views/api/pm/pipelines/index.json.jbuilder +++ b/app/views/api/pm/pipelines/index.json.jbuilder @@ -1,15 +1,24 @@ json.status 0 json.message "success" - -json.pipelines @pipelines.each do |pipeline| - json.extract! pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, - :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at - repo_config = @disabled_workflows.select { |config| config.repo_id = pipeline.project.gpid } - if repo_config.present? - json.disable JSON.parse(repo_config.first.config)["DisabledWorkflows"].to_s.include?(pipeline.file_name.to_s.gsub(".gitea/workflows/", "")) - else - json.disable pipeline.disable +json.projects @project_ids.each do |project_id| + json.id project_id + project = Project.find_by(id: project_id) + if project.present? + json.owner project.owner.name + json.identifier project.identifier + json.name project.name + json.url "#{Rails.application.config_for(:configuration)['platform_url']}/#{project.owner.name}/#{project.identifier}" + json.pipelines @pipelines.select { |p| p.repo_id == project_id }.each do |pipeline| + json.extract! pipeline, :id, :project_id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, + :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at + repo_config = @disabled_workflows.select { |config| config.repo_id = pipeline.project.gpid } + if repo_config.present? + json.disable JSON.parse(repo_config.first.config)["DisabledWorkflows"].to_s.include?(pipeline.file_name.to_s.gsub(".gitea/workflows/", "")) + else + json.disable pipeline.disable + end + json.pipeline_type pipeline.pipeline_type + json.run_data @run_result.select { |result| result[:filename] == pipeline.file_name }.first + end end - json.pipeline_type pipeline.pipeline_type - json.run_data @run_result.select { |result| result[:filename] == pipeline.file_name }.first end