gitlab-dangerfiles 3.6.1 → 3.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b09d209b943b3290f35336c38330a088cb19864a1f275c7019080f5a40aead19
4
- data.tar.gz: cfd9105eaf80390efce141b0fbc7ed37cc6b68883051f65b62881e136b810fd3
3
+ metadata.gz: 5c9ef239b79432bbb3b87cd49450338435f8ea5e0d27ed4beff1c2ce019dc79a
4
+ data.tar.gz: f5b42d80cba45edaba0bbda8fbbb314546489743e16ec74b7ab28dfc89bd4acb
5
5
  SHA512:
6
- metadata.gz: 4c5dd9b9adaeb69f2dac57d9a8dc7b7c06faa32dc3b7c865ef66176ccb4fc51a2fae329d24bbab69e261f89a3ac9b60b882bd11cf15b12d9b57118ebfff9d28e
7
- data.tar.gz: 61bb13462bfe1eb1531455a346b6a0285c87687fc89b9f8dfedce107f5872ddc8a5db54bb0cc6886154ea1ac63a04e8cd3ffe92a561e1db859e85d4ce8ce9290
6
+ metadata.gz: 3dc38989aa7959bac78ec9bcd36fa7ddfcd0c265b6a049c8ac37d5163bf8834e930e317368402d53850a8a12161bdf8f38cb1309068c27319f34c9a5b7c85d06
7
+ data.tar.gz: 779f8c6c3f1b817b88813010048d1541609fca1e92bd3021abf4f8b18f46fffcbee8ed239a48d78254a6858925d56b62ddf202b3f8c361b62f4ffcc57476fc51
data/.rubocop.yml CHANGED
@@ -32,6 +32,9 @@ Style/HashSyntax:
32
32
  Style/StringLiterals:
33
33
  EnforcedStyle: double_quotes
34
34
 
35
+ Style/TrailingCommaInHashLiteral:
36
+ EnforcedStyleForMultiline: consistent_comma
37
+
35
38
  # Was problematic, and not included in the .rubocop_todo.yml
36
39
  GitlabSecurity/PublicSend:
37
40
  Enabled: false
@@ -26,6 +26,7 @@ module Danger
26
26
  integrations_be: '~"group::integrations" (backend)',
27
27
  integrations_fe: '~"group::integrations" (frontend)',
28
28
  "Authentication and Authorization": '~"group::authentication and authorization"',
29
+ Compliance: '~"group::compliance"',
29
30
  }.freeze
30
31
 
31
32
  # Allows to set specific rule's configuration by passing a block.
@@ -14,6 +14,7 @@ module Gitlab
14
14
  {
15
15
  subject_too_short: "The %s must contain at least #{MIN_SUBJECT_WORDS_COUNT} words",
16
16
  subject_too_long: "The %s may not be longer than #{MAX_LINE_LENGTH} characters",
17
+ subject_starts_with_a_space: "The %s must not start with a space",
17
18
  subject_starts_with_lowercase: "The %s must start with a capital letter",
18
19
  subject_ends_with_a_period: "The %s must not end with a period",
19
20
  }
@@ -49,6 +50,10 @@ module Gitlab
49
50
  add_problem(:subject_too_long, self.class.subject_description)
50
51
  end
51
52
 
53
+ if subject_starts_with_a_space?
54
+ add_problem(:subject_starts_with_a_space, self.class.subject_description)
55
+ end
56
+
52
57
  if subject_starts_with_lowercase?
53
58
  add_problem(:subject_starts_with_lowercase, self.class.subject_description)
54
59
  end
@@ -78,8 +83,13 @@ module Gitlab
78
83
  line.length > MAX_LINE_LENGTH
79
84
  end
80
85
 
86
+ def subject_starts_with_a_space?
87
+ subject.start_with?(" ")
88
+ end
89
+
81
90
  def subject_starts_with_lowercase?
82
91
  return false if subject.empty?
92
+ return false if subject_starts_with_a_space?
83
93
  return false if ("A".."Z").cover?(subject[0])
84
94
 
85
95
  first_char = subject.sub(/\A(\[[^\]]+\]|[^:\s]+:)\s/, "")[0]
@@ -0,0 +1,97 @@
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
+ test: Test,
15
+ tooling: Tooling,
16
+ integrations_be: IntegrationsBE,
17
+ integrations_fe: IntegrationsFE,
18
+ ux: UX,
19
+ }.freeze
20
+ end
21
+ private_class_method :name_to_class
22
+
23
+ def has_capability?(...)
24
+ has_particular_capability?(...) || has_universal_capability?(...)
25
+ end
26
+
27
+ private
28
+
29
+ def has_particular_capability?(teammate)
30
+ teammate.capabilities(project).include?(capability)
31
+ end
32
+
33
+ def has_universal_capability?(teammate)
34
+ false
35
+ end
36
+
37
+ def capability
38
+ # name can be nil
39
+ @capability ||= "#{kind} #{name}".strip
40
+ end
41
+
42
+ class Test < Category
43
+ private
44
+
45
+ def has_particular_capability?(teammate)
46
+ return false if kind != :reviewer
47
+
48
+ area = teammate.role[/Software Engineer in Test(?:.*?, (\w+))/, 1]
49
+
50
+ area && labels.any?("devops::#{area.downcase}")
51
+ end
52
+ end
53
+
54
+ class Tooling < Category
55
+ private
56
+
57
+ def has_particular_capability?(teammate)
58
+ if super
59
+ true
60
+ elsif %i[trainee_maintainer maintainer].include?(kind)
61
+ false
62
+ else # fallback to backend reviewer
63
+ teammate.capabilities(project).include?("#{kind} backend")
64
+ end
65
+ end
66
+ end
67
+
68
+ class IntegrationsBE < Category
69
+ private
70
+
71
+ def has_particular_capability?(teammate)
72
+ kind == :reviewer &&
73
+ teammate.role.match?(/Backend Engineer.+Manage:Integrations/)
74
+ end
75
+ end
76
+
77
+ class IntegrationsFE < Category
78
+ private
79
+
80
+ def has_particular_capability?(teammate)
81
+ kind == :reviewer &&
82
+ teammate.role.match?(/Frontend Engineer.+Manage:Integrations/)
83
+ end
84
+ end
85
+
86
+ class UX < Category
87
+ private
88
+
89
+ def has_universal_capability?(teammate)
90
+ teammate.projects.each_value.find do |capabilities|
91
+ capabilities.include?(capability)
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "category"
4
+
3
5
  module Gitlab
4
6
  module Dangerfiles
5
7
  class Teammate
@@ -74,6 +76,10 @@ module Gitlab
74
76
  (Time.now.utc + tz_offset_hours * 3600).hour
75
77
  end
76
78
 
79
+ def capabilities(project)
80
+ projects.fetch(project, [])
81
+ end
82
+
77
83
  protected
78
84
 
79
85
  def floored_offset_hours
@@ -123,42 +129,7 @@ module Gitlab
123
129
  end
124
130
 
125
131
  def has_capability?(project, category, kind, labels)
126
- case category
127
- when :test
128
- area = role[/Software Engineer in Test(?:.*?, (\w+))/, 1]
129
-
130
- area && labels.any?("devops::#{area.downcase}") if kind == :reviewer
131
- when :tooling, :engineering_productivity # Deprecated as of 2.3.0 in favor of tooling
132
- return true if capabilities(project).include?("#{kind} #{category}")
133
- return false if %i[trainee_maintainer maintainer].include?(kind)
134
-
135
- capabilities(project).include?("#{kind} backend") # fallback to backend reviewer
136
- when :integrations_be
137
- kind == :reviewer &&
138
- role.match?(/Backend Engineer.+Manage:Integrations/)
139
- when :integrations_fe
140
- kind == :reviewer &&
141
- role.match?(/Frontend Engineer.+Manage:Integrations/)
142
- when nil
143
- capabilities(project).include?("#{kind}")
144
- else
145
- capabilities(project).include?("#{kind} #{category}")
146
- end || has_universal_capability?(category, kind, labels)
147
- end
148
-
149
- def has_universal_capability?(category, kind, labels)
150
- case category
151
- when :ux
152
- capacity = "#{kind} #{category}"
153
-
154
- projects.each_value.find do |capabilities|
155
- capabilities.include?(capacity)
156
- end
157
- end
158
- end
159
-
160
- def capabilities(project)
161
- projects.fetch(project, [])
132
+ Category.for(category, project: project, kind: kind, labels: labels).has_capability?(self)
162
133
  end
163
134
 
164
135
  def pluralize(count, singular, plural)
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "3.6.1"
3
+ VERSION = "3.6.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-dangerfiles
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.1
4
+ version: 3.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-18 00:00:00.000000000 Z
11
+ date: 2022-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -183,6 +183,7 @@ files:
183
183
  - lib/gitlab/Dangerfile
184
184
  - lib/gitlab/dangerfiles.rb
185
185
  - lib/gitlab/dangerfiles/base_linter.rb
186
+ - lib/gitlab/dangerfiles/category.rb
186
187
  - lib/gitlab/dangerfiles/changes.rb
187
188
  - lib/gitlab/dangerfiles/commit_linter.rb
188
189
  - lib/gitlab/dangerfiles/config.rb