新增:历史记录分页
This commit is contained in:
parent
d385319764
commit
2a3f2fb620
|
@ -113,14 +113,8 @@ class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController
|
|||
|
||||
def history
|
||||
return render_error("请输入正确的同步分支ID") unless params[:reposync_branch_ids]
|
||||
@reposync_branch_logs = []
|
||||
params[:reposync_branch_ids].split(",").each do |branch_id|
|
||||
@branch = SyncRepositoryBranch.find_by(reposync_branch_id: branch_id)
|
||||
repo = @branch&.sync_repository
|
||||
_, logs, _ = Reposync::GetLogsService.call(repo&.repo_name, branch_id)
|
||||
@reposync_branch_logs += logs
|
||||
end
|
||||
@reposync_branch_logs = @reposync_branch_logs.sort_by{|log|log["update_at"]}
|
||||
@branch = SyncRepositoryBranch.find_by(reposync_branch_id: params[:reposync_branch_ids].split(",")[0])
|
||||
_, @reposync_branch_logs, _ = Reposync::GetLogsService.call(nil, params[:reposync_branch_ids], page, limit)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
class Reposync::GetLogsService < Reposync::ClientService
|
||||
|
||||
attr_accessor :repo_name, :branch_id
|
||||
attr_accessor :repo_name, :branch_id, :page_num, :page_size
|
||||
|
||||
def initialize(repo_name, branch_id=nil)
|
||||
def initialize(repo_name=nil, branch_id=nil, page_num=1, page_size=10)
|
||||
@repo_name = repo_name
|
||||
@branch_id = branch_id
|
||||
@page_num = page_num
|
||||
@page_size = page_size
|
||||
end
|
||||
|
||||
def call
|
||||
|
@ -14,10 +16,18 @@ class Reposync::GetLogsService < Reposync::ClientService
|
|||
|
||||
private
|
||||
def request_params
|
||||
branch_id.present? ? {branch_id: branch_id}.stringify_keys : {}
|
||||
params = {
|
||||
page_num: page_num,
|
||||
page_size: page_size,
|
||||
create_sort: true
|
||||
}
|
||||
params.merge(repo_name: repo_name) if repo_name.present?
|
||||
params.merge(branch_id: branch_id) if branch_id.present?
|
||||
|
||||
return params.stringify_keys
|
||||
end
|
||||
|
||||
def url
|
||||
"/cerobot/sync/repo/#{repo_name}/logs"
|
||||
"/cerobot/sync/repo/logs"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue