2019-05-29 10:38:26 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative 'teammate'
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Danger
|
|
|
|
module Roulette
|
|
|
|
ROULETTE_DATA_URL = 'https://about.gitlab.com/roulette.json'
|
|
|
|
|
|
|
|
# Looks up the current list of GitLab team members and parses it into a
|
|
|
|
# useful form
|
|
|
|
#
|
|
|
|
# @return [Array<Teammate>]
|
|
|
|
def team
|
|
|
|
@team ||=
|
|
|
|
begin
|
2019-10-16 05:07:51 -04:00
|
|
|
data = Gitlab::Danger::RequestHelper.http_get_json(ROULETTE_DATA_URL)
|
2019-05-29 10:38:26 -04:00
|
|
|
data.map { |hash| ::Gitlab::Danger::Teammate.new(hash) }
|
|
|
|
rescue JSON::ParserError
|
|
|
|
raise "Failed to parse JSON response from #{ROULETTE_DATA_URL}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Like +team+, but only returns teammates in the current project, based on
|
|
|
|
# project_name.
|
|
|
|
#
|
|
|
|
# @return [Array<Teammate>]
|
|
|
|
def project_team(project_name)
|
|
|
|
team.select { |member| member.in_project?(project_name) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def canonical_branch_name(branch_name)
|
|
|
|
branch_name.gsub(/^[ce]e-|-[ce]e$/, '')
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_random(seed)
|
|
|
|
Random.new(Digest::MD5.hexdigest(seed).to_i(16))
|
|
|
|
end
|
|
|
|
|
|
|
|
# Known issue: If someone is rejected due to OOO, and then becomes not OOO, the
|
|
|
|
# selection will change on next spin
|
2019-10-16 05:07:51 -04:00
|
|
|
# @param [Array<Teammate>] people
|
2019-05-29 10:38:26 -04:00
|
|
|
def spin_for_person(people, random:)
|
2019-05-30 06:50:40 -04:00
|
|
|
people.shuffle(random: random)
|
|
|
|
.find(&method(:valid_person?))
|
|
|
|
end
|
2019-05-29 10:38:26 -04:00
|
|
|
|
2019-05-30 06:50:40 -04:00
|
|
|
private
|
2019-05-29 10:38:26 -04:00
|
|
|
|
2019-10-16 05:07:51 -04:00
|
|
|
# @param [Teammate] person
|
|
|
|
# @return [Boolean]
|
2019-05-30 06:50:40 -04:00
|
|
|
def valid_person?(person)
|
2019-10-16 17:07:22 -04:00
|
|
|
!mr_author?(person) && person.available?
|
2019-05-29 10:38:26 -04:00
|
|
|
end
|
|
|
|
|
2019-10-16 05:07:51 -04:00
|
|
|
# @param [Teammate] person
|
|
|
|
# @return [Boolean]
|
2019-05-30 06:50:40 -04:00
|
|
|
def mr_author?(person)
|
|
|
|
person.username == gitlab.mr_author
|
|
|
|
end
|
2019-05-29 10:38:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|