新增:贡献者分页
This commit is contained in:
parent
ec85b80a98
commit
3762a54eff
|
@ -166,8 +166,9 @@ class RepositoriesController < ApplicationController
|
||||||
if params[:filepath].present? || @project.educoder?
|
if params[:filepath].present? || @project.educoder?
|
||||||
@contributors = []
|
@contributors = []
|
||||||
else
|
else
|
||||||
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier)
|
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier, {page: params[:page], limit: params[:limit]})
|
||||||
@contributors = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
@total_count = result[:total_count]
|
||||||
|
@contributors = result.is_a?(Hash) ? result[:body] : []
|
||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
@contributors = []
|
@contributors = []
|
||||||
|
|
|
@ -1,22 +1,38 @@
|
||||||
class Gitea::Repository::Contributors::GetService < Gitea::ClientService
|
class Gitea::Repository::Contributors::GetService < Gitea::ClientService
|
||||||
attr_reader :owner, :repo_name
|
attr_reader :owner, :repo_name, :page, :limit
|
||||||
|
|
||||||
def initialize(owner, repo_name)
|
def initialize(owner, repo_name, page, limit)
|
||||||
@owner = owner
|
@owner = owner
|
||||||
@repo_name = repo_name
|
@repo_name = repo_name
|
||||||
|
@page = params[:page] || 1
|
||||||
|
@limit = params[:limit] || 20
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
response = get(url, params)
|
response = get(url, params)
|
||||||
render_status(response)
|
render_result(response)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def params
|
def params
|
||||||
Hash.new.merge(token: owner.gitea_token)
|
Hash.new.merge(token: owner.gitea_token, page: page, limit: limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
"/repos/#{owner.login}/#{repo_name}/contributors"
|
"/repos/#{owner.login}/#{repo_name}/contributors"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_result(response)
|
||||||
|
case response.status
|
||||||
|
when 200
|
||||||
|
result = {}
|
||||||
|
headers = response.headers.to_hash
|
||||||
|
body = JSON.parse(response.body)
|
||||||
|
total_count = headers["x-total"]
|
||||||
|
result.merge(total_count: total_count.to_i, body: body)
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
# {status: -1, message: "#{body['message']}"}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,7 +1,6 @@
|
||||||
total_count = @contributors.size
|
|
||||||
json.list @contributors.each do |contributor|
|
json.list @contributors.each do |contributor|
|
||||||
json.partial! 'contributor', locals: { contributor: contributor, project: @project }
|
json.partial! 'contributor', locals: { contributor: contributor, project: @project }
|
||||||
end
|
end
|
||||||
json.total_count total_count
|
json.total_count @total_count
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue