diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-09-05 11:05:30 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-09-05 11:05:30 +0000 |
commit | 960b8cd46094fd5ff8ac11267a6998af8d97ee22 (patch) | |
tree | f5c39b11f16faeac6eea16165b26ebfc2bfd6afe /lib/api | |
parent | f19910b56dea355b7606d38dbda07ab93bcbaad3 (diff) | |
parent | 02aa269e34b7c05a52e5226fc02d91ffbbb6010f (diff) | |
download | gitlab-ce-960b8cd46094fd5ff8ac11267a6998af8d97ee22.tar.gz |
Merge branch 'api_branches_head' into 'master'
Add branch existence check to the APIv4 branches via HEAD request
Closes #37159
See merge request !13979
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/branches.rb | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/api/branches.rb b/lib/api/branches.rb index a989394ad91..642c1140fcc 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -24,17 +24,22 @@ module API present paginate(branches), with: Entities::RepoBranch, project: user_project end - desc 'Get a single branch' do - success Entities::RepoBranch - end - params do - requires :branch, type: String, desc: 'The name of the branch' - end - get ':id/repository/branches/:branch', requirements: BRANCH_ENDPOINT_REQUIREMENTS do - branch = user_project.repository.find_branch(params[:branch]) - not_found!("Branch") unless branch + resource ':id/repository/branches/:branch', requirements: BRANCH_ENDPOINT_REQUIREMENTS do + desc 'Get a single branch' do + success Entities::RepoBranch + end + params do + requires :branch, type: String, desc: 'The name of the branch' + end + head do + user_project.repository.branch_exists?(params[:branch]) ? status(204) : status(404) + end + get do + branch = user_project.repository.find_branch(params[:branch]) + not_found!('Branch') unless branch - present branch, with: Entities::RepoBranch, project: user_project + present branch, with: Entities::RepoBranch, project: user_project + end end # Note: This API will be deprecated in favor of the protected branches API. |