2019-02-05 12:16:18 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Danger
|
|
|
|
class Teammate
|
|
|
|
attr_reader :name, :username, :projects
|
|
|
|
|
|
|
|
def initialize(options = {})
|
|
|
|
@username = options['username']
|
2019-05-29 11:15:09 -04:00
|
|
|
@name = options['name'] || @username
|
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
|
|
|
|
def reviewer?(project, category)
|
2019-03-06 11:00:27 -05:00
|
|
|
capabilities(project).include?("reviewer #{category}") || traintainer?(project, category)
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def traintainer?(project, category)
|
2019-03-06 11:00:27 -05:00
|
|
|
capabilities(project).include?("trainee_maintainer #{category}")
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def maintainer?(project, category)
|
2019-03-06 11:00:27 -05:00
|
|
|
capabilities(project).include?("maintainer #{category}")
|
2019-02-05 12:16:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
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
|