gitlab-dangerfiles 3.7.0 → 3.8.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: fcee2fd2dd96522a7b1a5d1f906bc7fccfa28c9d6e9f61d6843c1fcd22dee884
4
+ data.tar.gz: c433e7fd8d3fd698c1eb71e5291f24a191ee2c4a86d376bae6f18b0735352f2a
5
5
  SHA512:
6
- metadata.gz: d86af6131e0703fcab736fb75f09b62d1e656bec379f76f8bee6223899e99b34a085c86dc94d7c6d99ce88642acbea4d9079050ab50331abbc10d6c47c0fcc76
7
- data.tar.gz: dc878dcd339bed44e0cb4059ec965cce1f6e0513099002126779640c3f8986417bbfabdbbec1ffd4137729839d682d8f7bc6f69cf1654ee03b9a75007f561f93
6
+ metadata.gz: c014e0cf3905380549a0f088c5685b7e1251643f5bbdd3e5362e4cf3c0ca0c0e4a1456599db66eabd3dad006547b70010716a2ab5b9aa2318e573ced7bd3680d
7
+ data.tar.gz: 0311fcec0f9cd30684470739798c5ab9c296d2c3cfb22d7e73a98f2c644b6db373edd752587a134199a366372b877bca4d3f198aed89f133483db45a2d5979e6
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
@@ -278,6 +278,13 @@ module Danger
278
278
  gitlab_helper.mr_author
279
279
  end
280
280
 
281
+ # @return [Array<Hash>] +[]+ when not in the CI context, and the MR assignees otherwise.
282
+ def mr_assignees
283
+ return [] unless ci?
284
+
285
+ gitlab_helper.mr_json["assignees"]
286
+ end
287
+
281
288
  # @return [String] +""+ when not in the CI context, and the MR title otherwise.
282
289
  def mr_title
283
290
  return "" unless ci?
@@ -285,6 +292,13 @@ module Danger
285
292
  gitlab_helper.mr_json["title"]
286
293
  end
287
294
 
295
+ # @return [String] +""+ when not in the CI context, and the MR description otherwise.
296
+ def mr_description
297
+ return "" unless ci?
298
+
299
+ gitlab_helper.mr_body
300
+ end
301
+
288
302
  # @return [String] +""+ when not in the CI context, and the MR URL otherwise.
289
303
  def mr_web_url
290
304
  return "" unless ci?
@@ -292,6 +306,13 @@ module Danger
292
306
  gitlab_helper.mr_json["web_url"]
293
307
  end
294
308
 
309
+ # @return [Hash, nil] +nil+ when not in the CI context, and the MR milestone otherwise.
310
+ def mr_milestone
311
+ return unless ci?
312
+
313
+ gitlab_helper.mr_json["milestone"]
314
+ end
315
+
295
316
  # @return [Array<String>] +[]+ when not in the CI context, and the MR labels otherwise.
296
317
  def mr_labels
297
318
  return [] unless ci?
@@ -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,11 @@
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?
8
+
9
+ default_branch = ENV['CI_DEFAULT_BRANCH'] || 'main'
10
+ has_pick_into_stable_label = helper.mr_labels.find { |label| label.start_with?('Pick into') }
11
+ warn("Most of the time, merge requests should target `#{default_branch}`. Otherwise, please set the relevant `Pick into X.Y` label.") if helper.mr_target_branch != default_branch && !has_pick_into_stable_label && !helper.security_mr?
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "3.7.0"
3
+ VERSION = "3.8.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.8.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-03-03 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