From bddfe9d8f747c289ef47fa063639b9d5f36477d2 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 21 Apr 2025 13:59:15 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E6=B5=81=E6=B0=B4=E7=BA=BF=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/pipelines_controller.rb | 3 +-- app/controllers/api/v1/projects/pipelines_controller.rb | 2 +- app/views/api/pm/pipelines/index.json.jbuilder | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/pm/pipelines_controller.rb b/app/controllers/api/pm/pipelines_controller.rb index 815dde10b..0d42a9749 100644 --- a/app/controllers/api/pm/pipelines_controller.rb +++ b/app/controllers/api/pm/pipelines_controller.rb @@ -20,7 +20,7 @@ class Api::Pm::PipelinesController < Api::Pm::BaseController project = Project.find_by(gpid: file_info.repo_id) next if project.blank? unless db_files.include?(".gitea/workflows/#{file}") - pipeline = Action::Pipeline.new(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""), + pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""), file_name: ".gitea/workflows/#{file}", branch: project.default_branch, is_graphic_design: false, @@ -69,7 +69,6 @@ class Api::Pm::PipelinesController < Api::Pm::BaseController @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_type: params[:pipeline_type]) if params[:pipeline_type].present? - @has_pipeline_ids = @pipelines.pluck(:project_id).uniq @pipelines = @pipelines @pipelines = paginate @pipelines end diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 74b433d5a..98045e08d 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -11,7 +11,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @run_result = [] @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", ""), + pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""), file_name: ".gitea/workflows/#{file}", branch: @project.default_branch, is_graphic_design: false, diff --git a/app/views/api/pm/pipelines/index.json.jbuilder b/app/views/api/pm/pipelines/index.json.jbuilder index c7ee9e545..430873132 100644 --- a/app/views/api/pm/pipelines/index.json.jbuilder +++ b/app/views/api/pm/pipelines/index.json.jbuilder @@ -1,6 +1,7 @@ json.status 0 json.message "success" -json.projects @has_pipeline_ids.each do |project_id| +json.count @pipelines.total_count +json.projects @pipelines.map(&:project_id).each do |project_id| json.id project_id project = Project.find_by(id: project_id) if project.present?