Commit 3ffb9775 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'mk/check-ooo-in-roulette' into 'master'

Reviewer roulette via Danger should take OOO status into account

Closes #57652

See merge request gitlab-org/gitlab-ce!27696
parents 2fe10471 dfc9d0b6
...@@ -31,26 +31,52 @@ Please consider creating a merge request to ...@@ -31,26 +31,52 @@ Please consider creating a merge request to
for them. for them.
MARKDOWN MARKDOWN
def spin(team, project, category, branch_name) def spin_for_category(team, project, category, branch_name)
rng = Random.new(Digest::MD5.hexdigest(branch_name).to_i(16)) rng = Random.new(Digest::MD5.hexdigest(branch_name).to_i(16))
reviewers = team.select { |member| member.reviewer?(project, category) } reviewers = team.select { |member| member.reviewer?(project, category) }
traintainers = team.select { |member| member.traintainer?(project, category) } traintainers = team.select { |member| member.traintainer?(project, category) }
maintainers = team.select { |member| member.maintainer?(project, category) } maintainers = team.select { |member| member.maintainer?(project, category) }
# TODO: filter out people who are currently not in the office
# https://gitlab.com/gitlab-org/gitlab-ce/issues/57652
#
# TODO: take CODEOWNERS into account? # TODO: take CODEOWNERS into account?
# https://gitlab.com/gitlab-org/gitlab-ce/issues/57653 # https://gitlab.com/gitlab-org/gitlab-ce/issues/57653
# Make traintainers have triple the chance to be picked as a reviewer # Make traintainers have triple the chance to be picked as a reviewer
reviewer = (reviewers + traintainers + traintainers).sample(random: rng) reviewer = spin_for_person(reviewers + traintainers + traintainers, random: rng)
maintainer = maintainers.sample(random: rng) maintainer = spin_for_person(maintainers, random: rng)
"| #{helper.label_for_category(category)} | #{reviewer&.markdown_name} | #{maintainer&.markdown_name} |" "| #{helper.label_for_category(category)} | #{reviewer&.markdown_name} | #{maintainer&.markdown_name} |"
end end
# Known issue: If someone is rejected due to OOO, and then becomes not OOO, the
# selection will change on next spin
def spin_for_person(people, random:)
person = nil
people = people.dup
people.size.times do
person = people.sample(random: random)
return person unless out_of_office?(person)
people -= [person]
end
end
def out_of_office?(person)
username = CGI.escape(person.username)
api_endpoint = "https://gitlab.com/api/v4/users/#{username}/status"
response = HTTParty.get(api_endpoint) # rubocop:disable Gitlab/HTTParty
if response.code == 200
response["message"]&.match(/OOO/i)
else
false # this is no worse than not checking for OOO
end
rescue
false
end
def build_list(items) def build_list(items)
list = items.map { |filename| "* `#{filename}`" }.join("\n") list = items.map { |filename| "* `#{filename}`" }.join("\n")
...@@ -63,7 +89,7 @@ end ...@@ -63,7 +89,7 @@ end
changes = helper.changes_by_category changes = helper.changes_by_category
# Ignore any files that are known but uncategoried. Prompt for any unknown files # Ignore any files that are known but uncategorized. Prompt for any unknown files
changes.delete(:none) changes.delete(:none)
categories = changes.keys - [:unknown] categories = changes.keys - [:unknown]
...@@ -92,7 +118,7 @@ if changes.any? && !gitlab.mr_labels.include?('single codebase') && !gitlab.mr_l ...@@ -92,7 +118,7 @@ if changes.any? && !gitlab.mr_labels.include?('single codebase') && !gitlab.mr_l
project = helper.project_name project = helper.project_name
unknown = changes.fetch(:unknown, []) unknown = changes.fetch(:unknown, [])
rows = categories.map { |category| spin(team, project, category, canonical_branch_name) } rows = categories.map { |category| spin_for_category(team, project, category, canonical_branch_name) }
markdown(MESSAGE) markdown(MESSAGE)
markdown(CATEGORY_TABLE_HEADER + rows.join("\n")) unless rows.empty? markdown(CATEGORY_TABLE_HEADER + rows.join("\n")) unless rows.empty?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment