gitlab-dangerfiles 3.6.0 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af0d569b13b09e65dfaed6f7eaf3519e314e510e71279b395eabccdb49901f83
4
- data.tar.gz: 24050d6f8149c4e902d3c98a8b7d89aa8070a0e2445724f0f1733498d824800c
3
+ metadata.gz: 5c9ef239b79432bbb3b87cd49450338435f8ea5e0d27ed4beff1c2ce019dc79a
4
+ data.tar.gz: f5b42d80cba45edaba0bbda8fbbb314546489743e16ec74b7ab28dfc89bd4acb
5
5
  SHA512:
6
- metadata.gz: 84d10142bb9fbf7fe03c9b4d6aee7f39cf0e9ff0ca90c167b484f3d5f1f3a13ef7aed7756c2d1b7b2873e896025ac91dc17b40b5c625d3d2cebad95f4114f3d9
7
- data.tar.gz: 87cb02420672c5f9bb171837852733ee9550f30afc918ddb948a1e469224261eda5896ad18993b6aa550cc3d9ec5a782c1d17c278a40d3fc7a316edbf32d63c0
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.+Ecosystem:Integrations/)
139
- when :integrations_fe
140
- kind == :reviewer &&
141
- role.match?(/Frontend Engineer.+Ecosystem: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.0"
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.0
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-17 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