diff options
Diffstat (limited to 'lib/gitlab/danger/teammate.rb')
-rw-r--r-- | lib/gitlab/danger/teammate.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/gitlab/danger/teammate.rb b/lib/gitlab/danger/teammate.rb index 4ad66f61c2b..5c2324836d7 100644 --- a/lib/gitlab/danger/teammate.rb +++ b/lib/gitlab/danger/teammate.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'cgi' + module Gitlab module Danger class Teammate @@ -34,8 +36,30 @@ module Gitlab has_capability?(project, category, :maintainer, labels) 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 + end + + # @return [Boolean] + def available? + !out_of_office? && has_capacity? + end + private + # @return [Boolean] + def out_of_office? + status&.dig("message")&.match?(/OOO/i) || false + end + + # @return [Boolean] + def has_capacity? + status&.dig("emoji") != 'red_circle' + end + def has_capability?(project, category, kind, labels) case category when :test |