Module: Gitlab::Danger::Roulette
- Defined in:
- lib/gitlab_roulette/danger/roulette.rb
Constant Summary collapse
- ROULETTE_DATA_URL =
ENV["GITLAB_ROULETTE_URL"]
Instance Method Summary collapse
- #canonical_branch_name(branch_name) ⇒ Object
- #new_random(seed) ⇒ Object
-
#project_team(project_name) ⇒ Array<Teammate>
Like
team
, but only returns teammates in the current project, based on project_name. -
#spin_for_person(people, random:) ⇒ Object
Known issue: If someone is rejected due to OOO, and then becomes not OOO, the selection will change on next spin.
-
#team ⇒ Array<Teammate>
Looks up the current list of GitLab team members and parses it into a useful form.
Instance Method Details
#canonical_branch_name(branch_name) ⇒ Object
38 39 40 |
# File 'lib/gitlab_roulette/danger/roulette.rb', line 38 def canonical_branch_name(branch_name) branch_name.gsub(/^[ce]e-|-[ce]e$/, '') end |
#new_random(seed) ⇒ Object
42 43 44 |
# File 'lib/gitlab_roulette/danger/roulette.rb', line 42 def new_random(seed) Random.new(Digest::MD5.hexdigest(seed).to_i(16)) end |
#project_team(project_name) ⇒ Array<Teammate>
Like team
, but only returns teammates in the current project, based on project_name.
34 35 36 |
# File 'lib/gitlab_roulette/danger/roulette.rb', line 34 def project_team(project_name) team.select { |member| member.in_project?(project_name) } end |
#spin_for_person(people, random:) ⇒ Object
Known issue: If someone is rejected due to OOO, and then becomes not OOO, the selection will change on next spin
49 50 51 52 |
# File 'lib/gitlab_roulette/danger/roulette.rb', line 49 def spin_for_person(people, random:) people.shuffle(random: random) .find(&method(:valid_person?)) end |
#team ⇒ Array<Teammate>
Looks up the current list of GitLab team members and parses it into a useful form
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gitlab_roulette/danger/roulette.rb', line 14 def team @team ||= begin if ROULETTE_DATA_URL.include?("https") || ROULETTE_DATA_URL.include?("http") data = Gitlab::Danger::RequestHelper.http_get_json(ROULETTE_DATA_URL) else file = File.read(ROULETTE_DATA_URL) data = JSON.parse(file) end data.map { |hash| ::Gitlab::Danger::Teammate.new(hash) } rescue JSON::ParserError raise "Failed to parse JSON response from #{ROULETTE_DATA_URL}" end end |