Skip to content
Snippets Groups Projects
Commit a9958ddc authored by Timothy Andrew's avatar Timothy Andrew
Browse files

Fix default branch protection.

1. So it works with the new data model for protected branch access levels.
parent 9fa66147
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -88,9 +88,11 @@ class GitPushService < BaseService
 
# Set protection on the default branch if configured
if current_application_settings.default_branch_protection != PROTECTION_NONE
developers_can_push = current_application_settings.default_branch_protection == PROTECTION_DEV_CAN_PUSH ? true : false
developers_can_merge = current_application_settings.default_branch_protection == PROTECTION_DEV_CAN_MERGE ? true : false
@project.protected_branches.create({ name: @project.default_branch, developers_can_push: developers_can_push, developers_can_merge: developers_can_merge })
allowed_to_push = current_application_settings.default_branch_protection == PROTECTION_DEV_CAN_PUSH ? 'developers' : 'masters'
allowed_to_merge = current_application_settings.default_branch_protection == PROTECTION_DEV_CAN_MERGE ? 'developers' : 'masters'
params = { name: @project.default_branch, allowed_to_push: allowed_to_push, allowed_to_merge: allowed_to_merge }
ProtectedBranches::CreateService.new(@project, current_user, params).execute
end
end
 
Loading
Loading
module ProtectedBranches
class CreateService < BaseService
class CreateService < ProtectedBranches::BaseService
attr_reader :protected_branch
 
def execute
Loading
Loading
module ProtectedBranches
class UpdateService < BaseService
class UpdateService < ProtectedBranches::BaseService
attr_reader :protected_branch
 
def initialize(project, current_user, id, params = {})
Loading
Loading
Loading
Loading
@@ -224,8 +224,10 @@ describe GitPushService, services: true do
it "when pushing a branch for the first time" do
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
expect(project.protected_branches).to receive(:create).with({ name: "master", developers_can_push: false, developers_can_merge: false })
execute_service(project, user, @blankrev, 'newrev', 'refs/heads/master' )
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.first.allowed_to_push).to eq('masters')
expect(project.protected_branches.first.allowed_to_merge).to eq('masters')
end
 
it "when pushing a branch for the first time with default branch protection disabled" do
Loading
Loading
@@ -233,8 +235,8 @@ describe GitPushService, services: true do
 
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
expect(project.protected_branches).not_to receive(:create)
execute_service(project, user, @blankrev, 'newrev', 'refs/heads/master' )
expect(project.protected_branches).to be_empty
end
 
it "when pushing a branch for the first time with default branch protection set to 'developers can push'" do
Loading
Loading
@@ -242,9 +244,12 @@ describe GitPushService, services: true do
 
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
expect(project.protected_branches).to receive(:create).with({ name: "master", developers_can_push: true, developers_can_merge: false })
 
execute_service(project, user, @blankrev, 'newrev', 'refs/heads/master')
execute_service(project, user, @blankrev, 'newrev', 'refs/heads/master' )
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.last.allowed_to_push).to eq('developers')
expect(project.protected_branches.last.allowed_to_merge).to eq('masters')
end
 
it "when pushing a branch for the first time with default branch protection set to 'developers can merge'" do
Loading
Loading
@@ -252,8 +257,10 @@ describe GitPushService, services: true do
 
expect(project).to receive(:execute_hooks)
expect(project.default_branch).to eq("master")
expect(project.protected_branches).to receive(:create).with({ name: "master", developers_can_push: false, developers_can_merge: true })
execute_service(project, user, @blankrev, 'newrev', 'refs/heads/master' )
expect(project.protected_branches).not_to be_empty
expect(project.protected_branches.first.allowed_to_push).to eq('masters')
expect(project.protected_branches.first.allowed_to_merge).to eq('developers')
end
 
it "when pushing new commits to existing branch" do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment