gitlab-dangerfiles 3.6.4 → 3.6.6

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: 34ff9782c4b20cd3c7dbb4a25d7ecdf66cf49ef303e1deb0bb04074e1c4fca21
4
- data.tar.gz: b21f8643147b7147fca7e5cba536c67bf98d65f827cb169d72fd2ac5ff3de355
3
+ metadata.gz: fe954dbacd967eb64f63f537578e4960bc9047e4669c3e5829eafab2d7a09bcf
4
+ data.tar.gz: fb0f4784b78d62d8fcf4d7c695a3589e0ca6cfb345043fee4538ae8513a1226d
5
5
  SHA512:
6
- metadata.gz: 7f9f43daf58a905f330ad98020327073a47692f24c0494d407d7e76aa8b18819b74839772c58b19d9081b04034154a06e8dee588c70898b71db08bab03fa31a9
7
- data.tar.gz: f30572b11ac8e2d9a4ab9cc35c19000c68ecdaefd72f8e276f18e73da3beeb64b81a44d2e4919977c0aabecafec5d3fa64a25443604c27168865a5acb7c6bf97
6
+ metadata.gz: c28b7ea174d422b1963fb450d2a25d470fca59992c3659262a577ecb29c48eb551fa29856c3c48c929ff26bc42fc6cb9e4cac997125fa51273cf9efb8b131cfb
7
+ data.tar.gz: 7e64f86bb7ed4c3805d6e1d229e6bcba37583b5e33f33fe8bbba230a8e603f08083b049c20de7d0621b78e88c6179bfc97087cee05577cdbe6de18519b5a35f2
data/.rubocop.yml CHANGED
@@ -32,9 +32,14 @@ Style/HashSyntax:
32
32
  Style/StringLiterals:
33
33
  EnforcedStyle: double_quotes
34
34
 
35
+ # To respect rufo formatting
35
36
  Style/TrailingCommaInHashLiteral:
36
37
  EnforcedStyleForMultiline: consistent_comma
37
38
 
39
+ # To respect rufo formatting
40
+ Layout/MultilineOperationIndentation:
41
+ Enabled: false
42
+
38
43
  # Was problematic, and not included in the .rubocop_todo.yml
39
44
  GitlabSecurity/PublicSend:
40
45
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2022-09-23 13:42:34 UTC using RuboCop version 1.36.0.
3
+ # on 2023-01-12 11:28:46 UTC using RuboCop version 1.36.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -86,18 +86,6 @@ Layout/LineEndStringConcatenationIndentation:
86
86
  Exclude:
87
87
  - 'lib/gitlab/dangerfiles/commit_linter.rb'
88
88
 
89
- # Offense count: 7
90
- # This cop supports safe autocorrection (--autocorrect).
91
- # Configuration parameters: EnforcedStyle, IndentationWidth.
92
- # SupportedStyles: aligned, indented
93
- Layout/MultilineOperationIndentation:
94
- Exclude:
95
- - 'lib/danger/plugins/changelog.rb'
96
- - 'lib/gitlab/dangerfiles/commit_linter.rb'
97
- - 'lib/gitlab/dangerfiles/emoji_checker.rb'
98
- - 'lib/gitlab/dangerfiles/teammate.rb'
99
- - 'spec/danger/plugins/roulette_spec.rb'
100
-
101
89
  # Offense count: 1
102
90
  # This cop supports safe autocorrection (--autocorrect).
103
91
  Layout/RescueEnsureAlignment:
@@ -157,21 +145,6 @@ Lint/RedundantDirGlobSort:
157
145
  - 'spec/gitlab/dangerfiles_spec.rb'
158
146
  - 'spec/spec_helper.rb'
159
147
 
160
- # Offense count: 1
161
- # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes.
162
- Metrics/AbcSize:
163
- Max: 67
164
-
165
- # Offense count: 1
166
- # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
167
- Metrics/CyclomaticComplexity:
168
- Max: 31
169
-
170
- # Offense count: 1
171
- # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
172
- Metrics/PerceivedComplexity:
173
- Max: 26
174
-
175
148
  # Offense count: 1
176
149
  # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
177
150
  # CheckDefinitionPathHierarchyRoots: lib, spec, test, src
@@ -238,7 +211,7 @@ RSpec/EmptyLineAfterLetBlock:
238
211
  Exclude:
