Class: Gitlab::Danger::Teammate
- Inherits:
-
Object
- Object
- Gitlab::Danger::Teammate
- Defined in:
- lib/gitlab_roulette/danger/teammate.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#projects ⇒ Object
readonly
Returns the value of attribute projects.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #available? ⇒ Boolean
- #in_project?(name) ⇒ Boolean
-
#initialize(options = {}) ⇒ Teammate
constructor
A new instance of Teammate.
- #maintainer?(project, category, labels) ⇒ Boolean
- #markdown_name ⇒ Object
-
#reviewer?(project, category, labels) ⇒ Boolean
Traintainers also count as reviewers.
- #status ⇒ Object
- #traintainer?(project, category, labels) ⇒ Boolean
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( = {}) @username = ['username'] @name = ['name'] || @username @role = ['role'] @projects = ['projects'] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/gitlab_roulette/danger/teammate.rb', line 8 def name @name end |
#projects ⇒ Object (readonly)
Returns the value of attribute projects.
8 9 10 |
# File 'lib/gitlab_roulette/danger/teammate.rb', line 8 def projects @projects end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
8 9 10 |
# File 'lib/gitlab_roulette/danger/teammate.rb', line 8 def role @role end |
#username ⇒ Object (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
47 48 49 |
# File 'lib/gitlab_roulette/danger/teammate.rb', line 47 def available? !out_of_office? && has_capacity? end |
#in_project?(name) ⇒ 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
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_name ⇒ Object
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
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 |
#status ⇒ Object
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
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 |