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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
4e3e0dc8
Commit
4e3e0dc8
authored
Jul 27, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY the branches API requirements definition
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
649382b1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
6 deletions
+11
-6
changelogs/unreleased/rc-fix-branches-api-endpoint.yml
changelogs/unreleased/rc-fix-branches-api-endpoint.yml
+1
-1
lib/api/api.rb
lib/api/api.rb
+3
-0
lib/api/branches.rb
lib/api/branches.rb
+7
-5
No files found.
changelogs/unreleased/rc-fix-branches-api-endpoint.yml
View file @
4e3e0dc8
---
---
title
:
Fix the /projects/:id/repository/branches endpoint to handle dots in the branch
title
:
Fix the /projects/:id/repository/branches endpoint to handle dots in the branch
name when the project full patch contains a `/`
name when the project full patch contains a `/`
merge_request
:
merge_request
:
13115
author
:
author
:
lib/api/api.rb
View file @
4e3e0dc8
...
@@ -86,6 +86,9 @@ module API
...
@@ -86,6 +86,9 @@ module API
helpers
::
API
::
Helpers
helpers
::
API
::
Helpers
helpers
::
API
::
Helpers
::
CommonHelpers
helpers
::
API
::
Helpers
::
CommonHelpers
NO_SLASH_URL_PART_REGEX
=
%r{[^/]+}
PROJECT_ENDPOINT_REQUIREMENTS
=
{
id:
NO_SLASH_URL_PART_REGEX
}.
freeze
# Keep in alphabetical order
# Keep in alphabetical order
mount
::
API
::
AccessRequests
mount
::
API
::
AccessRequests
mount
::
API
::
AwardEmoji
mount
::
API
::
AwardEmoji
...
...
lib/api/branches.rb
View file @
4e3e0dc8
...
@@ -4,12 +4,14 @@ module API
...
@@ -4,12 +4,14 @@ module API
class
Branches
<
Grape
::
API
class
Branches
<
Grape
::
API
include
PaginationParams
include
PaginationParams
BRANCH_ENDPOINT_REQUIREMENTS
=
API
::
PROJECT_ENDPOINT_REQUIREMENTS
.
merge
(
branch:
API
::
NO_SLASH_URL_PART_REGEX
)
before
{
authorize!
:download_code
,
user_project
}
before
{
authorize!
:download_code
,
user_project
}
params
do
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
end
resource
:projects
,
requirements:
{
id:
%r{[^/]+}
}
do
resource
:projects
,
requirements:
API
::
PROJECT_ENDPOINT_REQUIREMENTS
do
desc
'Get a project repository branches'
do
desc
'Get a project repository branches'
do
success
Entities
::
RepoBranch
success
Entities
::
RepoBranch
end
end
...
@@ -28,7 +30,7 @@ module API
...
@@ -28,7 +30,7 @@ module API
params
do
params
do
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
end
end
get
':id/repository/branches/:branch'
,
requirements:
{
id:
%r{[^/]+}
,
branch:
%r{[^/]+}
}
do
get
':id/repository/branches/:branch'
,
requirements:
BRANCH_ENDPOINT_REQUIREMENTS
do
branch
=
user_project
.
repository
.
find_branch
(
params
[
:branch
])
branch
=
user_project
.
repository
.
find_branch
(
params
[
:branch
])
not_found!
(
"Branch"
)
unless
branch
not_found!
(
"Branch"
)
unless
branch
...
@@ -46,7 +48,7 @@ module API
...
@@ -46,7 +48,7 @@ module API
optional
:developers_can_push
,
type:
Boolean
,
desc:
'Flag if developers can push to that branch'
optional
:developers_can_push
,
type:
Boolean
,
desc:
'Flag if developers can push to that branch'
optional
:developers_can_merge
,
type:
Boolean
,
desc:
'Flag if developers can merge to that branch'
optional
:developers_can_merge
,
type:
Boolean
,
desc:
'Flag if developers can merge to that branch'
end
end
put
':id/repository/branches/:branch/protect'
,
requirements:
{
id:
%r{[^/]+}
,
branch:
%r{[^/]+}
}
do
put
':id/repository/branches/:branch/protect'
,
requirements:
BRANCH_ENDPOINT_REQUIREMENTS
do
authorize_admin_project
authorize_admin_project
branch
=
user_project
.
repository
.
find_branch
(
params
[
:branch
])
branch
=
user_project
.
repository
.
find_branch
(
params
[
:branch
])
...
@@ -81,7 +83,7 @@ module API
...
@@ -81,7 +83,7 @@ module API
params
do
params
do
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
end
end
put
':id/repository/branches/:branch/unprotect'
,
requirements:
{
id:
%r{[^/]+}
,
branch:
%r{[^/]+}
}
do
put
':id/repository/branches/:branch/unprotect'
,
requirements:
BRANCH_ENDPOINT_REQUIREMENTS
do
authorize_admin_project
authorize_admin_project
branch
=
user_project
.
repository
.
find_branch
(
params
[
:branch
])
branch
=
user_project
.
repository
.
find_branch
(
params
[
:branch
])
...
@@ -118,7 +120,7 @@ module API
...
@@ -118,7 +120,7 @@ module API
params
do
params
do
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
end
end
delete
':id/repository/branches/:branch'
,
requirements:
{
id:
%r{[^/]+}
,
branch:
%r{[^/]+}
}
do
delete
':id/repository/branches/:branch'
,
requirements:
BRANCH_ENDPOINT_REQUIREMENTS
do
authorize_push_project
authorize_push_project
result
=
DeleteBranchService
.
new
(
user_project
,
current_user
)
result
=
DeleteBranchService
.
new
(
user_project
,
current_user
)
...
...
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