239
212
  - 'spec/danger/plugins/internal/helper_spec.rb'
240
213
 
241
- # Offense count: 3
214
+ # Offense count: 7
242
215
  RSpec/ExpectInHook:
243
216
  Exclude:
244
217
  - 'spec/danger/plugins/internal/helper_spec.rb'
@@ -267,7 +240,7 @@ RSpec/LetBeforeExamples:
267
240
  - 'spec/danger/plugins/internal/helper_spec.rb'
268
241
  - 'spec/danger/plugins/roulette_spec.rb'
269
242
 
270
- # Offense count: 47
243
+ # Offense count: 51
271
244
  # This cop supports unsafe autocorrection (--autocorrect-all).
272
245
  # Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers.
273
246
  # SupportedStyles: inflected, explicit
@@ -282,7 +255,7 @@ RSpec/RepeatedExampleGroupDescription:
282
255
  Exclude:
283
256
  - 'spec/gitlab/dangerfiles/commit_linter_spec.rb'
284
257
 
285
- # Offense count: 31
258
+ # Offense count: 33
286
259
  # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
287
260
  RSpec/VerifiedDoubles:
288
261
  Exclude:
@@ -362,7 +335,7 @@ Style/IfInsideElse:
362
335
  Exclude:
363
336
  - 'lib/danger/rules/commit_messages/Dangerfile'
364
337
 
365
- # Offense count: 23
338
+ # Offense count: 22
366
339
  # This cop supports safe autocorrection (--autocorrect).
367
340
  Style/IfUnlessModifier:
368
341
  Exclude:
@@ -403,11 +376,6 @@ Style/NumericPredicate:
403
376
  - 'lib/danger/plugins/roulette.rb'
404
377
  - 'lib/gitlab/dangerfiles/teammate.rb'
405
378
 
406
- # Offense count: 1
407
- Style/OptionalArguments:
408
- Exclude:
409
- - 'lib/danger/rules/simple_roulette/Dangerfile'
410
-
411
379
  # Offense count: 8
412
380
  # This cop supports safe autocorrection (--autocorrect).
413
381
  # Configuration parameters: PreferredDelimiters.
@@ -420,7 +388,7 @@ Style/PercentLiteralDelimiters:
420
388
  - 'lib/gitlab/dangerfiles/tasks/main.rake'
421
389
  - 'spec/danger/plugins/internal/helper_spec.rb'
422
390
 
423
- # Offense count: 2
391
+ # Offense count: 4
424
392
  # This cop supports safe autocorrection (--autocorrect).
425
393
  # Configuration parameters: .
426
394
  # SupportedStyles: same_as_string_literals, single_quotes, double_quotes
@@ -444,12 +412,6 @@ Style/RedundantFreeze:
444
412
  - 'lib/gitlab/dangerfiles/emoji_checker.rb'
445
413
  - 'lib/gitlab/dangerfiles/title_linting.rb'
446
414
 
447
- # Offense count: 1
448
- # This cop supports unsafe autocorrection (--autocorrect-all).
449
- Style/RedundantInterpolation:
450
- Exclude:
451
- - 'lib/gitlab/dangerfiles/teammate.rb'
452
-
453
415
  # Offense count: 4
454
416
  # This cop supports safe autocorrection (--autocorrect).
455
417
  Style/RedundantRegexpEscape:
@@ -521,7 +483,7 @@ Style/StringConcatenation:
521
483
  - 'spec/gitlab/dangerfiles/commit_linter_spec.rb'
522
484
  - 'spec/gitlab/merge_request_linter_spec.rb'
523
485
 
524
- # Offense count: 6
486
+ # Offense count: 7
525
487
  # This cop supports safe autocorrection (--autocorrect).
526
488
  # Configuration parameters: EnforcedStyle.
527
489
  # SupportedStyles: single_quotes, double_quotes
@@ -549,7 +511,7 @@ Style/TrailingCommaInArguments:
549
511
  Exclude:
550
512
  - 'spec/danger/plugins/roulette_spec.rb'
551
513
 
552
- # Offense count: 18
514
+ # Offense count: 24
553
515
  # This cop supports safe autocorrection (--autocorrect).
554
516
  # Configuration parameters: EnforcedStyleForMultiline.
