debian-mirror-gitlab/lib/gitlab/danger/teammate.rb
2019-05-18 00:54:41 +05:30

42 lines
1,015 B
Ruby

# frozen_string_literal: true
module Gitlab
module Danger
class Teammate
attr_reader :name, :username, :projects
def initialize(options = {})
@name = options['name']
@username = options['username']
@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)
capabilities(project).include?("reviewer #{category}") || traintainer?(project, category)
end
def traintainer?(project, category)
capabilities(project).include?("trainee_maintainer #{category}")
end
def maintainer?(project, category)
capabilities(project).include?("maintainer #{category}")
end
private
def capabilities(project)
Array(projects.fetch(project, []))
end
end
end
end