Skip to content
Snippets Groups Projects

Reviewer roulette via Danger

Merged Nick Thomas requested to merge 56087-danger-roulette into master
All threads resolved!
Compare and Show latest version
2 files
+ 76
36
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 40
23
@@ -3,17 +3,17 @@
require 'net/http'
require 'yaml'
Teammate = Struct.new(:name, :projects, :gitlab, keyword_init: true) do
def self.build(hash)
new(name: hash['name'], projects: hash['projects'], gitlab: hash['gitlab'])
end
class Teammate
attr_reader :name, :projects, :gitlab
def initialize(*args, &blk)
super
def initialize(options = {})
@name = options['name']
@projects = options['projects']
@gitlab = options['gitlab']
end
def in_project?(name)
projects.has_key?(name)
projects&.has_key?(name)
end
# Traintainers also count as reviewers
@@ -69,7 +69,6 @@ def all_changed_files
.sort
end
# @return [Boolean]
def ee?
ENV['CI_PROJECT_NAME'] == 'gitlab-ee' || File.exist?('../../CHANGELOG-EE.md')
end
@@ -78,45 +77,63 @@ def project_name
ee? ? 'gitlab-ee' : 'gitlab-ce'
end
# Looks up the current list of GitLab team members and parses it into a
# useful form
#
# @return [Array<Teammate>]
def team
Psych.safe_load(Net::HTTP.get(TEAM_DATA_URL)).map { |hash| Teammate.build(hash) }
@team ||=
begin
data = Psych.safe_load(Net::HTTP.get(TEAM_DATA_URL), [Date])
data.map { |hash| Teammate.new(hash) }
end
end
# Like +team+, but only returns teammates in the current project, based on
# project_name.
#
# @return [Array<Teammate>]
def project_team
team.select { |member| member.in_project?(project_name) }
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
all_changed_files.each_with_object(Hash.new { |h, k| h[k] = [] }) do |file, hash|
hash[category_for_file(file)] << file
hash
end
end
# Determines the category a file is in, e.g., `:frontend` or `:backend`
# @return[Symbol]
def category_for_file(file)
_, category = CATEGORIES.find { |regexp, _| regexp.match?(file) }
category || :unknown
end
# rubocop:disable Style/RegexpLiteral
CATEGORIES = {
%r{\Adoc/} => :documentation,
%r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z/} => :documentation,
%r{\A(/ee)?/app/(assets|views)/} => :frontend,
%r{\A(/ee)?/public/} => :frontend,
%r{\A(/ee)?/vendor/assets/} => :frontend,
%r{\A/(jest\.config\.js|package\.json|yarn\.lock)\z} => :frontend,
%r{\A(ee/)?app/(assets|views)/} => :frontend,
%r{\A(ee/)?public/} => :frontend,
%r{\A(ee/)?vendor/assets/} => :frontend,
%r{\A(jest\.config\.js|package\.json|yarn\.lock)\z} => :frontend,
%r{\A(/ee)?/app/(controllers|finders|graphql|helpers|mailers|models|policies|presenters|serializers|services|uploaders|validators|workers)/} => :backend,
%r{\A(/ee)?/(bin|config|danger|generator_templates|lib|rubocop|scripts|spec)/} => :backend,
%r{\A(/ee)?/vendor/(cert_manager|Dockerfile|gitignore|ingress|jupyter|project_templates|prometheus|runner)/} => :backend,
%r{\A(/ee)?/vendor/(languages\.yml|licenses\.csv)\z/} => :backend,
%r{\A/(Gemfile|Gemfile.lock)\z} => :backend,
%r{\A/(GITALY_SERVER_VERSION|GITLAB_PAGES_VERSION|GITLAB_SHELL_VERSION|GITLAB_WORKHORSE_VERSION|Rakefile)\z} => :backend,
%r{\A(ee/)?app/(controllers|finders|graphql|helpers|mailers|models|policies|presenters|serializers|services|uploaders|validators|workers)/} => :backend,
%r{\A(ee/)?(bin|config|danger|generator_templates|lib|rubocop|scripts|spec)/} => :backend,
%r{\A(ee/)?vendor/(cert_manager|Dockerfile|gitignore|ingress|jupyter|project_templates|prometheus|runner)/} => :backend,
%r{\A(ee/)?vendor/(languages\.yml|licenses\.csv)\z/} => :backend,
%r{\A(Dangerfile|Gemfile|Gemfile.lock|Procfile|Rakefile)\z} => :backend,
%r{\A(GITALY_SERVER_VERSION|GITLAB_PAGES_VERSION|GITLAB_SHELL_VERSION|GITLAB_WORKHORSE_VERSION|Rakefile)\z} => :backend,
%r{\A(/ee)?/db/} => :database,
%r{\A(/ee)?/qa/} => :qa
%r{\A(ee/)?db/} => :database,
%r{\A(ee/)?qa/} => :qa
}.freeze
# rubocop:enable Style/RegexpLiteral
end
end
Loading