diff options
author | Michael Kozono <mkozono@gmail.com> | 2019-04-25 17:23:30 -0700 |
---|---|---|
committer | Brett Walker <bwalker@gitlab.com> | 2019-04-29 13:49:28 -0500 |
commit | dfc9d0b6940022b82a526e642ed89a9d5422d494 (patch) | |
tree | d6ab5217dd74bea65d669e11fd5e0da204d9fc6b /danger/roulette | |
parent | 7ae2107d9ebca0adecc8a21cacd1bfb6e89ee3ab (diff) | |
download | gitlab-ce-dfc9d0b6940022b82a526e642ed89a9d5422d494.tar.gz |
Exclude reviewers with OOO in status
Diffstat (limited to 'danger/roulette')
-rw-r--r-- | danger/roulette/Dangerfile | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/danger/roulette/Dangerfile b/danger/roulette/Dangerfile index e6820f49ee2..27763052192 100644 --- a/danger/roulette/Dangerfile +++ b/danger/roulette/Dangerfile @@ -31,26 +31,52 @@ Please consider creating a merge request to for them. 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)) reviewers = team.select { |member| member.reviewer?(project, category) } traintainers = team.select { |member| member.traintainer?(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? # https://gitlab.com/gitlab-org/gitlab-ce/issues/57653 # Make traintainers have triple the chance to be picked as a reviewer - reviewer = (reviewers + traintainers + traintainers).sample(random: rng) - maintainer = maintainers.sample(random: rng) + reviewer = spin_for_person(reviewers + traintainers + traintainers, random: rng) + maintainer = spin_for_person(maintainers, random: rng) "| #{helper.label_for_category(category)} | #{reviewer&.markdown_name} | #{maintainer&.markdown_name} |" 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) list = items.map { |filename| "* `#{filename}`" }.join("\n") @@ -63,7 +89,7 @@ end 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) categories = changes.keys - [:unknown] @@ -92,7 +118,7 @@ if changes.any? && !gitlab.mr_labels.include?('single codebase') && !gitlab.mr_l project = helper.project_name 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(CATEGORY_TABLE_HEADER + rows.join("\n")) unless rows.empty? |