2019-02-05 12:16:18 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Danger
|
|
|
|
class Teammate
|
2019-05-23 14:07:59 -04:00
|
|
|
attr_reader :name, :username, :role, :projects
|
2019-02-05 12:16:18 -05:00
|
|
|
|
|
|
|
def initialize(options = {})
|
|
|
|
@username = options['username']
|
2019-05-29 11:15:09 -04:00
|
|
|
@name = options['name'] || @username
|
2019-05-23 14:07:59 -04:00
|
|
|
@role = options['role']
|
2019-02-05 12:16:18 -05:00
|
|
|
@projects = options['projects']
|
|
|
|
end
|
|
|
|
|
|
|
|
def markdown_name
|
|
|
|
"[#{name}](https://gitlab.com/#{username}) (`@#{username}`)"
|
|
|
|
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
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-05-23 14:07:59 -04:00
|
|
|
def has_capability?(project, category, kind, labels)
|
|
|
|
case category
|
|
|
|
when :test
|
|
|
|
area = role[/Test Automation Engineer, (\w+)/, 1]
|
|
|
|
|
|
|
|
area && labels.any?(area) if kind == :reviewer
|
|
|
|
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
|