mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-18 00:56:41 +10:00
Create branch via API
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user