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
1069ffb8
Commit
1069ffb8
authored
Apr 01, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'branch-via-api' into 'master'
Create branch via API Fixes #1096
parents
2d3d210b
a88225b7
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
85 additions
and
5 deletions
+85
-5
CHANGELOG
CHANGELOG
+1
-0
app/controllers/projects/branches_controller.rb
app/controllers/projects/branches_controller.rb
+1
-5
app/services/create_branch_service.rb
app/services/create_branch_service.rb
+13
-0
doc/api/branches.md
doc/api/branches.md
+31
-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.
CHANGELOG
View file @
1069ffb8
...
...
@@ -5,6 +5,7 @@ v 6.8.0
- Remove omniauth-ldap nickname bug workaround
- Drop all tables before restoring a Postgres backup
- Make the repository downloads path configurable
- Create branches via API (sponsored by O'Reilly Media)
v 6.7.2
- Fix upgrader script
...
...
app/controllers/projects/branches_controller.rb
View file @
1069ffb8
...
...
@@ -16,11 +16,7 @@ class Projects::BranchesController < Projects::ApplicationController
end
def
create
@repository
.
add_branch
(
params
[
:branch_name
],
params
[
:ref
])
if
new_branch
=
@repository
.
find_branch
(
params
[
:branch_name
])
Event
.
create_ref_event
(
@project
,
current_user
,
new_branch
,
'add'
)
end
CreateBranchService
.
new
.
execute
(
project
,
params
[
:branch_name
],
params
[
:ref
],
current_user
)
redirect_to
project_branches_path
(
@project
)
end
...
...
app/services/create_branch_service.rb
0 → 100644
View file @
1069ffb8
class
CreateBranchService
def
execute
(
project
,
branch_name
,
ref
,
current_user
)
repository
=
project
.
repository
repository
.
add_branch
(
branch_name
,
ref
)
new_branch
=
repository
.
find_branch
(
branch_name
)
if
new_branch
Event
.
create_ref_event
(
project
,
current_user
,
new_branch
,
'add'
)
end
new_branch
end
end
doc/api/branches.md
View file @
1069ffb8
...
...
@@ -165,3 +165,34 @@ Parameters:
"protected"
:
false
}
```
## Create repository branch
```
POST /projects/:id/repository/branches
```
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
```
json
{
"name"
:
"my-new-branch"
,
"commit"
:
{
"id"
:
"8848c0e90327a0b70f1865b843fb2fbfb9345e57"
,
"message"
:
"Merge pull request #54 from brightbox/use_fog_brightbox_module
\n\n
Update to use fog-brightbox module"
,
"parent_ids"
:
[
"fff449e0bf453576f16c91d6544f00a2664009d8"
,
"f93a93626fec20fd659f4ed3ab2e64019b6169ae"
],
"authored_date"
:
"2014-02-20T19:54:55+02:00"
,
"author_name"
:
"john smith"
,
"author_email"
:
"john@example.com"
,
"committed_date"
:
"2014-02-20T19:54:55+02:00"
,
"committer_name"
:
"john smith"
,
"committer_email"
:
"john@example.com"
},
"protected"
:
false
}
```
lib/api/branches.rb
View file @
1069ffb8
...
...
@@ -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 @
1069ffb8
...
...
@@ -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 @
1069ffb8
...
...
@@ -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