module Gitlab::Danger::Helper
Constants
- CATEGORIES
- CATEGORY_LABELS
- RELEASE_TOOLS_BOT
Public Instance Methods
all_changed_files()
click to toggle source
Returns a list of all files that have been added, modified or renamed. `git.modified_files` might contain paths that already have been renamed, so we need to remove them from the list.
Considering these changes:
-
A new_file.rb
-
D deleted_file.rb
-
M modified_file.rb
-
R renamed_file_before.rb -> renamed_file_after.rb
it will return “`
- 'new_file.rb', 'modified_file.rb', 'renamed_file_after.rb'
-
“`
@return [Array<String>]
# File lib/gitlab_roulette/danger/helper.rb, line 27 def all_changed_files Set.new .merge(git.added_files.to_a) .merge(git.modified_files.to_a) .merge(git.renamed_files.map { |x| x[:after] }) .subtract(git.renamed_files.map { |x| x[:before] }) .to_a .sort end
category_for_file(file)
click to toggle source
Determines the category a file is in, e.g., `:frontend` or `:backend` @return
# File lib/gitlab_roulette/danger/helper.rb, line 78 def category_for_file(file) _, category = CATEGORIES.find { |regexp, _| regexp.match?(file) } category || :unknown end
changes_by_category()
click to toggle source
@return [Hash<String,Array<String>>]
# File lib/gitlab_roulette/danger/helper.rb, line 70 def changes_by_category all_changed_files.each_with_object(Hash.new { |h, k| h[k] = [] }) do |file, hash| hash[category_for_file(file)] << file end end
ee?()
click to toggle source
# File lib/gitlab_roulette/danger/helper.rb, line 37 def ee? # Support former project name for `dev` and support local Danger run %w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME']) || Dir.exist?('../../ee') end
gitlab_helper()
click to toggle source
# File lib/gitlab_roulette/danger/helper.rb, line 42 def gitlab_helper # Unfortunately the following does not work: # - respond_to?(:gitlab) # - respond_to?(:gitlab, true) gitlab rescue NoMethodError nil end
label_for_category(category)
click to toggle source
Returns the GFM for a category label, making its best guess if it's not a category we know about.
# File lib/gitlab_roulette/danger/helper.rb, line 88 def label_for_category(category) CATEGORY_LABELS.fetch(category, "~#{category}") end
markdown_list(items)
click to toggle source
# File lib/gitlab_roulette/danger/helper.rb, line 59 def markdown_list(items) list = items.map { |item| "* `#{item}`" }.join("\n") if items.size > 10 "\n<details>\n\n#{list}\n\n</details>\n" else list end end
missing_database_labels(current_mr_labels)
click to toggle source
# File lib/gitlab_roulette/danger/helper.rb, line 167 def missing_database_labels(current_mr_labels) labels = if has_database_scoped_labels?(current_mr_labels) ['database'] else ['database', 'database::review pending'] end labels - current_mr_labels end
new_teammates(usernames)
click to toggle source
# File lib/gitlab_roulette/danger/helper.rb, line 163 def new_teammates(usernames) usernames.map { |u| Gitlab::Danger::Teammate.new('username' => u) } end
project_name()
click to toggle source
# File lib/gitlab_roulette/danger/helper.rb, line 55 def project_name ENV["CI_PROJECT_NAME"] end
release_automation?()
click to toggle source
# File lib/gitlab_roulette/danger/helper.rb, line 51 def release_automation? gitlab_helper&.mr_author == RELEASE_TOOLS_BOT end
Private Instance Methods
has_database_scoped_labels?(current_mr_labels)
click to toggle source
# File lib/gitlab_roulette/danger/helper.rb, line 179 def has_database_scoped_labels?(current_mr_labels) current_mr_labels.any? { |label| label.start_with?('database::') } end