2019-02-05 12:16:18 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Danger
|
|
|
|
class Teammate
|
2020-06-17 14:09:08 -04:00
|
|
|
attr_reader :username, :name, :markdown_name, :role, :projects, :available, :has_capacity
|
2020-05-14 11:08:14 -04:00
|
|
|
|
2020-06-17 14:09:08 -04:00
|
|
|
# The options data are produced by https://gitlab.com/gitlab-org/gitlab-roulette/-/blob/master/lib/team_member.rb
|
2019-02-05 12:16:18 -05:00
|
|
|
def initialize(options = {})
|
|
|
|
@username = options['username']
|
2020-06-17 14:09:08 -04:00
|
|
|
@name = options['name']
|
|
|
|
@markdown_name = options['markdown_name']
|
2019-05-23 14:07:59 -04:00
|
|
|
@role = options['role']
|
2019-02-05 12:16:18 -05:00
|
|
|
@projects = options['projects']
|
2020-06-17 14:09:08 -04:00
|
|
|
@available = options['available']
|
|
|
|
@has_capacity = options['has_capacity']
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def in_project?(name)
|
|
|
|
projects&.has_key?(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Traintainers also count as reviewers
|
2019-05-23 14:07:59 -04:00
|
|
|
def reviewer?(project, category, labels)
|
|
|
|
has_capability?(project, category, :reviewer, labels) ||
|
|
|
|
traintainer?(project, category, labels)
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
2019-05-23 14:07:59 -04:00
|
|
|
def traintainer?(project, category, labels)
|
|
|
|
has_capability?(project, category, :trainee_maintainer, labels)
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
2019-05-23 14:07:59 -04:00
|
|
|
def maintainer?(project, category, labels)
|
|
|
|
has_capability?(project, category, :maintainer, labels)
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
2019-10-16 17:07:22 -04:00
|
|
|
private
|
|
|
|
|
2019-05-23 14:07:59 -04:00
|
|
|
def has_capability?(project, category, kind, labels)
|
|
|
|
case category
|
|
|
|
when :test
|
2019-11-22 16:06:19 -05:00
|
|
|
area = role[/Software Engineer in Test(?:.*?, (\w+))/, 1]
|
2019-05-23 14:07:59 -04:00
|
|
|
|
2019-08-27 13:13:55 -04:00
|
|
|
area && labels.any?("devops::#{area.downcase}") if kind == :reviewer
|
2019-09-03 18:02:55 -04:00
|
|
|
when :engineering_productivity
|
2019-10-31 08:06:26 -04:00
|
|
|
return false unless role[/Engineering Productivity/]
|
|
|
|
return true if kind == :reviewer
|
|
|
|
|
|
|
|
capabilities(project).include?("#{kind} backend")
|
2019-05-23 14:07:59 -04:00
|
|
|
else
|
|
|
|
capabilities(project).include?("#{kind} #{category}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-05 12:16:18 -05:00
|
|
|
def capabilities(project)
|
2019-03-06 11:00:27 -05:00
|
|
|
Array(projects.fetch(project, []))
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|