lib/danger/plugins/roulette.rb in gitlab-dangerfiles-3.4.3 vs lib/danger/plugins/roulette.rb in gitlab-dangerfiles-3.5.0
- old
+ new
@@ -88,10 +88,12 @@
# Fetch an already picked maintainer, or pick one otherwise
spin.maintainer = backend_spin&.maintainer || frontend_spin&.maintainer || spin_for_category(project, :backend, timezone_experiment: including_timezone).maintainer
end
when :integrations_be, :integrations_fe
spin.optional_role = :maintainer
+ when :ux
+ spin.optional_role = :maintainer
end
end
spins
end
@@ -99,19 +101,36 @@
def required_approvals
approval_rules = helper.mr_approval_state["rules"]
return [] unless approval_rules
- approval_rules.filter_map do |rule|
+ required_approval_rules = unique_approval_rules(approval_rules)
+ required_approval_rules.filter_map do |rule|
rule["rule_type"] == "code_owner" &&
rule["approvals_required"] > 0 &&
Approval.from_approval_rule(rule, spin_for_approver(rule))
end
end
private
+ # Returns an array containing all unique approval rules, based on on the section and eligible_approvers of the rules
+ #
+ # @param [Array<Hash>] approval rules
+ # @return [Array<Hash>]
+ def unique_approval_rules(approval_rules)
+ approval_rules.uniq do |rule|
+ section = rule["section"]
+
+ approvers = rule["eligible_approvers"].map do |approver|
+ approver["username"]
+ end
+
+ [section, approvers]
+ end
+ end
+
# @param [Gitlab::Dangerfiles::Teammate] person
# @return [Boolean]
def valid_person?(person)
!mr_author?(person) && person.available
end
@@ -259,10 +278,10 @@
#
# @return [Array<Gitlab::Dangerfiles::Teammate>]
def project_team(project_name)
company_members.select do |member|
member.in_project?(project_name) ||
- member.in_project?("gitlab") # Used for backup reviewer
+ member.in_project?("gitlab") # Used for universal reviewer
end
rescue => err
warn("Reviewer roulette failed to load team data: #{err.message}")
[]
end