lib/gitlab/dangerfiles/category.rb in gitlab-dangerfiles-3.10.0 vs lib/gitlab/dangerfiles/category.rb in gitlab-dangerfiles-3.11.0
- old
+ new
@@ -19,24 +19,16 @@
ux: UX,
}.freeze
end
private_class_method :name_to_class
- def has_capability?(...)
- has_particular_capability?(...) || has_universal_capability?(...)
+ def has_capability?(teammate)
+ teammate.capabilities(project).include?(capability)
end
private
- def has_particular_capability?(teammate)
- teammate.capabilities(project).include?(capability)
- end
-
- def has_universal_capability?(teammate)
- false
- end
-
def capability
@capability ||= "#{kind} #{name}"
end
class None < Category
@@ -44,25 +36,21 @@
@capability ||= kind.to_s
end
end
class Test < Category
- private
-
- def has_particular_capability?(teammate)
+ def has_capability?(teammate)
return false if kind != :reviewer
area = teammate.role[/Software Engineer in Test(?:.*?, (\w+))/, 1]
- area && labels.any?("devops::#{area.downcase}")
+ !!area && labels.any?("devops::#{area.downcase}")
end
end
class Tooling < Category
- private
-
- def has_particular_capability?(teammate)
+ def has_capability?(teammate)
if super
true
elsif %i[trainee_maintainer maintainer].include?(kind)
false
else # fallback to backend reviewer
@@ -70,62 +58,55 @@
end
end
end
class ImportIntegrateBE < Category
- private
-
- def has_particular_capability?(teammate)
+ def has_capability?(teammate)
kind == :reviewer &&
teammate.role.match?(/Backend Engineer.+Manage:Import and Integrate/)
end
end
class ImportIntegrateFE < Category
- private
-
- def has_particular_capability?(teammate)
+ def has_capability?(teammate)
kind == :reviewer &&
teammate.role.match?(/Frontend Engineer.+Manage:Import and Integrate/)
end
end
class UX < Category
- private
+ def has_capability?(teammate)
+ super &&
- def has_particular_capability?(teammate)
- if labels.any?("Community contribution")
- can_review_wider_community_contribution?(teammate)
- else
- super
- end
+ if labels.any?("Community contribution")
+ can_review_wider_community_contribution?(teammate)
+ else
+ can_review_team_memeber_contribution?(teammate)
+ end
end
- def has_universal_capability?(teammate)
- # No universal reviewer for community contribution.
- # If we do, then picking from corresponding group won't be accurate.
- # After solving the following issue, then we can revisit this:
- # https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/issues/58
- return false if labels.any?("Community contribution")
+ private
- teammate.projects.each_value.any? do |capabilities|
- capabilities.include?(capability)
- end
+ def can_review_wider_community_contribution?(teammate)
+ # We want the designer for the team to review the wider community
+ # contribution because they're more familiar with that area.
+ the_designer_for_the_team?(teammate)
end
- def can_review_wider_community_contribution?(teammate)
+ def can_review_team_memeber_contribution?(teammate)
+ # We don't want the designer for the team to review merge
+ # requests for the same team which is designed by themselves.
+ # So they can only review if they're not the designer for the team.
+ !the_designer_for_the_team?(teammate)
+ end
+
+ def the_designer_for_the_team?(teammate)
# Pick corresponding group for community contribution
- # Role can be:
- # Product Designer, Create:Source Code
- # Product Designer, Verify:Pipeline Insights, Verify:Runner
- # Product Designer, Release
# Specialty can be:
# Source Code
# [Growth: Activation, Growth: Expansion]
# Runner
- areas = teammate.role[/Product Designer(?:.*?, (.+))/, 1]&.split(",")
-
- group_labels = [*teammate.specialty, *areas].map do |field|
+ group_labels = Array(teammate.specialty).map do |field|
group = field.strip.sub(/^.+: ?/, "").downcase
"group::#{group}"
end