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:
authorDouwe Maan <douwe@gitlab.com>2018-02-14 12:58:31 +0300
committerDouwe Maan <douwe@gitlab.com>2018-02-14 12:58:31 +0300
commit7da1a3d7a30976090d437d7a0fcefe7ac2548ab3 (patch)
tree4c818fadad756e0811b1a5b02e1d1cfadd3e4fb1 /lib
parentc203c622c5134ea53e7bf9624c9c99b2386869e5 (diff)
parenta724f7e35f9f8ed9692b0f3f4d6c8a62632cdec4 (diff)
Merge branch 'api-refs-for-commit' into 'master'
API: Get refs for a particular commit Closes #18014 See merge request gitlab-org/gitlab-ce!15026
Diffstat (limited to 'lib')
-rw-r--r--lib/api/commits.rb23
-rw-r--r--lib/api/entities.rb4
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index d8fd6a6eb06..d83c43ee49b 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -156,6 +156,27 @@ module API
end
end
+ desc 'Get all references a commit is pushed to' do
+ detail 'This feature was introduced in GitLab 10.6'
+ success Entities::BasicRef
+ end
+ params do
+ requires :sha, type: String, desc: 'A commit sha'
+ 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 = []
+ 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 paginate(refs), with: Entities::BasicRef
+ end
+
desc 'Post comment to commit' do
success Entities::CommitNote
end
@@ -165,7 +186,7 @@ module API
optional :path, type: String, desc: 'The file path'
given :path do
requires :line, type: Integer, desc: 'The line number'
- requires :line_type, type: String, values: %w(new old), default: 'new', desc: 'The type of the line'
+ requires :line_type, type: String, values: %w[new old], default: 'new', desc: 'The type of the line'
end
end
post ':id/repository/commits/:sha/comments', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 7838de13c56..c8cda85b170 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -276,6 +276,10 @@ module API
expose :last_pipeline, using: 'API::Entities::PipelineBasic'
end
+ class BasicRef < Grape::Entity
+ expose :type, :name
+ end
+
class Branch < Grape::Entity
expose :name