555
517
  # SupportedStylesForMultiline: comma, consistent_comma, no_comma
@@ -565,22 +527,3 @@ Style/TrailingCommaInArrayLiteral:
565
527
  - 'spec/gitlab/dangerfiles/title_linting_spec.rb'
566
528
  - 'spec/gitlab/dangerfiles/weightage/maintainers_spec.rb'
567
529
  - 'spec/gitlab/dangerfiles/weightage/reviewers_spec.rb'
568
-
569
- # Offense count: 29
570
- # This cop supports safe autocorrection (--autocorrect).
571
- # Configuration parameters: EnforcedStyleForMultiline.
572
- # SupportedStylesForMultiline: comma, consistent_comma, no_comma
573
- Style/TrailingCommaInHashLiteral:
574
- Exclude:
575
- - 'lib/danger/plugins/changelog.rb'
576
- - 'lib/danger/plugins/internal/helper.rb'
577
- - 'lib/danger/plugins/roulette.rb'
578
- - 'lib/gitlab/dangerfiles/base_linter.rb'
579
- - 'lib/gitlab/dangerfiles/commit_linter.rb'
580
- - 'lib/gitlab/dangerfiles/spec_helper.rb'
581
- - 'lib/gitlab/dangerfiles/type_label_guesser.rb'
582
- - 'spec/danger/plugins/internal/helper_spec.rb'
583
- - 'spec/danger/plugins/roulette_spec.rb'
584
- - 'spec/gitlab/dangerfiles/config_spec.rb'
585
- - 'spec/gitlab/dangerfiles/teammate_spec.rb'
586
- - 'spec/gitlab/dangerfiles_spec.rb'
@@ -15,6 +15,11 @@ module Danger
15
15
  CHANGELOG_EE_TRAILER_REGEX = /^EE: true$/.freeze
16
16
  CHANGELOG_MODIFIED_URL_TEXT = "**CHANGELOG.md was edited.** Please remove the additions and follow the [changelog guidelines](https://docs.gitlab.com/ee/development/changelog.html).\n\n"
17
17
  CHANGELOG_MISSING_URL_TEXT = "**[CHANGELOG missing](https://docs.gitlab.com/ee/development/changelog.html)**:\n\n"
