Commit f1c97daf authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'danger-danger-palm-trees-mean-holiday' into 'master'

Make danger PTO-emoji-aware

See merge request gitlab-org/gitlab!31737
parents d2254dab 9c39d1e2
...@@ -64,7 +64,7 @@ It picks reviewers and maintainers from the list at the ...@@ -64,7 +64,7 @@ It picks reviewers and maintainers from the list at the
page, with these behaviors: page, with these behaviors:
1. It will not pick people whose [GitLab status](../user/profile/index.md#current-status) 1. It will not pick people whose [GitLab status](../user/profile/index.md#current-status)
contains the string 'OOO'. contains the string 'OOO', or the emoji is `:palm_tree:` or `:beach:`.
1. [Trainee maintainers](https://about.gitlab.com/handbook/engineering/workflow/code-review/#trainee-maintainer) 1. [Trainee maintainers](https://about.gitlab.com/handbook/engineering/workflow/code-review/#trainee-maintainer)
are three times as likely to be picked as other reviewers. are three times as likely to be picked as other reviewers.
1. It always picks the same reviewers and maintainers for the same 1. It always picks the same reviewers and maintainers for the same
......
# frozen_string_literal: true # frozen_string_literal: true
require 'cgi' require 'cgi'
require 'set'
module Gitlab module Gitlab
module Danger module Danger
class Teammate class Teammate
attr_reader :name, :username, :role, :projects 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 = {}) def initialize(options = {})
@username = options['username'] @username = options['username']
@name = options['name'] || @username @name = options['name'] || @username
...@@ -37,10 +44,14 @@ module Gitlab ...@@ -37,10 +44,14 @@ module Gitlab
end end
def status def status
api_endpoint = "https://gitlab.com/api/v4/users/#{CGI.escape(username)}/status" return @status if defined?(@status)
@status ||= Gitlab::Danger::RequestHelper.http_get_json(api_endpoint)
rescue Gitlab::Danger::RequestHelper::HTTPError, JSON::ParserError @status ||=
nil # better no status than a crashing Danger 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 end
# @return [Boolean] # @return [Boolean]
...@@ -50,14 +61,22 @@ module Gitlab ...@@ -50,14 +61,22 @@ module Gitlab
private 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] # @return [Boolean]
def out_of_office? def out_of_office?
status&.dig("message")&.match?(/OOO/i) || false status&.dig("message")&.match?(/OOO/i) || OOO_EMOJI.include?(status_emoji)
end end
# @return [Boolean] # @return [Boolean]
def has_capacity? def has_capacity?
status&.dig("emoji") != 'red_circle' !AT_CAPACITY_EMOJI.include?(status_emoji)
end end
def has_capability?(project, category, kind, labels) def has_capability?(project, category, kind, labels)
......
...@@ -163,6 +163,13 @@ describe Gitlab::Danger::Teammate do ...@@ -163,6 +163,13 @@ describe Gitlab::Danger::Teammate do
{ message: 'OOO: massage' } | false { message: 'OOO: massage' } | false
{ message: 'love it SOOO much' } | false { message: 'love it SOOO much' } | false
{ emoji: 'red_circle' } | false { emoji: 'red_circle' } | false
{ emoji: 'palm_tree' } | false
{ emoji: 'beach' } | false
{ emoji: 'beach_umbrella' } | false
{ emoji: 'beach_with_umbrella' } | false
{ emoji: nil } | true
{ emoji: '' } | true
{ emoji: 'dancer' } | true
end end
with_them do with_them do
...@@ -175,9 +182,9 @@ describe Gitlab::Danger::Teammate do ...@@ -175,9 +182,9 @@ describe Gitlab::Danger::Teammate do
end end
it 'returns true if request fails' do it 'returns true if request fails' do
expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json) expect(Gitlab::Danger::RequestHelper)
.twice .to receive(:http_get_json)
.and_raise(Gitlab::Danger::RequestHelper::HTTPError.new) .and_raise(Gitlab::Danger::RequestHelper::HTTPError.new)
expect(subject.available?).to be true expect(subject.available?).to be true
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment