File: default_branch_protection.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (38 lines) | stat: -rw-r--r-- 1,496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

module DefaultBranchProtection
  extend ActiveSupport::Concern

  def normalize_default_branch_params!(form_key)
    # The entity being configured will either be the instance or the group
    entity_settings_params = params[form_key]

    if Gitlab::Utils.to_boolean(entity_settings_params[:default_branch_protected]) == false
      entity_settings_params[:default_branch_protection_defaults] =
        ::Gitlab::Access::BranchProtection.protection_none

      return entity_settings_params
    end

    return entity_settings_params unless entity_settings_params.key?(:default_branch_protection_defaults)

    entity_settings_params.delete(:default_branch_protection_level)

    entity_settings_params[:default_branch_protection_defaults][:allowed_to_push].each do |entry|
      entry[:access_level] = entry[:access_level].to_i
    end

    entity_settings_params[:default_branch_protection_defaults][:allowed_to_merge].each do |entry|
      entry[:access_level] = entry[:access_level].to_i
    end

    [:allow_force_push, :code_owner_approval_required, :developer_can_initial_push].each do |key|
      next unless entity_settings_params[:default_branch_protection_defaults].key?(key)

      entity_settings_params[:default_branch_protection_defaults][key] =
        Gitlab::Utils.to_boolean(
          entity_settings_params[:default_branch_protection_defaults][key],
          default: ::Gitlab::Access::BranchProtection.protected_fully[key])
    end
  end
end