gitlab-dangerfiles 3.7.0 → 3.9.0

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: 2c8b3755415a3a732fc13c70da4176927062a9d5b6452a7d2513d3ef29617c89
4
- data.tar.gz: 1822e18dcc9e51d93f0ea1f3df574aaf5c1dd5ec1b0fd552bfea34f8b114971d
3
+ metadata.gz: 5759d8762183090115e7cb10b4b2d7244735d3225b53966c8feaf28e9d9eee7e
4
+ data.tar.gz: f49d06c663430072bad4c4f05b8bd1f509ca2c1a095bd1e499e3870fbe061fc9
5
5
  SHA512:
6
- metadata.gz: d86af6131e0703fcab736fb75f09b62d1e656bec379f76f8bee6223899e99b34a085c86dc94d7c6d99ce88642acbea4d9079050ab50331abbc10d6c47c0fcc76
7
- data.tar.gz: dc878dcd339bed44e0cb4059ec965cce1f6e0513099002126779640c3f8986417bbfabdbbec1ffd4137729839d682d8f7bc6f69cf1654ee03b9a75007f561f93
6
+ metadata.gz: 3cd96f3ceb33c2a028f62b1f72a16196ee1afa3768f0463783262ce3a4bd1d98d85e9ab905a916c0ad27cf7bfaf2c16608c5d533e07c30b6463807122d711f09
7
+ data.tar.gz: 253aa1b4a8a31c2c323ff05fbad3e2f613b932c82a5f1d61505e92966c1bfe7c593d17bae094f6ebd59b5568433d93d83e443b16df7c75d1b257d1015834a405
data/README.md CHANGED
@@ -106,6 +106,8 @@ This rule ensures the merge request follows our [Changelog guidelines](https://d
106
106
 
107
107
  #### `changes_size`
108
108
 
109
+ This rule ensures the merge request isn't too big to be reviewed, otherwise it suggests to split the MR.
110
+
109
111
  ##### Available configurations
110
112
 
111
113
  - `code_size_thresholds`: A hash of the form `{ high: 42, medium: 12 }` where
@@ -119,6 +121,14 @@ This rule ensures the merge request follows our [Changelog guidelines](https://d
119
121
  - `max_commits_count`: The maximum number of allowed non-squashed/non-fixup commits for a given MR.
120
122
  A warning is triggered if the MR has more commits.
121
123
 
124
+ #### `commits_counter`
125
+
126
+ This rule posts a failure if the merge request has more than 20 commits.
127
+
128
+ #### `metadata`
129
+
130
+ This rule ensures basic metadata such as assignee, milestone and description are set on the merge request.
131
+
122
132
  #### `simple_roulette`
123
133
 
124
134
  The library includes a simplified default reviewer roulette that you can use in your
@@ -230,7 +240,7 @@ Latest documentation can be found at <https://www.rubydoc.info/gems/gitlab-dange
230
240
 
231
241
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
232
242
 
233
- To install this gem onto your local machine, run `bundle exec rake install`.
243
+ To install this gem onto your local machine, run `bundle exec rake install`.
234
244
 
235
245
  ### Activate lefthook locally
236
246
 
@@ -137,7 +137,7 @@ module Danger
137
137
  check_result.warning(modified_text) if git.modified_files.include?("CHANGELOG.md")
138
138
 
139
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?
140
+ check_result.warning(IF_REVERT_MR_TEXT) if helper.revert_mr? && !helper.stable_branch?
141
141
 
142
142
  add_danger_messages(check_result)
143
143
  end
@@ -26,8 +26,8 @@ module Danger
26
26
  tooling: '~"maintenance::workflow" / ~"maintenance::pipelines" for CI, Danger',
27
27
  ci_template: '~"ci::templates"',
28
28
  product_intelligence: '~"product intelligence"',
29
- integrations_be: '~"group::integrations" (backend)',
30
- integrations_fe: '~"group::integrations" (frontend)',
29
+ import_integrate_be: '~"group::import and integrate" (backend)',
30
+ import_integrate_fe: '~"group::import and integrate" (frontend)',
31
31
  "Authentication and Authorization": '~"group::authentication and authorization"',
32
32
  Compliance: '~"group::compliance"',
33
33
  }.freeze
@@ -35,6 +35,8 @@ module Danger
35
35
 
36
36
  GITLAB_ORG_GROUP_ID = "9970"
37
37
 
38
+ STABLE_BRANCH_REGEX = %r{\A(?<version>\d+-\d+)-stable-ee\z}
39
+
38
40
  # Allows to set specific rule's configuration by passing a block.
39
41
  #
40
42
  # @yield [c] Yield a Gitlab::Dangerfiles::Config object
@@ -278,6 +280,13 @@ module Danger
278
280
  gitlab_helper.mr_author
279
281
  end
280
282
 
283
+ # @return [Array<Hash>] +[]+ when not in the CI context, and the MR assignees otherwise.
284
+ def mr_assignees
285
+ return [] unless ci?
286
+
287
+ gitlab_helper.mr_json["assignees"]
288
+ end
289
+
281
290
  # @return [String] +""+ when not in the CI context, and the MR title otherwise.
282
291
  def mr_title
283
292
  return "" unless ci?
@@ -285,6 +294,13 @@ module Danger
285
294
  gitlab_helper.mr_json["title"]
286
295
  end
287
296
 
297
+ # @return [String] +""+ when not in the CI context, and the MR description otherwise.
298
+ def mr_description
299
+ return "" unless ci?
300
+
301
+ gitlab_helper.mr_body
302
+ end
303
+
288
304
  # @return [String] +""+ when not in the CI context, and the MR URL otherwise.
289
305
  def mr_web_url
290
306
  return "" unless ci?
@@ -292,6 +308,13 @@ module Danger
292
308
  gitlab_helper.mr_json["web_url"]
293
309
  end
294
310
 
311
+ # @return [Hash, nil] +nil+ when not in the CI context, and the MR milestone otherwise.
312
+ def mr_milestone
313
+ return unless ci?
314
+
315
+ gitlab_helper.mr_json["milestone"]
316
+ end
317
+
295
318
  # @return [Array<String>] +[]+ when not in the CI context, and the MR labels otherwise.
296
319
  def mr_labels
297
320
  return [] unless ci?
@@ -348,6 +371,10 @@ module Danger
348
371
  mr_web_url.include?("/gitlab-org/security/")
349
372
  end
350
373
 
374
+ def stable_branch_mr?
375
+ !!mr_target_branch.match(STABLE_BRANCH_REGEX) && !security_mr?
376
+ end
377
+
351
378
  # @return [Boolean] whether a MR title includes "cherry-pick" or not.
352
379
  def cherry_pick_mr?
353
380
  Gitlab::Dangerfiles::TitleLinting.has_cherry_pick_flag?(mr_title)
@@ -428,11 +455,16 @@ module Danger
428
455
  all_changed_files.grep(regex)
429
456
  end
430
457
 
431
- # @return [Array<String>] the group labels (i.e. +"group::*"+) set on the MR.
458
+ # @return [String] the group label (i.e. +"group::*"+) set on the MR.
432
459
  def group_label
433
460
  mr_labels.find { |label| label.start_with?("group::") }
434
461
  end
435
462
 
463
+ # @return [String] the stage label (i.e. +"devops::*"+) set on the MR.
464
+ def stage_label
465
+ mr_labels.find { |label| label.start_with?("devops::") }
466
+ end
467
+
436
468
  # Accessor for storing labels to add so that other rules can check if labels will be added after Danger
437
469
  # has evaluated all the rules.
438
470
  # For instance, a rule might require a specific label to be set, but another rule could add this label
@@ -52,7 +52,7 @@ module Danger
52
52
  def spin(project = nil, categories = [:none], timezone_experiment: false)
53
53
  project = (project || config_project_name).downcase
54
54
  categories = categories.map { |category| category&.downcase || :none }
55
- categories.reject! { |category| integrations_reject_category?(category, project) }
55
+ categories.reject! { |category| import_and_integrate_reject_category?(category, project) }
56
56
 
57
57
  spins = categories.sort_by(&:to_s).map do |category|
58
58
  including_timezone = INCLUDE_TIMEZONE_FOR_CATEGORY.fetch(category, timezone_experiment)
@@ -96,7 +96,7 @@ module Danger
96
96
  # Fetch an already picked maintainer, or pick one otherwise
97
97
  spin.maintainer = backend_spin&.maintainer || frontend_spin&.maintainer || spin_for_category(project, :backend, timezone_experiment: including_timezone).maintainer
98
98
  end
99
- when :integrations_be, :integrations_fe
99
+ when :import_integrate_be, :import_integrate_fe
100
100
  spin.optional_role = :maintainer
101
101
  when :ux
102
102
  spin.optional_role = :maintainer
@@ -173,10 +173,10 @@ module Danger
173
173
 
174
174
  # @param [String] category name
175
175
  # @return [Boolean]
176
- def integrations_reject_category?(category, project)
177
- # Reject integrations categories if the MR author has reviewing abilities for the category.
178
- team_mr_author&.integrations_be?(project, category, helper.mr_labels) ||
179
- team_mr_author&.integrations_fe?(project, category, helper.mr_labels)
176
+ def import_and_integrate_reject_category?(category, project)
177
+ # Reject Import and Integrate categories if the MR author has reviewing abilities for the category.
178
+ team_mr_author&.import_integrate_be?(project, category, helper.mr_labels) ||
179
+ team_mr_author&.import_integrate_fe?(project, category, helper.mr_labels)
180
180
  end
181
181
 
182
182
  def random
@@ -267,12 +267,17 @@ module Danger
267
267
  rsp = Net::HTTP.get_response(URI.parse(url))
268
268
 
269
269
  if rsp.is_a?(Net::HTTPRedirection)
270
- warnings << "Redirection detected. Stopping."
270
+ if (uri = URI.parse(rsp.header["location"]))
271
+ uri.query = nil
272
+ end
273
+
274
+ warnings << "Redirection detected: #{uri}."
271
275
  return nil
272
276
  end
273
277
 
274
278
  unless rsp.is_a?(Net::HTTPOK)
275
- warnings << "HTTPError: Failed to read #{url}: #{rsp.code}."
279
+ message = rsp.message[0, 30]
280
+ warnings << "HTTPError: Failed to read #{url}: #{rsp.code} #{message}."
276
281
  return nil
277
282
  end
278
283
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ return if helper.stable_branch_mr?
4
+
3
5
  thresholds = helper.config.code_size_thresholds
4
6
  lines_changed = git.lines_of_code
5
7
 
@@ -1,5 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if git.commits.size > 20
4
- failure 'This MR has more than 20 commits. You need to rebase this branch to have fewer commits.'
3
+ gitlab_org_gitlab_project_id = 278964
4
+
5
+ return if git.commits.size <= 20
6
+
7
+ general_message = 'This merge request has more than 20 commits which may cause issues in some of the jobs. If you see errors like missing commits'
8
+
9
+ warning_message = "#{general_message}, please consider squashing some commits so it is within 20 commits."
10
+
11
+ failure_message = "#{general_message}, please enable squashing and consider squashing yourself as well."
12
+
13
+ # GitLab the project has quite some jobs relying on having less than 20
14
+ # commits due to GIT_DEPTH being set to 20. Those jobs require accessing to
15
+ # all the commits within the merge request thus it cannot have more than that.
16
+ # We also have a higher commit history standard for a larger project like that
17
+ # See also:
18
+ #
19
+ # https://gitlab.com/gitlab-org/gitlab/-/issues/358125
20
+ # https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/issues/49
21
+ if helper.mr_target_project_id == gitlab_org_gitlab_project_id
22
+ details = "See [comments in the file](https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/blob/master/lib/danger/rules/commits_counter/Dangerfile) implementing this for more details."
23
+
24
+ if helper.squash_mr?
25
+ warn "#{warning_message} #{details}"
26
+ else
27
+ failure "#{failure_message} #{details}"
28
+ end
29
+ else
30
+ warn warning_message
5
31
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ fail("Merge request description is too short. Please provide a proper merge request description.") if helper.mr_description.size < 5 # rubocop:disable Style/SignalException:
4
+
5
+ warn("This merge request does not have any assignee yet. Setting an assignee clarifies who needs to take action on the merge request at any given time.") if helper.mr_assignees.empty?
6
+
7
+ warn("This merge request does not refer to an existing milestone.", sticky: false) if helper.mr_milestone.nil?
@@ -14,8 +14,8 @@ module Gitlab
14
14
  none: None,
15
15
  test: Test,
16
16
  tooling: Tooling,
17
- integrations_be: IntegrationsBE,
18
- integrations_fe: IntegrationsFE,
17
+ import_integrate_be: ImportIntegrateBE,
18
+ import_integrate_fe: ImportIntegrateFE,
19
19
  ux: UX,
20
20
  }.freeze
