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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
a9958ddc
Commit
a9958ddc
authored
Jul 08, 2016
by
Timothy Andrew
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix default branch protection.
1. So it works with the new data model for protected branch access levels.
parent
9fa66147
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
10 deletions
+19
-10
app/services/git_push_service.rb
app/services/git_push_service.rb
+5
-3
app/services/protected_branches/create_service.rb
app/services/protected_branches/create_service.rb
+1
-1
app/services/protected_branches/update_service.rb
app/services/protected_branches/update_service.rb
+1
-1
spec/services/git_push_service_spec.rb
spec/services/git_push_service_spec.rb
+12
-5
No files found.
app/services/git_push_service.rb
View file @
a9958ddc
...
@@ -88,9 +88,11 @@ class GitPushService < BaseService
...
@@ -88,9 +88,11 @@ class GitPushService < BaseService
# Set protection on the default branch if configured
# Set protection on the default branch if configured
if
current_application_settings
.
default_branch_protection
!=
PROTECTION_NONE
if
current_application_settings
.
default_branch_protection
!=
PROTECTION_NONE
developers_can_push
=
current_application_settings
.
default_branch_protection
==
PROTECTION_DEV_CAN_PUSH
?
true
:
false
allowed_to_push
=
current_application_settings
.
default_branch_protection
==
PROTECTION_DEV_CAN_PUSH
?
'developers'
:
'masters'
developers_can_merge
=
current_application_settings
.
default_branch_protection
==
PROTECTION_DEV_CAN_MERGE
?
true
:
false
allowed_to_merge
=
current_application_settings
.
default_branch_protection
==
PROTECTION_DEV_CAN_MERGE
?
'developers'
:
'masters'
@project
.
protected_branches
.
create
({
name:
@project
.
default_branch
,
developers_can_push:
developers_can_push
,
developers_can_merge:
developers_can_merge
})
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
end
end
...
...
app/services/protected_branches/create_service.rb
View file @
a9958ddc
module
ProtectedBranches
module
ProtectedBranches
class
CreateService
<
BaseService
class
CreateService
<
ProtectedBranches
::
BaseService
attr_reader
:protected_branch
attr_reader
:protected_branch
def
execute
def
execute
...
...
app/services/protected_branches/update_service.rb
View file @
a9958ddc
module
ProtectedBranches
module
ProtectedBranches
class
UpdateService
<
BaseService
class
UpdateService
<
ProtectedBranches
::
BaseService
attr_reader
:protected_branch
attr_reader
:protected_branch
def
initialize
(
project
,
current_user
,
id
,
params
=
{})
def
initialize
(
project
,
current_user
,
id
,
params
=
{})
...
...
spec/services/git_push_service_spec.rb
View file @
a9958ddc
...
@@ -224,8 +224,10 @@ describe GitPushService, services: true do
...
@@ -224,8 +224,10 @@ describe GitPushService, services: true do
it
"when pushing a branch for the first time"
do
it
"when pushing a branch for the first time"
do
expect
(
project
).
to
receive
(
:execute_hooks
)
expect
(
project
).
to
receive
(
:execute_hooks
)
expect
(
project
.
default_branch
).
to
eq
(
"master"
)
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'
)
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
end
it
"when pushing a branch for the first time with default branch protection disabled"
do
it
"when pushing a branch for the first time with default branch protection disabled"
do
...
@@ -233,8 +235,8 @@ describe GitPushService, services: true do
...
@@ -233,8 +235,8 @@ describe GitPushService, services: true do
expect
(
project
).
to
receive
(
:execute_hooks
)
expect
(
project
).
to
receive
(
:execute_hooks
)
expect
(
project
.
default_branch
).
to
eq
(
"master"
)
expect
(
project
.
default_branch
).
to
eq
(
"master"
)
expect
(
project
.
protected_branches
).
not_to
receive
(
:create
)
execute_service
(
project
,
user
,
@blankrev
,
'newrev'
,
'refs/heads/master'
)
execute_service
(
project
,
user
,
@blankrev
,
'newrev'
,
'refs/heads/master'
)
expect
(
project
.
protected_branches
).
to
be_empty
end
end
it
"when pushing a branch for the first time with default branch protection set to 'developers can push'"
do
it
"when pushing a branch for the first time with default branch protection set to 'developers can push'"
do
...
@@ -242,9 +244,12 @@ describe GitPushService, services: true do
...
@@ -242,9 +244,12 @@ describe GitPushService, services: true do
expect
(
project
).
to
receive
(
:execute_hooks
)
expect
(
project
).
to
receive
(
:execute_hooks
)
expect
(
project
.
default_branch
).
to
eq
(
"master"
)
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
end
it
"when pushing a branch for the first time with default branch protection set to 'developers can merge'"
do
it
"when pushing a branch for the first time with default branch protection set to 'developers can merge'"
do
...
@@ -252,8 +257,10 @@ describe GitPushService, services: true do
...
@@ -252,8 +257,10 @@ describe GitPushService, services: true do
expect
(
project
).
to
receive
(
:execute_hooks
)
expect
(
project
).
to
receive
(
:execute_hooks
)
expect
(
project
.
default_branch
).
to
eq
(
"master"
)
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'
)
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
end
it
"when pushing new commits to existing branch"
do
it
"when pushing new commits to existing branch"
do
...
...
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