BigW Consortium Gitlab

Commit 960b8cd4 by Sean McGivern

Merge branch 'api_branches_head' into 'master'

Add branch existence check to the APIv4 branches via HEAD request Closes #37159 See merge request !13979
parents f19910b5 02aa269e
---
title: Add branch existence check to the APIv4 branches via HEAD request
merge_request: 13979
author: Vitaliy @blackst0ne Klachkov
type: added
......@@ -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.
......
......@@ -75,6 +75,22 @@ describe API::Branches do
let(:route) { "/projects/#{project_id}/repository/branches/#{branch_name}" }
shared_examples_for 'repository branch' do
context 'HEAD request' do
it 'returns 204 No Content' do
head api(route, user)
expect(response).to have_gitlab_http_status(204)
expect(response.body).to be_empty
end
it 'returns 404 Not Found' do
head api("/projects/#{project_id}/repository/branches/unknown", user)
expect(response).to have_gitlab_http_status(404)
expect(response.body).to be_empty
end
end
it 'returns the repository branch' do
get api(route, current_user)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment