summaryrefslogtreecommitdiff
path: root/lib/api/commits.rb
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2018-02-13 20:22:37 +0100
committerRobert Schilling <rschilling@student.tugraz.at>2018-02-14 10:16:34 +0100
commita724f7e35f9f8ed9692b0f3f4d6c8a62632cdec4 (patch)
tree07c821347130287119ad58dd4fe07e1a0552370b /lib/api/commits.rb
parent922d156a5e0412a12662df94e03479f7ed015f7b (diff)
downloadgitlab-ce-a724f7e35f9f8ed9692b0f3f4d6c8a62632cdec4.tar.gz
Refactor commits/refs API to use hash and add pagination headers
Diffstat (limited to 'lib/api/commits.rb')
-rw-r--r--lib/api/commits.rb19
1 files changed, 7 insertions, 12 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index afaf68114e8..d83c43ee49b 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -162,24 +162,19 @@ module API
end
params do
requires :sha, type: String, desc: 'A commit sha'
- optional :type, type: String, values: %w[branches tags all], default: 'all', desc: 'Scope'
+ optional :type, type: String, values: %w[branch tag all], default: 'all', desc: 'Scope'
+ use :pagination
end
get ':id/repository/commits/:sha/refs', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
commit = user_project.commit(params[:sha])
not_found!('Commit') unless commit
- refs =
- case params[:type]
- when 'branches'
- user_project.repository.branch_names_contains(commit.id).map {|branch_name| [branch_name, true]}
- when 'tags'
- user_project.repository.tag_names_contains(commit.id).map {|tag_name| [tag_name, false]}
- else
- refs = user_project.repository.branch_names_contains(commit.id).map {|branch_name| [branch_name, true]}
- refs.concat(user_project.repository.tag_names_contains(commit.id).map {|tag_name| [tag_name, false]})
- end
+ refs = []
+ refs.concat(user_project.repository.branch_names_contains(commit.id).map {|name| { type: 'branch', name: name }}) unless params[:type] == 'tag'
+ refs.concat(user_project.repository.tag_names_contains(commit.id).map {|name| { type: 'tag', name: name }}) unless params[:type] == 'branch'
+ refs = Kaminari.paginate_array(refs)
- present refs, with: Entities::BasicRef
+ present paginate(refs), with: Entities::BasicRef
end
desc 'Post comment to commit' do