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
iv
gitlab-ce
Commits
33a00cee
Commit
33a00cee
authored
Apr 01, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create branch via API
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
95b84e2c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
0 deletions
+39
-0
lib/api/branches.rb
lib/api/branches.rb
+15
-0
lib/api/helpers.rb
lib/api/helpers.rb
+4
-0
spec/requests/api/branches_spec.rb
spec/requests/api/branches_spec.rb
+20
-0
No files found.
lib/api/branches.rb
View file @
33a00cee
...
...
@@ -65,6 +65,21 @@ module API
present
@branch
,
with:
Entities
::
RepoObject
,
project:
user_project
end
# Create branch
#
# Parameters:
# id (required) - The ID of a project
# branch_name (required) - The name of the branch
# ref (required) - Create branch from commit sha or existing branch
# Example Request:
# POST /projects/:id/repository/branches
post
":id/repository/branches"
do
authorize_push_project
@branch
=
CreateBranchService
.
new
.
execute
(
user_project
,
params
[
:branch_name
],
params
[
:ref
],
current_user
)
present
@branch
,
with:
Entities
::
RepoObject
,
project:
user_project
end
end
end
end
lib/api/helpers.rb
View file @
33a00cee
...
...
@@ -78,6 +78,10 @@ module API
end
end
def
authorize_push_project
authorize!
:push_code
,
user_project
end
def
authorize_admin_project
authorize!
:admin_project
,
user_project
end
...
...
spec/requests/api/branches_spec.rb
View file @
33a00cee
...
...
@@ -92,4 +92,24 @@ describe API::API do
end
describe
"POST /projects/:id/repository/branches"
do
it
"should create a new branch"
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
),
branch_name:
'new_design'
,
ref:
'621491c677087aa243f165eab467bfdfbee00be1'
response
.
status
.
should
==
201
json_response
[
'name'
].
should
==
'new_design'
json_response
[
'commit'
][
'id'
].
should
==
'621491c677087aa243f165eab467bfdfbee00be1'
end
it
"should deny for user without push access"
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user2
),
branch_name:
'new_design'
,
ref:
'621491c677087aa243f165eab467bfdfbee00be1'
response
.
status
.
should
==
403
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