gitlab-dangerfiles 4.5.1 → 4.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gitlab
4
- module Dangerfiles
5
- CategoryStruct = Struct.new(:name, :project, :kind, :labels, keyword_init: true)
6
-
7
- class Category < CategoryStruct
8
- def self.for(name, **arguments)
9
- (name_to_class[name] || self).new(name: name, **arguments)
10
- end
11
-
12
- def self.name_to_class
13
- @name_to_class ||= {
14
- none: None,
15
- test: Test,
16
- tooling: Tooling,
17
- import_integrate_be: ImportIntegrateBE,
18
- import_integrate_fe: ImportIntegrateFE,
19
- ux: UX,
20
- }.freeze
21
- end
22
- private_class_method :name_to_class
23
-
24
- def has_capability?(teammate)
25
- teammate.capabilities(project).include?(capability)
26
- end
27
-
28
- private
29
-
30
- def capability
31
- @capability ||= "#{kind} #{name}"
32
- end
33
-
34
- class None < Category
35
- def capability
36
- @capability ||= kind.to_s
37
- end
38
- end
39
-
40
- class Test < Category
41
- def has_capability?(teammate)
42
- return false if kind != :reviewer
43
-
44
- area = teammate.role[/Software Engineer in Test(?:.*?, (\w+))/, 1]
45
-
46
- !!area && labels.any?("devops::#{area.downcase}")
47
- end
48
- end
49
-
50
- class Tooling < Category
51
- def has_capability?(teammate)
52
- if super
53
- true
54
- elsif %i[trainee_maintainer maintainer].include?(kind)
55
- false
56
- else # fallback to backend reviewer
57
- teammate.capabilities(project).include?("#{kind} backend")
58
- end
59
- end
60
- end
61
-
62
- class ImportIntegrateBE < Category
63
- def has_capability?(teammate)
64
- kind == :reviewer &&
65
- teammate.role.match?(/Backend Engineer.+Manage:Import and Integrate/)
66
- end
67
- end
68
-
69
- class ImportIntegrateFE < Category
70
- def has_capability?(teammate)
71
- kind == :reviewer &&
72
- teammate.role.match?(/Frontend Engineer.+Manage:Import and Integrate/)
73
- end
74
- end
75
-
76
- class UX < Category
77
- def has_capability?(teammate)
78
- super &&
79
-
80
- if labels.any?("Community contribution")
81
- # We want the designer for the team to review the wider community
82
- # contribution because they're more familiar with that area.
83
- the_designer_for_the_team?(teammate)
84
- else
85
- # We don't want the designer for the team to review merge
86
- # requests for the same team which is designed by themselves.
87
- # So they can only review if they're not the designer for the team.
88
- !the_designer_for_the_team?(teammate)
89
- end
90
- end
91
-
92
- private
93
-
94
- def the_designer_for_the_team?(teammate)
95
- # Pick corresponding group for community contribution
96
- # Specialty can be:
97
- # Source Code
98
- # [Growth: Activation, Growth: Expansion]
99
- # Runner
100
- group_labels = Array(teammate.specialty).map do |field|
101
- group = field.strip.sub(/^.+: ?/, "").downcase
102
-
103
- "group::#{group}"
104
- end
105
-
106
- (group_labels & labels).any?
107
- end
108
- end
109
- end
110
- end
111
- end