class Gitlab::Danger::Teammate

Attributes

name[R]
projects[R]
role[R]
username[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/gitlab_roulette/danger/teammate.rb, line 10
def initialize(options = {})
  @username = options['username']
  @name = options['name'] || @username
  @role = options['role']
  @projects = options['projects']
end

Public Instance Methods

available?() click to toggle source

@return [Boolean]

# File lib/gitlab_roulette/danger/teammate.rb, line 47
def available?
  !out_of_office? && has_capacity?
end
in_project?(name) click to toggle source
# File lib/gitlab_roulette/danger/teammate.rb, line 21
def in_project?(name)
  projects&.has_key?(name)
end
maintainer?(project, category, labels) click to toggle source
# File lib/gitlab_roulette/danger/teammate.rb, line 35
def maintainer?(project, category, labels)
  has_capability?(project, category, :maintainer, labels)
end
markdown_name() click to toggle source
# File lib/gitlab_roulette/danger/teammate.rb, line 17
def markdown_name
  "[#{name}](#{gitlab_host}/#{username}) (`@#{username}`)"
end
reviewer?(project, category, labels) click to toggle source

Traintainers also count as reviewers

# File lib/gitlab_roulette/danger/teammate.rb, line 26
def reviewer?(project, category, labels)
  has_capability?(project, category, :reviewer, labels) ||
    traintainer?(project, category, labels)
end
status() click to toggle source
# File lib/gitlab_roulette/danger/teammate.rb, line 39
def status
  api_endpoint = "#{gitlab_host}/api/v4/users/#{CGI.escape(username)}/status"
  @status ||= Gitlab::Danger::RequestHelper.http_get_json(api_endpoint)
rescue Gitlab::Danger::RequestHelper::HTTPError, JSON::ParserError
  nil # better no status than a crashing Danger
end
traintainer?(project, category, labels) click to toggle source
# File lib/gitlab_roulette/danger/teammate.rb, line 31
def traintainer?(project, category, labels)
  has_capability?(project, category, :trainee_maintainer, labels)
end

Private Instance Methods

capabilities(project) click to toggle source
# File lib/gitlab_roulette/danger/teammate.rb, line 83
def capabilities(project)
  Array(projects.fetch(project, []))
end
gitlab_host() click to toggle source
# File lib/gitlab_roulette/danger/teammate.rb, line 53
def gitlab_host
  @gitlab_host ||= ENV["GITLAB_HOST"]
end
has_capability?(project, category, kind, labels) click to toggle source
# File lib/gitlab_roulette/danger/teammate.rb, line 67
def has_capability?(project, category, kind, labels)
  case category
  when :test
    area = role[/Software Engineer in Test(?:.*?, (\w+))/, 1]

    area && labels.any?("devops::#{area.downcase}") if kind == :reviewer
  when :engineering_productivity
    return false unless role[/Engineering Productivity/]
    return true if kind == :reviewer

    capabilities(project).include?("#{kind} backend")
  else
    capabilities(project).include?("#{kind} #{category}")
  end
end
has_capacity?() click to toggle source

@return [Boolean]

# File lib/gitlab_roulette/danger/teammate.rb, line 63
def has_capacity?
  status&.dig("emoji") != 'red_circle'
end
out_of_office?() click to toggle source

@return [Boolean]

# File lib/gitlab_roulette/danger/teammate.rb, line 58
def out_of_office?
  status&.dig("message")&.match?(/OOO/i) || false
end