summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2017-10-24 13:28:06 +0300
committerRobert Schilling <rschilling@student.tugraz.at>2018-02-09 13:25:02 +0100
commitcea2a8f741d623ca2085e8149112de3a20a4779f (patch)
tree373d81aa73e0baf0f4210e3873ab21583e5a650b /lib/api
parent7534f7a892d6e8c50475720e387b8689c94582da (diff)
downloadgitlab-ce-cea2a8f741d623ca2085e8149112de3a20a4779f.tar.gz
Basic ref fetching for commits
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/commits.rb25
-rw-r--r--lib/api/entities.rb16
2 files changed, 38 insertions, 3 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index d8fd6a6eb06..3cf88551fa7 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -156,6 +156,31 @@ module API
end
end
+ desc 'Get all reference a commit is pushed to' do
+ detail 'This feature was introduced in GitLab 10.6'
+ success Entities::SimpleRef
+ end
+ params do
+ requires :sha, type: String, desc: 'A commit sha'
+ optional :type, type: String, values: %w(branches tags all), default: 'all', desc: 'Scope'
+ end
+ get ':id/repository/commits/:sha/refs', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
+ commit = user_project.commit(params[:sha])
+ not_found!('Commit') unless commit
+
+ case params[:type]
+ when 'branches'
+ refs = user_project.repository.branch_names_contains(commit.id)
+ when 'tags'
+ refs = user_project.repository.tag_names_contains(commit.id)
+ else
+ refs = user_project.repository.branch_names_contains(commit.id)
+ refs.push(*user_project.repository.tag_names_contains(commit.id))
+ end
+
+ present refs, with: Entities::SimpleRef
+ end
+
desc 'Post comment to commit' do
success Entities::CommitNote
end
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 7838de13c56..e8c9ba6fce5 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -276,7 +276,17 @@ module API
expose :last_pipeline, using: 'API::Entities::PipelineBasic'
end
- class Branch < Grape::Entity
+ class BasicRef < Grape::Entity
+ expose :name
+ end
+
+ class SimpleRef < Grape::Entity
+ expose :name do |ref, options|
+ ref
+ end
+ end
+
+ class Branch < BasicRef
expose :name
expose :commit, using: Entities::Commit do |repo_branch, options|
@@ -845,8 +855,8 @@ module API
expose :description
end
- class Tag < Grape::Entity
- expose :name, :message
+ class Tag < BasicRef
+ expose :message
expose :commit, using: Entities::Commit do |repo_tag, options|
options[:project].repository.commit(repo_tag.dereferenced_target)