gitlab-dangerfiles 4.8.1 → 4.9.0

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: b42206a72b735d7a0016622666b37571d85d541a758d5454fbca3260e359f1f2
4
- data.tar.gz: ac570434fc3dee200d7656a557668454e2ceb5719c43d49b80c364688d3d0e13
3
+ metadata.gz: 98bba3bef6a0636a636a8b1e038baf11ac64f9b2139a7196990a093cd94c11e7
4
+ data.tar.gz: 6b65192e78b836b3efac843ea670560d2a169b3bd1135989bc968ce0fdc089a3
5
5
  SHA512:
6
- metadata.gz: '030678a153058f6c0ab3fdb198d109ca43b8693f763a6259585b2864c7d688faec108dbbe93285226a7b926ab6f99423b6b57d703f83004b588df27917582d22'
7
- data.tar.gz: 7a3398d6bc48bdbd28a43329c311088c211b6343e00200a782b0eef9503dae39befeaaa139710847d3a674e1032508b8c938ef889f7907d9739548919fa12c97
6
+ metadata.gz: 3f46e0a6ac334fe988c303bcb12b7bb58ecd2162fe5c5c3a8547b165e6037e535a4fa9308ec2503c421fdc3a09f8fd66d2702c79375585b99325d399bf65750f
7
+ data.tar.gz: d024b3cb5fc602e1811bb3692cd559119ae653827c06c9051c8e858f200c23f6a8f059193289d33d3e7e7d8f3ea247dee19fc9a20f96e66a0e8f1416bb29b9bf
data/.gitlab-ci.yml CHANGED
@@ -23,7 +23,7 @@ default:
23
23
  - vendor/ruby
24
24
 
25
25
  .default-test-job:
26
- image: "ruby:${RUBY_VERSION}"
26
+ image: "${GITLAB_DEPENDENCY_PROXY}ruby:${RUBY_VERSION}"
27
27
  stage: test
28
28
  needs: []
29
29
  before_script:
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-dangerfiles (4.8.1)
4
+ gitlab-dangerfiles (4.9.0)
5
5
  danger (>= 9.3.0)
6
6
  danger-gitlab (>= 8.0.0)
7
7
  rake (~> 13.0)
data/README.md CHANGED
@@ -171,6 +171,15 @@ This rule ensures the merge request isn't too big to be reviewed, otherwise it s
171
171
 
172
172
  This rule posts a failure if the merge request has more than 20 commits.
173
173
 
174
+ #### `danger_code_review`
175
+
176
+ This rule posts a warning/failure when `@GitLabDuo` isn't assigned as a reviewer.
177
+
178
+ ##### Available configurations
179
+
180
+ - `duo_code_review`: Whether a review from GitLab Duo Code is `:mandatory` or `:optional`.
181
+ Default to `:optional`.
182
+
174
183
  #### `metadata`
175
184
 
176
185
  This rule ensures basic metadata such as assignee, milestone and description are set on the merge request.
@@ -194,6 +203,16 @@ project. To use it in your project, perform the following steps:
194
203
  end
195
204
  ```
196
205
 
206
+ ##### Available configurations
207
+
208
+ Note: These options aren't actually used in the `simple_roulette` rule, but can be used in your own
209
+ implementation of the roulette if you use `roulette.required_approvals`/`roulette.codeowners_approvals`.
210
+
211
+ - `included_optional_codeowners_sections_for_roulette`: Indicates which optional codeowners sections
212
+ should be included in roulette. Default to `[]`.
213
+ - `excluded_required_codeowners_sections_for_roulette`: Indicates which required codeowners sections
214
+ should be excluded from roulette. Default to `[]`.
215
+
197
216
  #### `type_label`
198
217
 
199
218
  If the `changelog` plugin is available, it tries to infer a type label from the `Changelog` trailer of the MR.
@@ -281,6 +300,16 @@ To run the Danger Rake task in a project that doesn't have `master` as the defau
281
300
  DANGER_LOCAL_BASE="origin/main" bundle exec rake danger_local
282
301
  ```
283
302
 
