summaryrefslogtreecommitdiff
path: root/lib/gitlab/danger/teammate.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 14:34:42 +0000
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /lib/gitlab/danger/teammate.rb
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
downloadgitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'lib/gitlab/danger/teammate.rb')
-rw-r--r--lib/gitlab/danger/teammate.rb31
1 files changed, 25 insertions, 6 deletions
diff --git a/lib/gitlab/danger/teammate.rb b/lib/gitlab/danger/teammate.rb
index 55476cd9789..651b002d2bf 100644
--- a/lib/gitlab/danger/teammate.rb
+++ b/lib/gitlab/danger/teammate.rb
@@ -1,12 +1,19 @@
# frozen_string_literal: true
require 'cgi'
+require 'set'
module Gitlab
module Danger
class Teammate
attr_reader :name, :username, :role, :projects
+ AT_CAPACITY_EMOJI = Set.new(%w[red_circle]).freeze
+ OOO_EMOJI = Set.new(%w[
+ palm_tree
+ beach beach_umbrella beach_with_umbrella
+ ]).freeze
+
def initialize(options = {})
@username = options['username']
@name = options['name'] || @username
@@ -37,10 +44,14 @@ module Gitlab
end
def status
- api_endpoint = "https://gitlab.com/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
+ return @status if defined?(@status)
+
+ @status ||=
+ begin
+ Gitlab::Danger::RequestHelper.http_get_json(status_api_endpoint)
+ rescue Gitlab::Danger::RequestHelper::HTTPError, JSON::ParserError
+ nil # better no status than a crashing Danger
+ end
end
# @return [Boolean]
@@ -50,14 +61,22 @@ module Gitlab
private
+ def status_api_endpoint
+ "https://gitlab.com/api/v4/users/#{CGI.escape(username)}/status"
+ end
+
+ def status_emoji
+ status&.dig("emoji")
+ end
+
# @return [Boolean]
def out_of_office?
- status&.dig("message")&.match?(/OOO/i) || false
+ status&.dig("message")&.match?(/OOO/i) || OOO_EMOJI.include?(status_emoji)
end
# @return [Boolean]
def has_capacity?
- status&.dig("emoji") != 'red_circle'
+ !AT_CAPACITY_EMOJI.include?(status_emoji)
end
def has_capability?(project, category, kind, labels)