diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-04-01 10:39:53 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-04-01 10:39:53 +0300 |
commit | 33a00ceeeacfc52272d25cef914a027b9bf13a2a (patch) | |
tree | 3baeffab781954259202a814f0d349517bae2e41 | |
parent | 95b84e2c5aa92a5a8effc108fdbdf596dff4818c (diff) | |
download | gitlab-ce-33a00ceeeacfc52272d25cef914a027b9bf13a2a.tar.gz |
Create branch via API
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r-- | lib/api/branches.rb | 15 | ||||
-rw-r--r-- | lib/api/helpers.rb | 4 | ||||
-rw-r--r-- | spec/requests/api/branches_spec.rb | 20 |
3 files changed, 39 insertions, 0 deletions
diff --git a/lib/api/branches.rb b/lib/api/branches.rb index 6339094bd99..953c6100f8b 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -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 diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 03a2968fcc7..7ee4b9d1381 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -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 diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index 47c0ba94a4a..f792c618e67 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -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 |