303
+ ## Warnings vs Errors
304
+
305
+ The following lint violations generate warnings:
306
+
307
+ 1. The commit subject is too short ([code](https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/blob/bccb167/lib/gitlab/dangerfiles/base_linter.rb#L74-76)).
308
+ 1. The commit changes too many lines across too many files without describing the changes in the commit body ([code](https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/blob/bccb167/lib/gitlab/dangerfiles/commit_linter.rb#L83-85)).
309
+ 1. The commit body contains too many characters per line ([code](https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/blob/bccb167/lib/gitlab/dangerfiles/commit_linter.rb#L87-96)).
310
+
311
+ All other lint violations generate errors, except when the MR has [Squash commits when merge request is accepted](https://docs.gitlab.com/ee/user/project/merge_requests/squash_and_merge.html#squash-commits-in-a-merge-request) enabled, which downgrades lint violations to warnings.
312
+
284
313
  ## Documentation
285
314
 
286
315
  Latest documentation can be found at <https://www.rubydoc.info/gems/gitlab-dangerfiles>.
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Danger
4
+ # Contains method to check if Duo code suggestion added to MR as a reviewer.
5
+ class DuoCode < Danger::Plugin
6
+ def suggestion_added?
7
+ return false unless helper.ci?
8
+
9
+ helper.mr_reviewers.include?("GitLabDuo")
10
+ end
11
+ end
12
+ end
@@ -244,7 +244,7 @@ module Danger
244
244
  # @return [String] the GFM for a category label, making its best guess if it's not
245
245
  # a category we know about.
246
246
  def label_for_category(category)
247
- CATEGORY_LABELS[category] ||
247
+ helper.config.custom_labels_for_categories[category] || CATEGORY_LABELS[category] ||
248
248
 
249
249
  if category.start_with?("`")
250
250
  category.to_s
@@ -288,6 +288,13 @@ module Danger
288
288
  gitlab_helper.mr_json["assignees"]
289
289
  end
290
290
 
291
+ # @return [Array<Hash>] +[]+ when not in the CI context, and the MR reviewers otherwise.
292
+ def mr_reviewers
293
+ return [] unless ci?
294
+
295
+ gitlab_helper.mr_json["reviewers"]
296
+ end
297
+
291
298
  # @return [String] +""+ when not in the CI context, and the MR title otherwise.
292
299
  def mr_title
293
300
  return "" unless ci?
@@ -113,7 +113,7 @@ def warn_or_fail_commits(failed_linters, default_to_fail: true)
113
113
  Array(failed_linters).each do |linter|
114
114
  linter.problems.each do |problem_key, problem_desc|
115
115
  case problem_key
116
- when :subject_too_short, :subject_above_warning, :details_too_many_changes, :details_line_too_long
116
+ when :subject_too_short, :details_too_many_changes, :details_line_too_long
117
117
  warn_commit(linter.commit, problem_desc)
118
118
  else
119
119
  self.__send__(:"#{level}_commit", linter.commit, problem_desc)
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ return if duo_code.suggestion_added?
4
+
5
+ case helper.config.duo_code_review
6
+ when :optional
7
+ markdown("We advise getting a review from from GitLab Duo Code. You can assign `@GitLabDuo` as a reviewer to this merge request.")
8
+ when :mandatory
9
+ failure("A review from GitLab Duo Code is mandatory. Please assign `@GitLabDuo` as a reviewer to this merge request.")
10
+ end
@@ -21,22 +21,36 @@ module Gitlab
21
21
  # match changed lines in files that match +filename_regex+. Used in `helper.changes_by_category`, `helper.changes`, and `helper.categories_for_file`.
22
22
  attr_accessor :files_to_category
23
23
 
24
+ # @!attribute custom_labels_for_categories
25
+ # @return [{String => String}] A hash of the form +{ category_name => label }+.
26
+ # Used in `helper.custom_labels_for_categories`.
27
+ attr_accessor :custom_labels_for_categories
28
+
29
+ # @!attribute disabled_roulette_categories
30
+ # @return [Array] indicating which categories would be disabled for the simple roulette. Default to `[]` (all categories are enabled)
31
+ attr_accessor :disabled_roulette_categories
32
+
33
+ # Rule: changes_size
24
34
  # @!attribute code_size_thresholds
25
35
  # @return [{ high: Integer, medium: Integer }] a hash of the form +{ high: 42, medium: 12 }+ where +:high+ is the lines changed threshold which triggers an error, and +:medium+ is the lines changed threshold which triggers a warning. Also, see +DEFAULT_CHANGES_SIZE_THRESHOLDS+ for the format of the hash.
26
36
  attr_accessor :code_size_thresholds
27
37
 
38
+ # Rule: commit_messages
28
39
  # @!attribute max_commits_count
29
40
  # @return [Integer] the maximum number of allowed non-squashed/non-fixup commits for a given MR. A warning is triggered if the MR has more commits.
30
41
  attr_accessor :max_commits_count
31
42
 
32
- # @!attribute disabled_roulette_categories
33
- # @return [Array] indicating which categories would be disabled for the simple roulette. Default to `[]` (all categories are enabled)
34
- attr_accessor :disabled_roulette_categories
43
+ # Rule: duo_code_review
44
+ # @!attribute duo_code_review
45
+ # @return [Symbol] whether a review from GitLab Duo Code is `:mandatory` or `:optional`. Default to `:optional`.
46
+ attr_accessor :duo_code_review
35
47
 
48
+ # Rule: simple_roulette
36
49
  # @!attribute included_optional_codeowners_sections_for_roulette
37
50
  # @return [Array] indicating which optional codeowners sections should be included in roulette. Default to `[]`.
38
51
  attr_accessor :included_optional_codeowners_sections_for_roulette
39
52
 
53
+ # Rule: simple_roulette
40
54
  # @!attribute excluded_required_codeowners_sections_for_roulette
41
55
  # @return [Array] indicating which required codeowners sections should be excluded from roulette. Default to `[]`.
42
56
  attr_accessor :excluded_required_codeowners_sections_for_roulette
@@ -46,6 +60,7 @@ module Gitlab
46
60
 
47
61
  def initialize
48
62
  @files_to_category = {}
63
+ @custom_labels_for_categories = {}
49
64
  @project_root = nil
50
65
  @project_name = ENV["CI_PROJECT_NAME"]
51
66
  @ci_only_rules = []
@@ -54,6 +69,7 @@ module Gitlab
54
69
  @disabled_roulette_categories = []
55
70
  @included_optional_codeowners_sections_for_roulette = []
56
71
  @excluded_required_codeowners_sections_for_roulette = []
72
+ @duo_code_review = :optional
57
73
  end
58
74
  end
59
75
  end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "4.8.1"
3
+ VERSION = "4.9.0"
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: 4.8.1
4
+ version: 4.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: 2025-01-09 00:00:00.000000000 Z
11
+ date: 2025-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -225,12 +225,14 @@ files:
225
225
  - gitlab-dangerfiles.gemspec
226
226
  - lefthook.yml
227
227
  - lib/danger/plugins/changelog.rb
228
+ - lib/danger/plugins/duo_code.rb
228
229
  - lib/danger/plugins/internal/helper.rb
229
230
  - lib/danger/plugins/roulette.rb
230
231
  - lib/danger/rules/changelog/Dangerfile
231
232
  - lib/danger/rules/changes_size/Dangerfile
232
233
  - lib/danger/rules/commit_messages/Dangerfile
233
234
  - lib/danger/rules/commits_counter/Dangerfile
235
+ - lib/danger/rules/duo_code_review/Dangerfile
234
236
  - lib/danger/rules/metadata/Dangerfile
235
237
  - lib/danger/rules/simple_roulette/Dangerfile
236
238
  - lib/danger/rules/type_label/Dangerfile
@@ -282,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
284
  - !ruby/object:Gem::Version
283
285
  version: '0'
284
286
  requirements: []
285
- rubygems_version: 3.3.27
287
+ rubygems_version: 3.5.22
286
288
  signing_key:
287
289
  specification_version: 4
288
290
  summary: This gem provides common Dangerfile and plugins for GitLab projects.