Class: Gitlab::Dangerfiles::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/dangerfiles/config.rb

Constant Summary collapse

DEFAULT_CHANGES_SIZE_THRESHOLDS =
{ high: 2_000, medium: 500 }.freeze
DEFAULT_COMMIT_MESSAGES_MAX_COMMITS_COUNT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/gitlab/dangerfiles/config.rb', line 69

def initialize
  @files_to_category = {}
  @custom_labels_for_categories = {}
  @project_root = nil
  @project_name = ENV["CI_PROJECT_NAME"]
  @ci_only_rules = []
  @code_size_thresholds = DEFAULT_CHANGES_SIZE_THRESHOLDS
  @max_commits_count = DEFAULT_COMMIT_MESSAGES_MAX_COMMITS_COUNT
  @disabled_roulette_categories = []
  @included_optional_codeowners_sections_for_roulette = []
  @excluded_required_codeowners_sections_for_roulette = []
  @auto_assign_for_roulette_roles = []
  @auto_assign_for_roulette_labels = []
  @duo_code_review = :optional
end

Instance Attribute Details

#auto_assign_for_roulette_labelsArray<String>

Returns MR labels that allow auto reviewer assignment. If empty, applies to all MRs, provided :auto_assign_for_roulette_roles is not empty. Default to ‘[]`.

Returns:

  • (Array<String>)

    MR labels that allow auto reviewer assignment. If empty, applies to all MRs, provided :auto_assign_for_roulette_roles is not empty. Default to ‘[]`.



64
65
66
# File 'lib/gitlab/dangerfiles/config.rb', line 64

def auto_assign_for_roulette_labels
  @auto_assign_for_roulette_labels
end

#auto_assign_for_roulette_rolesArray<Symbol>

Returns which roles to auto assign as reviewers, given roulette recommendations (:reviewer, :maintainer, or both). If empty, auto-assignment is disabled. Default to ‘[]`.

Returns:

  • (Array<Symbol>)

    which roles to auto assign as reviewers, given roulette recommendations (:reviewer, :maintainer, or both). If empty, auto-assignment is disabled. Default to ‘[]`.



60
61
62
# File 'lib/gitlab/dangerfiles/config.rb', line 60

def auto_assign_for_roulette_roles
  @auto_assign_for_roulette_roles
end

#ci_only_rulesArray<String>

Returns rules that cannot be run locally.

Returns:

  • (Array<String>)

    rules that cannot be run locally.



16
17
18
# File 'lib/gitlab/dangerfiles/config.rb', line 16

def ci_only_rules
  @ci_only_rules
end

#code_size_thresholds{ high: Integer, medium: Integer }

Returns a hash of the form { high: 42, medium: 12 } where :high is the lines changed threshold which triggers an error, and :medium is the lines changed threshold which triggers a warning. Also, see DEFAULT_CHANGES_SIZE_THRESHOLDS for the format of the hash.

Returns:

  • ({ high: Integer, medium: Integer })

    a hash of the form { high: 42, medium: 12 } where :high is the lines changed threshold which triggers an error, and :medium is the lines changed threshold which triggers a warning. Also, see DEFAULT_CHANGES_SIZE_THRESHOLDS for the format of the hash.



36
37
38
# File 'lib/gitlab/dangerfiles/config.rb', line 36

def code_size_thresholds
  @code_size_thresholds
end

#custom_labels_for_categories{String => String}

Returns A hash of the form { category_name => label }. Used in ‘helper.custom_labels_for_categories`.

Returns:

  • ({String => String})

    A hash of the form { category_name => label }. Used in ‘helper.custom_labels_for_categories`.



27
28
29
# File 'lib/gitlab/dangerfiles/config.rb', line 27

def custom_labels_for_categories
  @custom_labels_for_categories
end

#disabled_roulette_categoriesArray

Returns indicating which categories would be disabled for the simple roulette. Default to ‘[]` (all categories are enabled).

Returns:

  • (Array)

    indicating which categories would be disabled for the simple roulette. Default to ‘[]` (all categories are enabled)



31
32
33
# File 'lib/gitlab/dangerfiles/config.rb', line 31

def disabled_roulette_categories
  @disabled_roulette_categories
end

#duo_code_reviewSymbol

Returns whether a review from GitLab Duo Code is ‘:mandatory` or `:optional`. Default to `:optional`.

Returns:

  • (Symbol)

    whether a review from GitLab Duo Code is ‘:mandatory` or `:optional`. Default to `:optional`.



46
47
48
# File 'lib/gitlab/dangerfiles/config.rb', line 46

def duo_code_review
  @duo_code_review
end

#excluded_required_codeowners_sections_for_rouletteArray

Returns indicating which required codeowners sections should be excluded from roulette. Default to ‘[]`.

Returns:

  • (Array)

    indicating which required codeowners sections should be excluded from roulette. Default to ‘[]`.



56
57
58
# File 'lib/gitlab/dangerfiles/config.rb', line 56

def excluded_required_codeowners_sections_for_roulette
  @excluded_required_codeowners_sections_for_roulette
end

#files_to_category{Regexp => Array<Symbol>}, {Array<Regexp> => Array<Symbol>}

Returns A hash of the form { filename_regex => categories, [filename_regex, changes_regex] => categories }. filename_regex is the regex pattern to match file names. changes_regex is the regex pattern to match changed lines in files that match filename_regex. Used in ‘helper.changes_by_category`, `helper.changes`, and `helper.categories_for_file`.

Returns:

  • ({Regexp => Array<Symbol>}, {Array<Regexp> => Array<Symbol>})

    A hash of the form { filename_regex => categories, [filename_regex, changes_regex] => categories }. filename_regex is the regex pattern to match file names. changes_regex is the regex pattern to match changed lines in files that match filename_regex. Used in ‘helper.changes_by_category`, `helper.changes`, and `helper.categories_for_file`.



22
23
24
# File 'lib/gitlab/dangerfiles/config.rb', line 22

def files_to_category
  @files_to_category
end

#included_optional_codeowners_sections_for_rouletteArray

Returns indicating which optional codeowners sections should be included in roulette. Default to ‘[]`.

Returns:

  • (Array)

    indicating which optional codeowners sections should be included in roulette. Default to ‘[]`.



51
52
53
# File 'lib/gitlab/dangerfiles/config.rb', line 51

def included_optional_codeowners_sections_for_roulette
  @included_optional_codeowners_sections_for_roulette
end

#max_commits_countInteger

Returns the maximum number of allowed non-squashed/non-fixup commits for a given MR. A warning is triggered if the MR has more commits.

Returns:

  • (Integer)

    the maximum number of allowed non-squashed/non-fixup commits for a given MR. A warning is triggered if the MR has more commits.



41
42
43
# File 'lib/gitlab/dangerfiles/config.rb', line 41

def max_commits_count
  @max_commits_count
end

#project_nameString

Returns the project name. Currently used by the Roulette plugin to fetch relevant reviewers/maintainers based on the project name. Default to ENV.

Returns:

  • (String)

    the project name. Currently used by the Roulette plugin to fetch relevant reviewers/maintainers based on the project name. Default to ENV.



12
13
14
# File 'lib/gitlab/dangerfiles/config.rb', line 12

def project_name
  @project_name
end

#project_rootString

Returns the project root folder path.

Returns:

  • (String)

    the project root folder path.



8
9
10
# File 'lib/gitlab/dangerfiles/config.rb', line 8

def project_root
  @project_root
end