summaryrefslogtreecommitdiff
path: root/danger/roulette
diff options
context:
space:
mode:
Diffstat (limited to 'danger/roulette')
-rw-r--r--danger/roulette/Dangerfile45
1 files changed, 37 insertions, 8 deletions
diff --git a/danger/roulette/Dangerfile b/danger/roulette/Dangerfile
index d07d652e601..417b5889bcf 100644
--- a/danger/roulette/Dangerfile
+++ b/danger/roulette/Dangerfile
@@ -38,24 +38,32 @@ MARKDOWN
NO_REVIEWER = 'No reviewer available'.freeze
NO_MAINTAINER = 'No maintainer available'.freeze
-def spin_for_category(team, project, category, branch_name)
- random = roulette.new_random(branch_name)
- labels = gitlab.mr_labels
+Spin = Struct.new(:reviewer, :maintainer)
+
+def spin_role_for_category(team, role, project, category)
+ team.select do |member|
+ member.public_send("#{role}?", project, category, gitlab.mr_labels) # rubocop:disable GitlabSecurity/PublicSend
+ end
+end
+def spin_for_category(team, project, category, branch_name)
reviewers, traintainers, maintainers =
- %i[reviewer? traintainer? maintainer?].map do |kind|
- team.select do |member|
- member.public_send(kind, project, category, labels) # rubocop:disable GitlabSecurity/PublicSend
- end
+ %i[reviewer traintainer maintainer].map do |role|
+ spin_role_for_category(team, role, project, category)
end
# TODO: take CODEOWNERS into account?
# https://gitlab.com/gitlab-org/gitlab/issues/26723
# Make traintainers have triple the chance to be picked as a reviewer
+ random = roulette.new_random(branch_name)
reviewer = roulette.spin_for_person(reviewers + traintainers + traintainers, random: random)
maintainer = roulette.spin_for_person(maintainers, random: random)
+ Spin.new(reviewer, maintainer)
+end
+
+def markdown_row_for_category(category, reviewer, maintainer)
"| #{helper.label_for_category(category)} | #{reviewer&.markdown_name || NO_REVIEWER} | #{maintainer&.markdown_name || NO_MAINTAINER} |"
end
@@ -85,8 +93,29 @@ if changes.any? && !gitlab.mr_labels.include?('CSS cleanup')
project = helper.project_name
unknown = changes.fetch(:unknown, [])
+ spin_per_category = categories.each_with_object({}) do |category, memo|
+ memo[category] = spin_for_category(team, project, category, canonical_branch_name)
+ end
+
+ rows = spin_per_category.map do |category, spin|
+ reviewer = spin.reviewer
+ maintainer = spin.maintainer
+
+ case category
+ when :test
+ if reviewer.nil?
+ # Fetch an already picked backend reviewer, or pick one otherwise
+ reviewer = spin_per_category[:backend]&.reviewer || spin_for_category(team, project, :backend, canonical_branch_name).reviewer
+ end
+ when :engineering_productivity
+ if maintainer.nil?
+ # Fetch an already picked backend maintainer, or pick one otherwise
+ maintainer = spin_per_category[:backend]&.maintainer || spin_for_category(team, project, :backend, canonical_branch_name).maintainer
+ end
+ end
- rows = categories.map { |category| spin_for_category(team, project, category, canonical_branch_name) }
+ markdown_row_for_category(category, reviewer, maintainer)
+ end
markdown(MESSAGE)
markdown(CATEGORY_TABLE_HEADER + rows.join("\n")) unless rows.empty?