summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLeonid Batizhevskii <Batizhevskii@fidor.com>2018-06-06 15:15:35 +0300
committerLeonid Batizhevsky <l.batizhevsky@fun-box.ru>2018-06-12 17:15:53 +0200
commit404ef05002e067d057dabafb4945d79a49d028bc (patch)
tree3a7a5f674bffe1c07855c7352f364d033a398003 /lib
parent760b12dc6b3a927c918855e2ee85a1c0e6bddb73 (diff)
downloadgitlab-ce-404ef05002e067d057dabafb4945d79a49d028bc.tar.gz
Added with_statsoption for GET /projects/:id/repository/commits
Diffstat (limited to 'lib')
-rw-r--r--lib/api/commits.rb22
-rw-r--r--lib/api/entities.rb4
2 files changed, 17 insertions, 9 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index 684955a1b24..964780cba6a 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -15,19 +15,21 @@ module API
end
params do
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 :path, type: String, desc: 'The file path'
- optional :all, type: Boolean, desc: 'Every commit will be returned'
+ 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 :path, type: String, desc: 'The file path'
+ optional :all, type: Boolean, desc: 'Every commit will be returned'
+ optional :with_stats, type: Boolean, desc: 'Stats about each commit will be added to the response'
use :pagination
end
get ':id/repository/commits' do
- path = params[:path]
+ path = params[:path]
before = params[:until]
- after = params[:since]
- ref = params[:ref_name] || user_project.try(:default_branch) || 'master' unless params[:all]
+ after = params[:since]
+ ref = params[:ref_name] || user_project.try(:default_branch) || 'master' unless params[:all]
offset = (params[:page] - 1) * params[:per_page]
- all = params[:all]
+ all = params[:all]
+ with_stats = params[:with_stats]
commits = user_project.repository.commits(ref,
path: path,
@@ -47,7 +49,9 @@ module API
paginated_commits = Kaminari.paginate_array(commits, total_count: commit_count)
- present paginate(paginated_commits), with: Entities::Commit
+ serializer = with_stats ? Entities::CommitWithStats : Entities::Commit
+
+ present paginate(paginated_commits), with: serializer
end
desc 'Commit multiple file changes as one commit' do
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 22afcb9edf2..52e716a7686 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -308,6 +308,10 @@ module API
expose :additions, :deletions, :total
end
+ class CommitWithStats < Commit
+ expose :stats, using: Entities::CommitStats
+ end
+
class CommitDetail < Commit
expose :stats, using: Entities::CommitStats, if: :stats
expose :status