Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2018-02-13 22:22:37 +0300
committerRobert Schilling <rschilling@student.tugraz.at>2018-02-14 12:16:34 +0300
commita724f7e35f9f8ed9692b0f3f4d6c8a62632cdec4 (patch)
tree07c821347130287119ad58dd4fe07e1a0552370b /lib
parent922d156a5e0412a12662df94e03479f7ed015f7b (diff)
Refactor commits/refs API to use hash and add pagination headers
Diffstat (limited to 'lib')
-rw-r--r--lib/api/commits.rb19
-rw-r--r--lib/api/entities.rb8
2 files changed, 8 insertions, 19 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
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index c7a817877f0..c8cda85b170 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -277,13 +277,7 @@ module API
end
class BasicRef < Grape::Entity
- expose :branch_name, if: lambda { |ref, options| ref[1] } do |ref, options|
- ref[0]
- end
-
- expose :tag_name, if: lambda { |ref, options| !ref[1] } do |ref, options|
- ref[0]
- end
+ expose :type, :name
end
class Branch < Grape::Entity