diff options
author | Rémy Coutable <remy@rymai.me> | 2018-09-10 08:26:31 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-09-10 08:26:31 +0000 |
commit | cee47fb31dc48d6ae16f1fb9fe3d15814a080a28 (patch) | |
tree | bd83a23d47efe68bb571b7b9aa73c5fff9224d88 | |
parent | bea943aed45c235d4c72f57a2693c1024afa662a (diff) | |
parent | 4e39fc1a407de8cb946cd70f789eacd149d6653b (diff) | |
download | gitlab-ce-cee47fb31dc48d6ae16f1fb9fe3d15814a080a28.tar.gz |
Merge branch 'api-promote-find-branch' into 'master'
API: Use find_branch! in all places
Closes #51250
See merge request gitlab-org/gitlab-ce!21614
-rw-r--r-- | changelogs/unreleased/api-promote-find-branch.yml | 5 | ||||
-rw-r--r-- | lib/api/branches.rb | 8 | ||||
-rw-r--r-- | lib/api/commits.rb | 5 | ||||
-rw-r--r-- | lib/api/helpers.rb | 6 |
4 files changed, 13 insertions, 11 deletions
diff --git a/changelogs/unreleased/api-promote-find-branch.yml b/changelogs/unreleased/api-promote-find-branch.yml new file mode 100644 index 00000000000..cfa767809b2 --- /dev/null +++ b/changelogs/unreleased/api-promote-find-branch.yml @@ -0,0 +1,5 @@ +--- +title: 'API: Use find_branch! in all places' +merge_request: 21614 +author: Robert Schilling +type: fixed diff --git a/lib/api/branches.rb b/lib/api/branches.rb index 3e445e6b1fa..6c1d445e53d 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -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' diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 92329465b2c..3e8de3c8dae 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -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) diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index be17653dbb2..5505d7a7b08 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -156,6 +156,12 @@ module API end end + def find_branch!(branch_name) + user_project.repository.find_branch(branch_name) || not_found!('Branch') + rescue Gitlab::Git::CommandError + render_api_error!('The branch refname is invalid', 400) + end + def find_project_label(id) labels = available_labels_for(user_project) label = labels.find_by_id(id) || labels.find_by_title(id) |