Class: Gitlab::Danger::Teammate

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_roulette/danger/teammate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Teammate

Returns a new instance of Teammate.



10
11
12
13
14
15
# 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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/gitlab_roulette/danger/teammate.rb', line 8

def name
  @name
end

#projectsObject (readonly)

Returns the value of attribute projects.



8
9
10
# File 'lib/gitlab_roulette/danger/teammate.rb', line 8

def projects
  @projects
end

#roleObject (readonly)

Returns the value of attribute role.



8
9
10
# File 'lib/gitlab_roulette/danger/teammate.rb', line 8

def role
  @role
end

#usernameObject (readonly)

Returns the value of attribute username.



8
9
10
# File 'lib/gitlab_roulette/danger/teammate.rb', line 8

def username
  @username
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/gitlab_roulette/danger/teammate.rb', line 47

def available?
  !out_of_office? && has_capacity?
end

#in_project?(name) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/gitlab_roulette/danger/teammate.rb', line 21

def in_project?(name)
  projects&.has_key?(name)
end

#maintainer?(project, category, labels) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/gitlab_roulette/danger/teammate.rb', line 35

def maintainer?(project, category, labels)
  has_capability?(project, category, :maintainer, labels)
end

#markdown_nameObject



17
18
19
# File 'lib/gitlab_roulette/danger/teammate.rb', line 17

def markdown_name
  "[#{name}](#{gitlab_host}/#{username}) (`@#{username}`)"
end

#reviewer?(project, category, labels) ⇒ Boolean

Traintainers also count as reviewers

Returns:

  • (Boolean)


26
27
28
29
# 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

#statusObject



39
40
41
42
43
44
# 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) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/gitlab_roulette/danger/teammate.rb', line 31

def traintainer?(project, category, labels)
  has_capability?(project, category, :trainee_maintainer, labels)
end