From 467d722d25950ed48c95581efbd835551de56312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Mon, 15 Aug 2022 14:03:27 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20reposyncer=20job=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ob_repository_syncs_controller.rb | 15 +++++++++------ app/services/ob_repository_sync/api_service.rb | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/controllers/ob_repository_syncs_controller.rb b/app/controllers/ob_repository_syncs_controller.rb index ebae8e427..90f7fd6fd 100644 --- a/app/controllers/ob_repository_syncs_controller.rb +++ b/app/controllers/ob_repository_syncs_controller.rb @@ -34,7 +34,7 @@ class ObRepositorySyncsController < ApplicationController def delete service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) res = service.delete_project @ob_repository_sync.sync_id - tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200" + tip_exception "删除失败: #{res["msg"]}" if res["code"].to_s != "200" if res["code"].to_s == "200" @ob_repository_sync.destroy! end @@ -43,14 +43,17 @@ class ObRepositorySyncsController < ApplicationController def jobs tip_exception "该项目未创建同步任务" if @ob_repository_sync.blank? + page = params[:page] || 1 + limit = params[:limit] || 10 service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) - res = service.get_projects_jobs - data = res["data"]["list"] + source = "" if params[:type] && params[:type].to_s.downcase == "github" - data = data.select { |row| row["github_branch"].present? } + source = "github_branch" elsif params[:type] && params[:type].to_s.downcase == "gitee" - data = data.select { |row| row["gitee_branch"].present? } + source = "gitee_branch" end + res = service.get_projects_jobs(source, page, limit) + data = res["data"]["list"] render_ok(count: res["data"]["total"], data: data) end @@ -83,7 +86,7 @@ class ObRepositorySyncsController < ApplicationController tip_exception "缺少参数job_id" if params[:job_id].blank? service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) res = service.delete_job params[:job_id] - tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200" + tip_exception "删除失败: #{res["msg"]}" if res["code"].to_s != "200" job = ObRepositorySyncJob.find_by(ob_repository_sync_id: @ob_repository_sync.id, job_id: params[:job_id]) job.destroy! if job.present? render_ok diff --git a/app/services/ob_repository_sync/api_service.rb b/app/services/ob_repository_sync/api_service.rb index 5ecd48afa..293a65928 100644 --- a/app/services/ob_repository_sync/api_service.rb +++ b/app/services/ob_repository_sync/api_service.rb @@ -42,8 +42,8 @@ class ObRepositorySync::ApiService < ApplicationService res end - def get_projects_jobs - url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs?pageSize=100&pageNum=1") + def get_projects_jobs(source, pageNum = 1, pageSize = 100) + url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs?pageSize=#{pageSize}&pageNum=#{pageNum}&source=#{source}") http = Net::HTTP.new(url.host, url.port) request = Net::HTTP::Get.new(url) request["Content-Type"] = "application/json"