diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2019-01-11 18:29:01 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2019-01-16 14:25:14 +0100 |
commit | 52eeb56bf033e0695acba6c236ed6a9a40bc8a4d (patch) | |
tree | 0b144c95b893193457a5e40e899d1f311e48810d /app/models/project.rb | |
parent | 3e9c9f97273efab6b623966597242811f8896024 (diff) | |
download | gitlab-ce-52eeb56bf033e0695acba6c236ed6a9a40bc8a4d.tar.gz |
Refactor code for protecting default branches
This refactors some of the logic used for protecting default branches,
in particular Project#after_create_default_branch. The logic for this
method is moved into a separate service class. Ideally we'd get rid of
Project#after_create_default_branch entirely, but unfortunately
Project#after_import depends on it. This means it has to stick around
until we also refactor Project#after_import.
For branch protection levels we introduce
Gitlab::Access::BranchProtection, which provides a small wrapper around
Integer based branch protection levels. Using this class removes the
need for having to constantly refer to Gitlab::Access::PROTECTION_*
constants.
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 19 |
1 files changed, 1 insertions, 18 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 7ab2fc30c24..e31ee0f5228 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1602,24 +1602,7 @@ class Project < ActiveRecord::Base # rubocop: disable CodeReuse/ServiceClass def after_create_default_branch - return unless default_branch - - # Ensure HEAD points to the default branch in case it is not master - change_head(default_branch) - - if Gitlab::CurrentSettings.default_branch_protection != Gitlab::Access::PROTECTION_NONE && !ProtectedBranch.protected?(self, default_branch) - params = { - name: default_branch, - push_access_levels_attributes: [{ - access_level: Gitlab::CurrentSettings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_PUSH ? Gitlab::Access::DEVELOPER : Gitlab::Access::MAINTAINER - }], - merge_access_levels_attributes: [{ - access_level: Gitlab::CurrentSettings.default_branch_protection == Gitlab::Access::PROTECTION_DEV_CAN_MERGE ? Gitlab::Access::DEVELOPER : Gitlab::Access::MAINTAINER - }] - } - - ProtectedBranches::CreateService.new(self, creator, params).execute(skip_authorization: true) - end + Projects::ProtectDefaultBranchService.new(self).execute end # rubocop: enable CodeReuse/ServiceClass |