From 473cab818aff034d072f0f6c8537a584bc5aa41c Mon Sep 17 00:00:00 2001 From: Jordan Ryan Reuter Date: Fri, 20 Jan 2017 10:04:16 -0500 Subject: Manually set total_count when paginating commits `Kaminari.paginate_array` takes some options, most relevant of which is a `total_count` parameter. Using the `commit_count` for `total_count` lets us correctly treat the return of `Repository#commits` as a subset of all the commits we may wish to list. Addition of a new `Repository#commit_count_for_ref` method was necessarry to allow the user to start from an arbitrary ref. Ref #1381 --- lib/api/commits.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/api') diff --git a/lib/api/commits.rb b/lib/api/commits.rb index b0aa10f8bf2..6205bff3bc0 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -33,7 +33,10 @@ module API after: params[:since], before: params[:until]) - present commits, with: Entities::RepoCommit + commit_count = user_project.repository.commit_count_for_ref(ref) + paginated_commits = Kaminari.paginate_array(commits, total_count: commit_count) + + present paginate(paginated_commits), with: Entities::RepoCommit end desc 'Commit multiple file changes as one commit' do -- cgit v1.2.1