Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a14e9cfd
Commit
a14e9cfd
authored
Sep 08, 2018
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Use find_branch! in all places
parent
ec54fd36
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
11 deletions
+15
-11
changelogs/unreleased/api-promote-find-branch.yml
changelogs/unreleased/api-promote-find-branch.yml
+5
-0
lib/api/branches.rb
lib/api/branches.rb
+0
-8
lib/api/commits.rb
lib/api/commits.rb
+2
-3
lib/api/helpers.rb
lib/api/helpers.rb
+8
-0
No files found.
changelogs/unreleased/api-promote-find-branch.yml
0 → 100644
View file @
a14e9cfd
---
title
:
'
API:
Use
find_branch!
in
all
places'
merge_request
:
21614
author
:
Robert Schilling
type
:
fixed
lib/api/branches.rb
View file @
a14e9cfd
...
@@ -9,14 +9,6 @@ module API
...
@@ -9,14 +9,6 @@ module API
before
{
authorize!
:download_code
,
user_project
}
before
{
authorize!
:download_code
,
user_project
}
helpers
do
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
params
:filter_params
do
optional
:search
,
type:
String
,
desc:
'Return list of branches matching the search criteria'
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'
optional
:sort
,
type:
String
,
desc:
'Return list of branches sorted by the given field'
...
...
lib/api/commits.rb
View file @
a14e9cfd
...
@@ -159,8 +159,7 @@ module API
...
@@ -159,8 +159,7 @@ module API
commit
=
user_project
.
commit
(
params
[
:sha
])
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
(
'Commit'
)
unless
commit
not_found!
(
'Commit'
)
unless
commit
branch
=
user_project
.
repository
.
find_branch
(
params
[
:branch
])
find_branch!
(
params
[
:branch
])
not_found!
(
'Branch'
)
unless
branch
commit_params
=
{
commit_params
=
{
commit:
commit
,
commit:
commit
,
...
@@ -171,7 +170,7 @@ module API
...
@@ -171,7 +170,7 @@ module API
result
=
::
Commits
::
CherryPickService
.
new
(
user_project
,
current_user
,
commit_params
).
execute
result
=
::
Commits
::
CherryPickService
.
new
(
user_project
,
current_user
,
commit_params
).
execute
if
result
[
:status
]
==
:success
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
present
user_project
.
repository
.
commit
(
branch
.
dereferenced_target
),
with:
Entities
::
Commit
else
else
render_api_error!
(
result
[
:message
],
400
)
render_api_error!
(
result
[
:message
],
400
)
...
...
lib/api/helpers.rb
View file @
a14e9cfd
...
@@ -156,6 +156,14 @@ module API
...
@@ -156,6 +156,14 @@ module API
end
end
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
)
def
find_project_label
(
id
)
labels
=
available_labels_for
(
user_project
)
labels
=
available_labels_for
(
user_project
)
label
=
labels
.
find_by_id
(
id
)
||
labels
.
find_by_title
(
id
)
label
=
labels
.
find_by_id
(
id
)
||
labels
.
find_by_title
(
id
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment