Class: Gitlab::Access::DefaultBranchProtection
- Inherits:
-
Object
- Object
- Gitlab::Access::DefaultBranchProtection
- Defined in:
- lib/gitlab/access/default_branch_protection.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
- #allow_force_push? ⇒ Boolean
- #any? ⇒ Boolean
- #code_owner_approval_required? ⇒ Boolean
- #developer_can_initial_push? ⇒ Boolean
- #developer_can_merge? ⇒ Boolean
- #developer_can_push? ⇒ Boolean
- #fully_protected? ⇒ Boolean
-
#initialize(settings) ⇒ DefaultBranchProtection
constructor
A new instance of DefaultBranchProtection.
- #maintainer_can_merge? ⇒ Boolean
- #maintainer_can_push? ⇒ Boolean
- #no_one_can_merge? ⇒ Boolean
- #no_one_can_push? ⇒ Boolean
Constructor Details
#initialize(settings) ⇒ DefaultBranchProtection
Returns a new instance of DefaultBranchProtection.
8 9 10 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 8 def initialize(settings) @settings = settings.deep_symbolize_keys end |
Instance Attribute Details
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
6 7 8 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 6 def settings @settings end |
Instance Method Details
#allow_force_push? ⇒ Boolean
16 17 18 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 16 def allow_force_push? !!settings[:allow_force_push] end |
#any? ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 20 def any? return true unless settings[:allow_force_push] allowed_to_merge_values = settings[:allowed_to_merge] allowed_to_push_values = settings[:allowed_to_push] any_push_levels_not_developer = allowed_to_push_values.any? do |entry| entry[:access_level] != Gitlab::Access::DEVELOPER end any_merge_levels_not_developer = allowed_to_merge_values.any? do |entry| entry[:access_level] != Gitlab::Access::DEVELOPER end any_push_levels_not_developer || any_merge_levels_not_developer end |
#code_owner_approval_required? ⇒ Boolean
12 13 14 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 12 def code_owner_approval_required? !!settings[:code_owner_approval_required] end |
#developer_can_initial_push? ⇒ Boolean
62 63 64 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 62 def developer_can_initial_push? settings[:developer_can_initial_push].present? end |
#developer_can_merge? ⇒ Boolean
66 67 68 69 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 66 def developer_can_merge? allowed_to_merge_values = settings[:allowed_to_merge] allowed_to_merge_values.any? { |entry| entry[:access_level] == Gitlab::Access::DEVELOPER } end |
#developer_can_push? ⇒ Boolean
57 58 59 60 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 57 def developer_can_push? allowed_to_push_values = settings[:allowed_to_push] allowed_to_push_values.any? { |entry| entry[:access_level] == Gitlab::Access::DEVELOPER } end |
#fully_protected? ⇒ Boolean
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 71 def fully_protected? return false if settings[:allow_force_push] || developer_can_initial_push? allowed_to_merge_values = settings[:allowed_to_merge] allowed_to_push_values = settings[:allowed_to_push] all_push_levels_at_maintainer = allowed_to_push_values.all? do |entry| entry[:access_level] == Gitlab::Access::MAINTAINER end all_merge_levels_at_maintainer = allowed_to_merge_values.all? do |entry| entry[:access_level] == Gitlab::Access::MAINTAINER end all_push_levels_at_maintainer && all_merge_levels_at_maintainer end |
#maintainer_can_merge? ⇒ Boolean
52 53 54 55 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 52 def maintainer_can_merge? allowed_to_merge_values = settings[:allowed_to_merge] allowed_to_merge_values.any? { |entry| entry[:access_level] == Gitlab::Access::MAINTAINER } end |
#maintainer_can_push? ⇒ Boolean
47 48 49 50 |
# File 'lib/gitlab/access/default_branch_protection.rb', line 47 def maintainer_can_push? allowed_to_push_values = settings[:allowed_to_push] allowed_to_push_values.any? { |entry| entry[:access_level] == Gitlab::Access::MAINTAINER } end |