21
21
  end
@@ -71,7 +71,7 @@ module Gitlab
71
71
  end
72
72
  end
73
73
 
74
- class IntegrationsBE < Category
74
+ class ImportIntegrateBE < Category
75
75
  private
76
76
 
77
77
  def has_particular_capability?(teammate)
@@ -80,7 +80,7 @@ module Gitlab
80
80
  end
81
81
  end
82
82
 
83
- class IntegrationsFE < Category
83
+ class ImportIntegrateFE < Category
84
84
  private
85
85
 
86
86
  def has_particular_capability?(teammate)
@@ -55,14 +55,14 @@ module Gitlab
55
55
  has_capability?(project, category, :maintainer, labels)
56
56
  end
57
57
 
58
- def integrations_be?(project, category, labels)
59
- return false unless category == :integrations_be
58
+ def import_integrate_be?(project, category, labels)
59
+ return false unless category == :import_integrate_be
60
60
 
61
61
  has_capability?(project, category, :reviewer, labels)
62
62
  end
63
63
 
64
- def integrations_fe?(project, category, labels)
65
- return false unless category == :integrations_fe
64
+ def import_integrate_fe?(project, category, labels)
65
+ return false unless category == :import_integrate_fe
66
66
 
67
67
  has_capability?(project, category, :reviewer, labels)
68
68
  end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "3.7.0"
3
+ VERSION = "3.9.0"
4
4
  end
5
5
  end
@@ -5,6 +5,7 @@ module Gitlab
5
5
  module Dangerfiles
6
6
  RULES_DIR = File.expand_path("../danger/rules", __dir__)
7
7
  CI_ONLY_RULES = %w[
8
+ metadata
8
9
  simple_roulette
9
10
  type_label
10
11
  subtype_label
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.7.0
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-15 00:00:00.000000000 Z
11
+ date: 2023-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -174,6 +174,7 @@ files:
174
174
  - lib/danger/rules/changes_size/Dangerfile
175
175
  - lib/danger/rules/commit_messages/Dangerfile
176
176
  - lib/danger/rules/commits_counter/Dangerfile
177
+ - lib/danger/rules/metadata/Dangerfile
177
178
  - lib/danger/rules/simple_roulette/Dangerfile
178
179
  - lib/danger/rules/subtype_label/Dangerfile
179
180
  - lib/danger/rules/type_label/Dangerfile