debian-mirror-gitlab/lib/gitlab/danger/teammate.rb

56 lines
1.4 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
module Gitlab
module Danger
class Teammate
2019-09-04 21:01:54 +05:30
attr_reader :name, :username, :role, :projects
2019-07-07 11:18:12 +05:30
def initialize(options = {})
@username = options['username']
2019-09-04 21:01:54 +05:30
@name = options['name'] || @username
@role = options['role']
2019-07-07 11:18:12 +05:30
@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-09-04 21:01:54 +05:30
def reviewer?(project, category, labels)
has_capability?(project, category, :reviewer, labels) ||
traintainer?(project, category, labels)
2019-07-07 11:18:12 +05:30
end
2019-09-04 21:01:54 +05:30
def traintainer?(project, category, labels)
has_capability?(project, category, :trainee_maintainer, labels)
2019-07-07 11:18:12 +05:30
end
2019-09-04 21:01:54 +05:30
def maintainer?(project, category, labels)
has_capability?(project, category, :maintainer, labels)
2019-07-07 11:18:12 +05:30
end
private
2019-09-04 21:01:54 +05:30
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-07-07 11:18:12 +05:30
def capabilities(project)
Array(projects.fetch(project, []))
end
end
end
end