18
+ IF_REVERT_MR_TEXT = <<~MARKDOWN
19
+ In a revert merge request? Use the revert merge request template to add labels [that skip changelog checks](https://docs.gitlab.com/ee/development/pipelines#revert-mrs).
20
+
21
+ Reverting something in the current milestone? A changelog isn't required. Skip changelog checks by adding `~"regression:*"` label, then re-run the danger job (there is a link at the bottom of this comment).
22
+ MARKDOWN
18
23
 
19
24
  OPTIONAL_CHANGELOG_MESSAGE = {
20
25
  local: "If this merge request [doesn't need a CHANGELOG entry](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry), feel free to ignore this message.",
@@ -110,25 +115,47 @@ module Danger
110
115
  valid_changelog_commits.map(&:category)
111
116
  end
112
117
 
113
- # rubocop:disable Style/SignalException
114
118
  def check!
115
- if git.modified_files.include?("CHANGELOG.md")
116
- fail modified_text
117
- end
119
+ return if revert_in_current_milestone?
120
+
121
+ critical_checks
122
+ regular_checks
123
+ changelog_categories_checks
124
+ end
125
+
126
+ def revert_in_current_milestone?
127
+ return false unless helper.revert_mr?
128
+
129
+ current_regression_label = "regression:#{helper.current_milestone.title}"
130
+
131
+ helper.mr_labels.any?(current_regression_label)
132
+ end
118
133
 
134
+ def critical_checks
135
+ check_result = ChangelogCheckResult.empty
136
+
137
+ check_result.error(modified_text) if git.modified_files.include?("CHANGELOG.md")
138
+
139
+ # Help the user to apply the correct labels to skip this danger check in case it's a revert MR
140
+ check_result.warning(IF_REVERT_MR_TEXT) if helper.revert_mr?
141
+
142
+ add_danger_messages(check_result)
143
+ end
144
+
145
+ def regular_checks
119
146
  if exist?
120
147
  add_danger_messages(check_changelog_path)
121
148
  elsif required?
122
- required_texts.each { |_, text| fail(text) } # rubocop:disable Lint/UnreachableLoop
149
+ required_texts.each { |_, text| fail(text) } # rubocop:disable Lint/UnreachableLoop, Style/SignalException
123
150
  elsif optional?
124
151
  message optional_text
125
152
  end
153
+ end
126
154
 
155
+ def changelog_categories_checks
127
156
  check_changelog_commit_categories
128
157
  end
129
158
 
130
- # rubocop:enable Style/SignalException
131
-
132
159
  # rubocop:disable Style/SignalException
133
160
  def add_danger_messages(check_result)
134
161
  check_result.errors.each { |error| fail(error) } # rubocop:disable Lint/UnreachableLoop
@@ -12,9 +12,11 @@ module Danger
12
12
  # Common helper functions for our danger scripts.
13
13
  class Helper < Danger::Plugin
14
14
  RELEASE_TOOLS_BOT = "gitlab-release-tools-bot"
15
+ # rubocop:disable Style/HashSyntax
15
16
  CATEGORY_LABELS = {
16
17
  docs: "~documentation", # Docs are reviewed along DevOps stages, so don't need roulette for now.
17
- none: "",
18
+ none: "None",
19
+ nil => "N/A",
18
20
  qa: "~QA",
19
21
  ux: "~UX",
20
22
  codeowners: '~"Code Owners"',
@@ -29,6 +31,9 @@ module Danger
29
31
  "Authentication and Authorization": '~"group::authentication and authorization"',
30
32
  Compliance: '~"group::compliance"',
31
33
  }.freeze
34
+ # rubocop:enable Style/HashSyntax
35
+
36
+ GITLAB_ORG_GROUP_ID = "9970"
32
37
 
33
38
  # Allows to set specific rule's configuration by passing a block.
34
39
  #
@@ -228,7 +233,7 @@ module Danger
228
233
  found
229
234
  end
230
235
 
231
- Array(categories || :unknown)
236
+ Array(categories || :none)
232
237
  end
233
238
 
234
239
  # @param category [Symbol] A category.
@@ -317,6 +322,13 @@ module Danger
317
322
  )
318
323
  end
319
324
 
325
+ # @return [Boolean] +false+ when not in the CI context, and returns +true+ if the MR title starts with Revert or revert
326
+ def revert_mr?
327
+ return false unless ci?
328
+
329
+ mr_title.start_with?(/[Rr]evert/)
330
+ end
331
+
320
332
  # @return [Boolean] +true+ when not in the CI context, and whether the MR is set to be squashed otherwise.
321
333
  def squash_mr?
322
334
  return true unless ci?
@@ -432,6 +444,12 @@ module Danger
432
444
  @labels_to_add ||= []
433
445
  end
434
446
 
447
+ def current_milestone
448
+ @current_milestone ||= gitlab_helper.api.group_milestones(GITLAB_ORG_GROUP_ID, state: "active")
449
+ .select { |m| m.title.match?(/\A\d+\.\d+\z/) && !m.expired && m.start_date && m.due_date }
450
+ .min_by(&:start_date)
451
+ end
452
+
435
453
  private
436
454
 
437
455
  # @return [Danger::RequestSources::GitLab, nil] the +gitlab+ helper, or +nil+ when it's not available.
@@ -48,9 +48,10 @@ module Danger
48
48
  # @param timezone_experiment [Boolean] Whether to select reviewers based in timezone or not.
49
49
  #
50
50
  # @return [Array<Spin>]
51
- def spin(project = nil, categories = [nil], timezone_experiment: false)
51
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
52
+ def spin(project = nil, categories = [:none], timezone_experiment: false)
52
53
  project = (project || config_project_name).downcase
53
- categories = categories.map { |category| category&.downcase }
54
+ categories = categories.map { |category| category&.downcase || :none }
54
55
  categories.reject! { |category| integrations_reject_category?(category, project) }
55
56
 
56
57
  spins = categories.sort_by(&:to_s).map do |category|
@@ -67,7 +68,8 @@ module Danger
67
68
  case spin.category
68
69
  when :qa
69
70
  # MR includes QA changes, but also other changes, and author isn't an SET
70
- if categories.size > 1 && !team_mr_author&.any_capability?(project, spin.category)
71
+ if categories.size > 1 &&
72
+ !(team_mr_author && team_mr_author.capabilities(project).any? { |capability| capability.end_with?("qa") })
71
73
  spin.optional_role = :maintainer
72
74
  end
73
75
  when :test
@@ -104,6 +106,8 @@ module Danger
104
106
  spins
105
107
  end
106
108
 
109
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
110
+
107
111
  def required_approvals
108
112
  approval_rules = helper.mr_approval_state["rules"]
109
113
 
@@ -60,12 +60,12 @@ def note_for_spin_role(spin, role)
60
60
  spin.public_send(role)&.markdown_name(author: roulette.team_mr_author)
61
61
  end
62
62
 
63
- def markdown_row_for_spins(category = nil, spins_array, has_categories:)
63
+ def markdown_row_for_spins(category, spins_array, show_category_column:)
64
64
  reviewer_note = note_for_spins_role(spins_array, :reviewer)
65
65
  maintainer_note = note_for_spins_role(spins_array, :maintainer)
66
66
 
67
67
  row = +"| #{reviewer_note} | #{maintainer_note} |"
68
- row.prepend("| #{helper.label_for_category(category)} ") if has_categories
68
+ row.prepend("| #{helper.label_for_category(category)} ") if show_category_column
69
69
  row
70
70
  end
71
71
 
@@ -73,7 +73,7 @@ changes = helper.changes_by_category
73
73
 
74
74
  # Replicating label based categories from:
75
75
  # https://gitlab.com/gitlab-org/gitlab/-/blob/master/danger/roulette/Dangerfile
76
- categories = Set.new(changes.keys - [:unknown])
76
+ categories = Set.new(changes.keys)
77
77
 
78
78
  # Ensure to spin for database reviewer/maintainer when ~database is applied (e.g. to review SQL queries)
79
79
  categories << :database if helper.mr_labels.include?('database')
@@ -91,15 +91,14 @@ categories.delete(:product_intelligence) if helper.mr_labels.include?("growth ex
91
91
  categories.subtract(helper.config.disabled_roulette_categories)
92
92
 
93
93
  if changes.any?
94
- has_categories = categories.any?
95
- categories = [nil] unless has_categories
94
+ show_category_column = categories.size > 1 || categories.first != :none
96
95
  random_roulette_spins = roulette.spin(nil, categories)
97
96
 
98
97
  rows = random_roulette_spins.map do |spin|
99
- markdown_row_for_spins(spin.category, [spin], has_categories: has_categories)
98
+ markdown_row_for_spins(spin.category, [spin], show_category_column: show_category_column)
100
99
  end
101
100
 
102
- table_header = has_categories ? TABLE_HEADER_WITH_CATEGORIES : TABLE_HEADER_WITHOUT_CATEGORIES
101
+ table_header = show_category_column ? TABLE_HEADER_WITH_CATEGORIES : TABLE_HEADER_WITHOUT_CATEGORIES
103
102
 
104
103
  markdown(MESSAGE)
105
104
  markdown(TABLE_MARKDOWN + table_header + rows.join("\n")) unless rows.empty?
@@ -11,6 +11,7 @@ module Gitlab
11
11
 
12
12
  def self.name_to_class
13
13
  @name_to_class ||= {
14
+ none: None,
14
15
  test: Test,
15
16
  tooling: Tooling,
16
17
  integrations_be: IntegrationsBE,
@@ -35,8 +36,13 @@ module Gitlab
35
36
  end
36
37
 
37
38
  def capability
38
- # name can be nil
39
- @capability ||= "#{kind} #{name}".strip
39
+ @capability ||= "#{kind} #{name}"
40
+ end
41
+
42
+ class None < Category
43
+ def capability
44
+ @capability ||= kind.to_s
45
+ end
40
46
  end
41
47
 
42
48
  class Test < Category
@@ -42,10 +42,6 @@ module Gitlab
42
42
  projects&.has_key?(name)
43
43
  end
44
44
 
45
- def any_capability?(project, category)
46
- capabilities(project).any? { |capability| capability.end_with?(category.to_s) }
47
- end
48
-
49
45
  def reviewer?(project, category, labels)
50
46
  has_capability?(project, category, :reviewer, labels)
51
47
  end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "3.6.4"
3
+ VERSION = "3.6.6"
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.4
4
+ version: 3.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-14 00:00:00.000000000 Z
11
+ date: 2023-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake