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
Léo-Paul Géneau
gitlab-ce
Commits
4a0ca858
Commit
4a0ca858
authored
Dec 06, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow branch names with dots on API endpoint
parent
a361eb2f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
8 deletions
+43
-8
changelogs/unreleased/issue_25030.yml
changelogs/unreleased/issue_25030.yml
+4
-0
lib/api/branches.rb
lib/api/branches.rb
+8
-8
spec/requests/api/branches_spec.rb
spec/requests/api/branches_spec.rb
+31
-0
No files found.
changelogs/unreleased/issue_25030.yml
0 → 100644
View file @
4a0ca858
---
title
:
Allow branch names with dots on API endpoint
merge_request
:
author
:
lib/api/branches.rb
View file @
4a0ca858
...
...
@@ -23,9 +23,9 @@ module API
success
Entities
::
RepoBranch
end
params
do
requires
:branch
,
type:
String
,
regexp:
/.+/
,
desc:
'The name of the branch'
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
end
get
':id/repository/branches/:branch'
do
get
':id/repository/branches/:branch'
,
requirements:
{
branch:
/.+/
}
do
branch
=
user_project
.
repository
.
find_branch
(
params
[
:branch
])
not_found!
(
"Branch"
)
unless
branch
...
...
@@ -39,11 +39,11 @@ module API
success
Entities
::
RepoBranch
end
params
do
requires
:branch
,
type:
String
,
regexp:
/.+/
,
desc:
'The name of the branch'
requires
:branch
,
type:
String
,
desc:
'The name of the 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'
end
put
':id/repository/branches/:branch/protect'
do
put
':id/repository/branches/:branch/protect'
,
requirements:
{
branch:
/.+/
}
do
authorize_admin_project
branch
=
user_project
.
repository
.
find_branch
(
params
[
:branch
])
...
...
@@ -76,9 +76,9 @@ module API
success
Entities
::
RepoBranch
end
params
do
requires
:branch
,
type:
String
,
regexp:
/.+/
,
desc:
'The name of the branch'
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
end
put
':id/repository/branches/:branch/unprotect'
do
put
':id/repository/branches/:branch/unprotect'
,
requirements:
{
branch:
/.+/
}
do
authorize_admin_project
branch
=
user_project
.
repository
.
find_branch
(
params
[
:branch
])
...
...
@@ -112,9 +112,9 @@ module API
desc
'Delete a branch'
params
do
requires
:branch
,
type:
String
,
regexp:
/.+/
,
desc:
'The name of the branch'
requires
:branch
,
type:
String
,
desc:
'The name of the branch'
end
delete
":id/repository/branches/:branch"
do
delete
":id/repository/branches/:branch"
,
requirements:
{
branch:
/.+/
}
do
authorize_push_project
result
=
DeleteBranchService
.
new
(
user_project
,
current_user
).
...
...
spec/requests/api/branches_spec.rb
View file @
4a0ca858
...
...
@@ -11,6 +11,7 @@ describe API::Branches, api: true do
let!
(
:guest
)
{
create
(
:project_member
,
:guest
,
user:
user2
,
project:
project
)
}
let!
(
:branch_name
)
{
'feature'
}
let!
(
:branch_sha
)
{
'0b4bc9a49b562e85de7cc9e834518ea6828729b9'
}
let!
(
:branch_with_dot
)
{
CreateBranchService
.
new
(
project
,
user
).
execute
(
"with.1.2.3"
,
"master"
)
}
describe
"GET /projects/:id/repository/branches"
do
it
"returns an array of project branches"
do
...
...
@@ -37,6 +38,13 @@ describe API::Branches, api: true do
expect
(
json_response
[
'developers_can_merge'
]).
to
eq
(
false
)
end
it
"returns the branch information for a single branch with dots in the name"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/branches/with.1.2.3"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
"with.1.2.3"
)
end
context
'on a merged branch'
do
it
"returns the branch information for a single branch"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/branches/merge-test"
,
user
)
...
...
@@ -71,6 +79,14 @@ describe API::Branches, api: true do
expect
(
json_response
[
'developers_can_merge'
]).
to
eq
(
false
)
end
it
"protects a single branch with dots in the name"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/with.1.2.3/protect"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
"with.1.2.3"
)
expect
(
json_response
[
'protected'
]).
to
eq
(
true
)
end
it
'protects a single branch and developers can push'
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
/protect"
,
user
),
developers_can_push:
true
...
...
@@ -220,6 +236,14 @@ describe API::Branches, api: true do
expect
(
json_response
[
'protected'
]).
to
eq
(
false
)
end
it
"update branches with dots in branch name"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/with.1.2.3/unprotect"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
"with.1.2.3"
)
expect
(
json_response
[
'protected'
]).
to
eq
(
false
)
end
it
"returns success when unprotect branch"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/unknown/unprotect"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
...
...
@@ -292,6 +316,13 @@ describe API::Branches, api: true do
expect
(
json_response
[
'branch_name'
]).
to
eq
(
branch_name
)
end
it
"removes a branch with dots in the branch name"
do
delete
api
(
"/projects/
#{
project
.
id
}
/repository/branches/with.1.2.3"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'branch_name'
]).
to
eq
(
"with.1.2.3"
)
end
it
'returns 404 if branch not exists'
do
delete
api
(
"/projects/
#{
project
.
id
}
/repository/branches/foobar"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
...
...
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