module Gitlab::Danger::Roulette

Constants

ROULETTE_DATA_URL

Public Instance Methods

canonical_branch_name(branch_name) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

Like team, but only returns teammates in the current project, based on project_name.

@return [Array<Teammate>]

# 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:) click to toggle source

Known issue: If someone is rejected due to OOO, and then becomes not OOO, the selection will change on next spin @param [Array<Teammate>] people

# 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() click to toggle source

Looks up the current list of GitLab team members and parses it into a useful form

@return [Array<Teammate>]

# 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

Private Instance Methods

mr_author?(person) click to toggle source

@param [Teammate] person @return [Boolean]

# File lib/gitlab_roulette/danger/roulette.rb, line 64
def mr_author?(person)
  person.username == gitlab.mr_author
end
valid_person?(person) click to toggle source

@param [Teammate] person @return [Boolean]

# File lib/gitlab_roulette/danger/roulette.rb, line 58
def valid_person?(person)
  !mr_author?(person) && person.available?
end