diff options
author | Nick Thomas <nick@gitlab.com> | 2019-02-05 20:16:18 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-02-13 19:41:28 +0300 |
commit | 77b2ecd2b1de3f66c3d9ebd5e58fedafb17ea606 (patch) | |
tree | eb360eb0264b50370ff3ad48910ad437183bc3b6 /danger/plugins | |
parent | 235fe67bdbc7f177a6f4b213bb1780f043944246 (diff) |
Reviewer roulette via Danger
Make danger pick reviewers and maintainers at random, for feontend,
backend, database, etc, changes, whenever files belonging to those
teams get changed.
Diffstat (limited to 'danger/plugins')
-rw-r--r-- | danger/plugins/helper.rb | 59 |
1 files changed, 9 insertions, 50 deletions
diff --git a/danger/plugins/helper.rb b/danger/plugins/helper.rb index 09ee50a2ef0..581c0720083 100644 --- a/danger/plugins/helper.rb +++ b/danger/plugins/helper.rb @@ -1,56 +1,15 @@ # frozen_string_literal: true -module Danger - # Common helper functions for our danger scripts - # If we find ourselves repeating code in our danger files, we might as well put them in here. - class Helper < Plugin - # 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>] - 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 - - # @return [Boolean] - def ee? - ENV['CI_PROJECT_NAME'] == 'gitlab-ee' || File.exist?('../../CHANGELOG-EE.md') - end - - # @return [Hash<String,Array<String>>] - def changes_by_category - all_changed_files.inject(Hash.new { |h, k| h[k] = [] }) do |hsh, file| - hsh[category_for_file(file)] << file - end - end +require 'net/http' +require 'yaml' - def category_for_file(file) - _, category = CATEGORIES.find { |regexp, _| regexp.match?(file) } +require_relative '../../lib/gitlab/danger/helper' - category || :unknown - end - - CATEGORIES = { - %r{\Adoc/} => :documentation - } +module Danger + # Common helper functions for our danger scripts. See Gitlab::Danger::Helper + # for more details + class Helper < Plugin + # Put the helper code somewhere it can be tested + include Gitlab::Danger::Helper end end |