diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2019-05-29 22:38:26 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2019-05-30 19:24:28 +0800 |
commit | c90ba127bf8cdd4ccac9692b6c96fa746314cd55 (patch) | |
tree | 480c8fe6e25d71625c3d8c7376851c3a91e572f2 /danger | |
parent | c8b4edf651009c4603802bf22a66a04d395b4f00 (diff) | |
download | gitlab-ce-c90ba127bf8cdd4ccac9692b6c96fa746314cd55.tar.gz |
Extract roulette to its own module
So it's more modular and extensible
Diffstat (limited to 'danger')
-rw-r--r-- | danger/plugins/helper.rb | 3 | ||||
-rw-r--r-- | danger/plugins/roulette.rb | 10 | ||||
-rw-r--r-- | danger/roulette/Dangerfile | 45 |
3 files changed, 16 insertions, 42 deletions
diff --git a/danger/plugins/helper.rb b/danger/plugins/helper.rb index 581c0720083..2d7a933e801 100644 --- a/danger/plugins/helper.rb +++ b/danger/plugins/helper.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require 'net/http' -require 'yaml' - require_relative '../../lib/gitlab/danger/helper' module Danger diff --git a/danger/plugins/roulette.rb b/danger/plugins/roulette.rb new file mode 100644 index 00000000000..7c62cff0c92 --- /dev/null +++ b/danger/plugins/roulette.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require_relative '../../lib/gitlab/danger/roulette' + +module Danger + class Roulette < Plugin + # Put the helper code somewhere it can be tested + include Gitlab::Danger::Roulette + end +end diff --git a/danger/roulette/Dangerfile b/danger/roulette/Dangerfile index 62e5526c02b..de314c5b39f 100644 --- a/danger/roulette/Dangerfile +++ b/danger/roulette/Dangerfile @@ -32,7 +32,7 @@ for them. MARKDOWN def spin_for_category(team, project, category, branch_name) - rng = Random.new(Digest::MD5.hexdigest(branch_name).to_i(16)) + random = roulette.new_random(branch_name) reviewers = team.select { |member| member.reviewer?(project, category) } traintainers = team.select { |member| member.traintainer?(project, category) } @@ -42,43 +42,12 @@ def spin_for_category(team, project, category, branch_name) # https://gitlab.com/gitlab-org/gitlab-ce/issues/57653 # Make traintainers have triple the chance to be picked as a reviewer - reviewer = spin_for_person(reviewers + traintainers + traintainers, random: rng) - maintainer = spin_for_person(maintainers, random: rng) + reviewer = roulette.spin_for_person(reviewers + traintainers + traintainers, random: random) + maintainer = roulette.spin_for_person(maintainers, random: random) "| #{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) - - break person unless out_of_office?(person) - - people -= [person] - end - - person -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") @@ -101,14 +70,12 @@ categories = changes.keys - [:unknown] # disable the review roulette for such MRs. if changes.any? && !gitlab.mr_labels.include?('single codebase') && !gitlab.mr_labels.include?('CSS cleanup') # Strip leading and trailing CE/EE markers - canonical_branch_name = gitlab - .mr_json['source_branch'] - .gsub(/^[ce]e-/, '') - .gsub(/-[ce]e$/, '') + canonical_branch_name = + roulette.canonical_branch_name(gitlab.mr_json['source_branch']) team = begin - helper.project_team + roulette.project_team(helper.project_name) rescue => err warn("Reviewer roulette failed to load team data: #{err.message}") [] |