Class: Gitlab::BackgroundMigration::BackfillDefaultBranchProtectionNamespaceSetting::BranchProtection

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/backfill_default_branch_protection_namespace_setting.rb

Overview

Migration only version of Gitlab::Access:BranchProtection application code.

Constant Summary collapse

PROTECTION_NONE =
0
PROTECTION_DEV_CAN_PUSH =
1
PROTECTION_FULL =
2
PROTECTION_DEV_CAN_MERGE =
3
PROTECTION_DEV_CAN_INITIAL_PUSH =
4
DEVELOPER =
30
MAINTAINER =
40

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level) ⇒ BranchProtection

Returns a new instance of BranchProtection.



31
32
33
# File 'lib/gitlab/background_migration/backfill_default_branch_protection_namespace_setting.rb', line 31

def initialize(level)
  @level = level
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



29
30
31
# File 'lib/gitlab/background_migration/backfill_default_branch_protection_namespace_setting.rb', line 29

def level
  @level
end

Class Method Details

.protected_after_initial_pushObject



88
89
90
91
92
93
94
95
# File 'lib/gitlab/background_migration/backfill_default_branch_protection_namespace_setting.rb', line 88

def protected_after_initial_push
  {
    allowed_to_push: [{ 'access_level' => MAINTAINER }],
    allowed_to_merge: [{ 'access_level' => DEVELOPER }],
    allow_force_push: true,
    developer_can_initial_push: true
  }
end

.protected_against_developer_pushesObject



80
81
82
83
84
85
86
# File 'lib/gitlab/background_migration/backfill_default_branch_protection_namespace_setting.rb', line 80

def protected_against_developer_pushes
  {
    allowed_to_push: [{ 'access_level' => MAINTAINER }],
    allowed_to_merge: [{ 'access_level' => DEVELOPER }],
    allow_force_push: true
  }
end

.protected_fullyObject



72
73
74
75
76
77
78
# File 'lib/gitlab/background_migration/backfill_default_branch_protection_namespace_setting.rb', line 72

def protected_fully
  {
    allowed_to_push: [{ 'access_level' => MAINTAINER }],
    allowed_to_merge: [{ 'access_level' => MAINTAINER }],
    allow_force_push: false
  }
end

.protection_noneObject



60
61
62
63
64
65
66
# File 'lib/gitlab/background_migration/backfill_default_branch_protection_namespace_setting.rb', line 60

def protection_none
  {
    allowed_to_push: [{ 'access_level' => DEVELOPER }],
    allowed_to_merge: [{ 'access_level' => DEVELOPER }],
    allow_force_push: true
  }
end

.protection_partialObject



68
69
70
# File 'lib/gitlab/background_migration/backfill_default_branch_protection_namespace_setting.rb', line 68

def protection_partial
  protection_none.merge(allow_force_push: false)
end

Instance Method Details

#to_hashObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gitlab/background_migration/backfill_default_branch_protection_namespace_setting.rb', line 44

def to_hash
  case level
  when PROTECTION_NONE
    self.class.protection_none
  when PROTECTION_DEV_CAN_PUSH
    self.class.protection_partial
  when PROTECTION_FULL
    self.class.protected_fully
  when PROTECTION_DEV_CAN_MERGE
    self.class.protected_against_developer_pushes
  when PROTECTION_DEV_CAN_INITIAL_PUSH
    self.class.protected_after_initial_push
  end
end