Commit a14e9cfd authored by Robert Schilling's avatar Robert Schilling

API: Use find_branch! in all places

parent ec54fd36
---
title: 'API: Use find_branch! in all places'
merge_request: 21614
author: Robert Schilling
type: fixed
......@@ -9,14 +9,6 @@ module API
before { authorize! :download_code, user_project }
helpers do
def find_branch!(branch_name)
begin
user_project.repository.find_branch(branch_name) || not_found!('Branch')
rescue Gitlab::Git::CommandError
render_api_error!('The branch refname is invalid', 400)
end
end
params :filter_params do
optional :search, type: String, desc: 'Return list of branches matching the search criteria'
optional :sort, type: String, desc: 'Return list of branches sorted by the given field'
......
......@@ -159,8 +159,7 @@ module API
commit = user_project.commit(params[:sha])
not_found!('Commit') unless commit
branch = user_project.repository.find_branch(params[:branch])
not_found!('Branch') unless branch
find_branch!(params[:branch])
commit_params = {
commit: commit,
......@@ -171,7 +170,7 @@ module API
result = ::Commits::CherryPickService.new(user_project, current_user, commit_params).execute
if result[:status] == :success
branch = user_project.repository.find_branch(params[:branch])
branch = find_branch!(params[:branch])
present user_project.repository.commit(branch.dereferenced_target), with: Entities::Commit
else
render_api_error!(result[:message], 400)
......
......@@ -156,6 +156,14 @@ module API
end
end
def find_branch!(branch_name)
begin
user_project.repository.find_branch(branch_name) || not_found!('Branch')
rescue Gitlab::Git::CommandError
render_api_error!('The branch refname is invalid', 400)
end
end
def find_project_label(id)
labels = available_labels_for(user_project)
label = labels.find_by_id(id) || labels.find_by_title(id)
......
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