blob: 2c7826f0302f03786d690f7dd8b51fb07b9dc553 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# frozen_string_literal: true
require 'cgi'
require_dependency 'gitlab/get_json'
require_dependency 'gitlab/danger/teammate'
# To use this module, you need to implement a `roulette_data :: Array<Hash>` method, which
# returns the data needed to play reviewer roulette.
#
# For an example of this, see: `danger/plugins/roulette.rb`
module Gitlab
module Danger
module Roulette
include ::Gitlab::GetJSON
# Looks up the current list of GitLab team members and parses it into a
# useful form
#
# @return [Array<Teammate>]
def team
@team ||= roulette_data.map { |hash| ::Gitlab::Danger::Teammate.new(hash) }
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
def spin_for_person(people, random:)
people.shuffle(random: random)
.find(&method(:valid_person?))
end
private
def valid_person?(person)
!mr_author?(person) && !out_of_office?(person)
end
def mr_author?(person)
person.username == gitlab.mr_author
end
def out_of_office?(person)
username = CGI.escape(person.username)
api_endpoint = "https://gitlab.com/api/v4/users/#{username}/status"
response = http_get_json(api_endpoint)
response["message"]&.match?(/OOO/i)
rescue Gitlab::GetJSON::Error
false # this is no worse than not checking for OOO
end
end
end
end
|