diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2017-03-02 23:06:06 -0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2017-03-07 22:56:31 -0300 |
commit | d13451cd49e3380c3b69c3143cea929a9b3ec06a (patch) | |
tree | f5dbe7d0775bcbb47811e1323d7a5c1d026297b6 /lib | |
parent | c46f933bb7cb6eccdf648112a57872dc24ebf3ad (diff) | |
download | gitlab-ce-d13451cd49e3380c3b69c3143cea929a9b3ec06a.tar.gz |
Returns correct header data for commits endpoint
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/commits.rb | 24 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 15 |
2 files changed, 26 insertions, 13 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 330ad4e3d3b..42401abfe0f 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -18,22 +18,32 @@ module API optional :ref_name, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used' optional :since, type: DateTime, desc: 'Only commits after or on this date will be returned' optional :until, type: DateTime, desc: 'Only commits before or on this date will be returned' - optional :page, type: Integer, default: 0, desc: 'The page for pagination' - optional :per_page, type: Integer, default: 20, desc: 'The number of results per page' optional :path, type: String, desc: 'The file path' + use :pagination end get ":id/repository/commits" do - ref = params[:ref_name] || user_project.try(:default_branch) || 'master' + path = params[:path] + before = params[:until] + after = params[:since] + ref = params[:ref_name] || user_project.try(:default_branch) || 'master' offset = (params[:page] - 1) * params[:per_page] commits = user_project.repository.commits(ref, - path: params[:path], + path: path, limit: params[:per_page], offset: offset, - after: params[:since], - before: params[:until]) + before: before, + after: after) + + commit_count = + if path || before || after + user_project.repository.count_commits(ref: ref, path: path, before: before, after: after) + else + # Cacheable commit count. + user_project.repository.commit_count_for_ref(ref) + end - paginated_commits = Kaminari.paginate_array(commits, total_count: commits.size) + paginated_commits = Kaminari.paginate_array(commits, total_count: commit_count) present paginate(paginated_commits), with: Entities::RepoCommit end diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 0f092d4c4ab..228ef7bb7a9 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -292,6 +292,7 @@ module Gitlab } options = default_options.merge(options) + options[:limit] ||= 0 options[:offset] ||= 0 actual_ref = options[:ref] || root_ref begin @@ -354,12 +355,14 @@ module Gitlab end def count_commits(options) - cmd = %W(#{Gitlab.config.git.bin_path} --git-dir=#{path} rev-list) - cmd += %W(--after=#{options[:after].iso8601}) if options[:after] - cmd += %W(--before=#{options[:before].iso8601}) if options[:before] - cmd += %W(--count #{options[:ref]}) - cmd += %W(-- #{options[:path]}) if options[:path].present? - raw_output = IO.popen(cmd) {|io| io.read } + cmd = %W[#{Gitlab.config.git.bin_path} --git-dir=#{path} rev-list] + cmd << "--after=#{options[:after].iso8601}" if options[:after] + cmd << "--before=#{options[:before].iso8601}" if options[:before] + cmd += %W[--count #{options[:ref]}] + cmd += %W[-- #{options[:path]}] if options[:path].present? + + raw_output = IO.popen(cmd) { |io| io.read } + raw_output.to_i end |