summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-01-16 16:56:30 +0000
committerNick Thomas <nick@gitlab.com>2019-01-16 16:56:30 +0000
commit824c6b03e7f0f4c549fc2eacfc23ea8529274849 (patch)
tree1d2d0641540eded0ea708ad0b4e598e0e385ea16 /lib
parent766fbe1c1c3c542c28c24b1dda5c087a6b2f0645 (diff)
parent52eeb56bf033e0695acba6c236ed6a9a40bc8a4d (diff)
downloadgitlab-ce-824c6b03e7f0f4c549fc2eacfc23ea8529274849.tar.gz
Merge branch 'refactor-after-create-default-branch' into 'master'
Refactor Project#after_create_default_branch See merge request gitlab-org/gitlab-ce!24329
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/access/branch_protection.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/gitlab/access/branch_protection.rb b/lib/gitlab/access/branch_protection.rb
new file mode 100644
index 00000000000..f039e5c011f
--- /dev/null
+++ b/lib/gitlab/access/branch_protection.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Access
+ # A wrapper around Integer based branch protection levels.
+ #
+ # This wrapper can be used to work with branch protection levels without
+ # having to directly refer to the constants. For example, instead of this:
+ #
+ # if access_level == Gitlab::Access::PROTECTION_DEV_CAN_PUSH
+ # ...
+ # end
+ #
+ # You can write this instead:
+ #
+ # protection = BranchProtection.new(access_level)
+ #
+ # if protection.developer_can_push?
+ # ...
+ # end
+ class BranchProtection
+ attr_reader :level
+
+ # @param [Integer] level The branch protection level as an Integer.
+ def initialize(level)
+ @level = level
+ end
+
+ def any?
+ level != PROTECTION_NONE
+ end
+
+ def developer_can_push?
+ level == PROTECTION_DEV_CAN_PUSH
+ end
+
+ def developer_can_merge?
+ level == PROTECTION_DEV_CAN_MERGE
+ end
+ end
+ end
+end