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
Boxiang Sun
gitlab-ce
Commits
3f111741
Commit
3f111741
authored
Mar 16, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use "branch_name" instead "branch" on V3 branch creation API
parent
0fa511fd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
0 deletions
+77
-0
changelogs/unreleased/29604-v3-fix-branch-creation.yml
changelogs/unreleased/29604-v3-fix-branch-creation.yml
+4
-0
lib/api/v3/branches.rb
lib/api/v3/branches.rb
+21
-0
spec/requests/api/v3/branches_spec.rb
spec/requests/api/v3/branches_spec.rb
+52
-0
No files found.
changelogs/unreleased/29604-v3-fix-branch-creation.yml
0 → 100644
View file @
3f111741
---
title
:
Use "branch_name" instead "branch" on V3 branch creation API
merge_request
:
author
:
lib/api/v3/branches.rb
View file @
3f111741
...
...
@@ -45,6 +45,27 @@ module API
status
(
200
)
end
desc
'Create branch'
do
success
::
API
::
Entities
::
RepoBranch
end
params
do
requires
:branch_name
,
type:
String
,
desc:
'The name of the branch'
requires
:ref
,
type:
String
,
desc:
'Create branch from commit sha or existing branch'
end
post
":id/repository/branches"
do
authorize_push_project
result
=
CreateBranchService
.
new
(
user_project
,
current_user
).
execute
(
params
[
:branch_name
],
params
[
:ref
])
if
result
[
:status
]
==
:success
present
result
[
:branch
],
with:
::
API
::
Entities
::
RepoBranch
,
project:
user_project
else
render_api_error!
(
result
[
:message
],
400
)
end
end
end
end
end
...
...
spec/requests/api/v3/branches_spec.rb
View file @
3f111741
...
...
@@ -10,6 +10,7 @@ describe API::V3::Branches, api: true do
let!
(
:master
)
{
create
(
:project_member
,
:master
,
user:
user
,
project:
project
)
}
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
...
...
@@ -80,4 +81,55 @@ describe API::V3::Branches, api: true do
expect
(
response
).
to
have_http_status
(
403
)
end
end
describe
"POST /projects/:id/repository/branches"
do
it
"creates a new branch"
do
post
v3_api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
),
branch_name:
'feature1'
,
ref:
branch_sha
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'feature1'
)
expect
(
json_response
[
'commit'
][
'id'
]).
to
eq
(
branch_sha
)
end
it
"denies for user without push access"
do
post
v3_api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user2
),
branch_name:
branch_name
,
ref:
branch_sha
expect
(
response
).
to
have_http_status
(
403
)
end
it
'returns 400 if branch name is invalid'
do
post
v3_api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
),
branch_name:
'new design'
,
ref:
branch_sha
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Branch name is invalid'
)
end
it
'returns 400 if branch already exists'
do
post
v3_api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
),
branch_name:
'new_design1'
,
ref:
branch_sha
expect
(
response
).
to
have_http_status
(
201
)
post
v3_api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
),
branch_name:
'new_design1'
,
ref:
branch_sha
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Branch already exists'
)
end
it
'returns 400 if ref name is invalid'
do
post
v3_api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
),
branch_name:
'new_design3'
,
ref:
'foo'
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Invalid reference name'
)
end
end
end
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