gitlab-dangerfiles 4.8.1 → 4.9.1

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: 833ebf65ece50022cfe565242ddb8af684071fdd9abab0d24f94fdf3331b8c37
4
+ data.tar.gz: 10782785c698f9a32ff8f215cbdf1e8407ce5c85caf7f60faa69ff234748b635
5
5
  SHA512:
6
- metadata.gz: '030678a153058f6c0ab3fdb198d109ca43b8693f763a6259585b2864c7d688faec108dbbe93285226a7b926ab6f99423b6b57d703f83004b588df27917582d22'
7
- data.tar.gz: 7a3398d6bc48bdbd28a43329c311088c211b6343e00200a782b0eef9503dae39befeaaa139710847d3a674e1032508b8c938ef889f7907d9739548919fa12c97
6
+ metadata.gz: bb2ffba4936cdb33385fb88eec7958bc56b87cce7735c8fc59c79afdb73ccb88e0817cf567a63378612602ba54a2236b029a2059d831933ad72b2db4f4c9d17a
7
+ data.tar.gz: 22bffdd675c0254a09504a00dcb4fbc949f53f53f0b814e1b1accf500c7e571c022a866256ec60e0f666ffb401fd4a44650f3c88139e539e8ce59c434bc0d45d
@@ -2,7 +2,7 @@
2
2
  commit from this merge request, and `<NEW_VERSION>` with the upcoming version number. -->
3
3
  ## Diff
4
4
 
5
- https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/compare/v<PREVIOUS_VERSION>...<COMMIT_UPDATING_VERSION>
5
+ https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/compare/<PREVIOUS_VERSION>...<COMMIT_UPDATING_VERSION>
6
6
 
7
7
  ## Checklist
8
8
 
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.1)
5
5
  danger (>= 9.3.0)
6
6
  danger-gitlab (>= 8.0.0)
7
7
  rake (~> 13.0)
@@ -117,6 +117,7 @@ GEM
117
117
  parallel (1.22.1)
118
118
  parser (3.2.1.0)
119
119
  ast (~> 2.4.1)
120
+ racc
120
121
  proc_to_ast (0.1.0)
121
122
  coderay
122
123
  parser
@@ -125,6 +126,7 @@ GEM
125
126
  coderay (~> 1.1)
126
127
  method_source (~> 1.0)
127
128
  public_suffix (5.0.1)
129
+ racc (1.8.1)
128
130
  rack (3.0.4.1)
129
131
  rainbow (3.1.1)
130
132
  rake (13.0.6)
@@ -220,6 +222,7 @@ DEPENDENCIES
220
222
  gitlab-styles (~> 10.0)
221
223
  guard-rspec (~> 4.7.3)
222
224
  lefthook (~> 1.3)
225
+ racc (~> 1.8)
223
226
  rspec (~> 3.8)
224
227
  rspec-parameterized
225
228
  rubocop-rails (< 2.21.2)
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>.
@@ -307,8 +336,8 @@ For example, to test `gitlab-dangerfiles` changes from the `your-branch-name` br
307
336
 
308
337
  ```ruby
309
338
  group :development, :test, :danger do
310
- gem 'gitlab-dangerfiles', '~> 3.4.3', require: false,
311
- git: 'https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles.git',
339
+ gem 'gitlab-dangerfiles', require: false, feature_category: :tooling,
340
+ git: 'https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles.git', # rubocop:disable Cop/GemFetcher -- Testing unreleased changes
312
341
  ref: 'your-branch-name'
313
342
  end
314
343
  ```
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "lefthook", "~> 1.3"
38
38
  spec.add_development_dependency "rspec-parameterized"
39
39
  spec.add_development_dependency "rspec", "~> 3.8"
40
+ spec.add_development_dependency "racc", "~> 1.8"
40
41
  # we do not commit the bundle lockfile, so this temporary workaround needs to be
41
42
  # present until 2.21.3 or 2.22.x is released
42
43
  # See https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/issues/63
@@ -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?
@@ -45,7 +45,7 @@ module Danger
45
45
  # @param categories [Array<Symbol>] An array of categories symbols.
46
46
  #
47
47
  # @return [Array<Spin>]
48
- def spin(project = nil, categories = [:none], ux_fallback_wider_community_reviewer: teammate_pedroms)
48
+ def spin(project = nil, categories = [:none], ux_fallback_wider_community_reviewer: ux_fallback_reviewer)
49
49
  # TODO: Deprecate the project argument. It prevents us from
50
50
  # memorizing Spinner and can cause unexpected results if it's
51
51
  # passing a different project than the merge request project.
@@ -89,8 +89,9 @@ module Danger
89
89
 
90
90
  private
91
91
 
92
- def teammate_pedroms
93
- @teammate_pedroms ||= Gitlab::Dangerfiles::Teammate.find_member("pedroms")
92
+ def ux_fallback_reviewer
93
+ teammates = %w[pedroms annabeldunstone seggenberger jmiocene clavimoniere]
94
+ Gitlab::Dangerfiles::Teammate.find_member(teammates.sample)
94
95
  end
95
96
 
96
97
  def spin_for_approval_rule?(rule)
@@ -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
@@ -62,15 +62,13 @@ module Gitlab
62
62
 
63
63
  class ImportIntegrateBE < Capability
64
64
  def has_capability?(teammate)
65
- kind == :reviewer &&
66
- teammate.role.match?(/Backend Engineer.+Manage:Import and Integrate/)
65
+ kind == :reviewer && teammate.role.match?(/Backend Engineer.+:Import and Integrate/)
67
66
  end
68
67
  end
69
68
 
70
69
  class ImportIntegrateFE < Capability
71
70
  def has_capability?(teammate)
72
- kind == :reviewer &&
73
- teammate.role.match?(/Frontend Engineer.+Manage:Import and Integrate/)
71
+ kind == :reviewer && teammate.role.match?(/Frontend Engineer.+:Import and Integrate/)
74
72
  end
75
73
  end
76
74
 
@@ -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
@@ -168,8 +168,8 @@ RSpec.shared_context "with teammates" do
168
168
  let(:software_engineer_in_import_integrate_fe) do
169
169
  Gitlab::Dangerfiles::Teammate.new(
170
170
  "username" => "software-engineer-in-import-and-integrate-fe",
171
- "name" => "Software Engineer in Import and Integrate FE",
172
- "role" => "Frontend Engineer, Manage:Import and Integrate",
171
+ "name" => "Frontend Engineer in Import and Integrate",
172
+ "role" => "AnyRole Frontend Engineer, AnyStage:Import and Integrate",
173
173
  "projects" => { "gitlab" => "reviewer frontend" },
174
174
  "available" => true,
175
175
  "tz_offset_hours" => 2.0
@@ -179,8 +179,8 @@ RSpec.shared_context "with teammates" do
179
179
  let(:software_engineer_in_import_integrate_be) do
180
180
  Gitlab::Dangerfiles::Teammate.new(
181
181
  "username" => "software-engineer-in-import-and-integrate-be",
182
- "name" => "Software Engineer in Import and Integrate BE",
183
- "role" => "Backend Engineer, Manage:Import and Integrate",
182
+ "name" => "Backend Engineer in Import and Integrate",
183
+ "role" => "AnyRole Backend Engineer, AnyStage:Import and Integrate",
184
184
  "projects" => { "gitlab" => "reviewer backend" },
185
185
  "available" => true,
186
186
  "tz_offset_hours" => 2.0
@@ -224,7 +224,7 @@ RSpec.shared_context "with teammates" do
224
224
  Gitlab::Dangerfiles::Teammate.new(
225
225
  "username" => "import-and-integrate-backend-reviewer",
226
226
  "name" => "Import and Integrate BE engineer",
227
- "role" => "Backend Engineer, Manage:Import and Integrate",
227
+ "role" => "AnyRole Backend Engineer, AnyStage:Import and Integrate",
228
228
  "projects" => { "gitlab" => "reviewer backend" },
229
229
  "available" => backend_reviewer_available,
230
230
  "tz_offset_hours" => 2.0
@@ -235,7 +235,7 @@ RSpec.shared_context "with teammates" do
235
235
  Gitlab::Dangerfiles::Teammate.new(
236
236
  "username" => "import-and-integrate-frontend-reviewer",
237
237
  "name" => "Import and Integrate FE engineer",
238
- "role" => "Frontend Engineer, Manage:Import and Integrate",
238
+ "role" => "AnyRole Frontend Engineer, AnyStage:Import and Integrate",
239
239
  "projects" => { "gitlab" => "reviewer frontend" },
240
240
  "available" => true,
241
241
  "tz_offset_hours" => 2.0
@@ -285,7 +285,7 @@ RSpec.shared_context "with teammates" do
285
285
  end
286
286
 
287
287
  let(:teammate_json) { teammates.to_json }
288
- let(:teammate_pedroms) { instance_double(Gitlab::Dangerfiles::Teammate, name: "Pedro") }
288
+ let(:ux_fallback_reviewer) { instance_double(Gitlab::Dangerfiles::Teammate) }
289
289
  let(:company_members) { Gitlab::Dangerfiles::Teammate.fetch_company_members }
290
290
 
291
291
  before do
@@ -18,7 +18,7 @@ module Gitlab
18
18
  @team_author = team_author
19
19
  @labels = labels
20
20
  @categories = categories.reject do |category|
21
- import_and_integrate_reject_category?(category)
21
+ import_and_integrate_reject_category?(project, category, labels)
22
22
  end
23
23
  @random = random
24
24
  @ux_fallback_wider_community_reviewer = ux_fallback_wider_community_reviewer
@@ -98,12 +98,13 @@ module Gitlab
98
98
 
99
99
  attr_reader :random, :ux_fallback_wider_community_reviewer
100
100
 
101
+ # Reject Import and Integrate categories if the MR author has reviewing abilities for the category.
102
+ #
101
103
  # @param [String] category name
102
104
  # @return [Boolean]
103
- def import_and_integrate_reject_category?(category)
104
- # Reject Import and Integrate categories if the MR author has reviewing abilities for the category.
105
- team_author&.import_integrate_be?(project, category, labels) ||
106
- team_author&.import_integrate_fe?(project, category, labels)
105
+ def import_and_integrate_reject_category?(project, category, labels)
106
+ [:import_integrate_be, :import_integrate_fe].include?(category) && team_author &&
107
+ (team_author.reviewer?(project, category, labels) || team_author.maintainer?(project, category, labels))
107
108
  end
108
109
 
109
110
  # MR includes QA changes, but also other changes, and author isn't an SET
@@ -141,18 +141,6 @@ module Gitlab
141
141
  has_capability?(project, category, :maintainer, labels)
142
142
  end
143
143
 
144
- def import_integrate_be?(project, category, labels)
145
- return false unless category == :import_integrate_be
146
-
147
- has_capability?(project, category, :reviewer, labels)
148
- end
149
-
150
- def import_integrate_fe?(project, category, labels)
151
- return false unless category == :import_integrate_fe
152
-
153
- has_capability?(project, category, :reviewer, labels)
154
- end
155
-
156
144
  def markdown_name(author: nil)
157
145
  "#{@markdown_name}#{utc_offset_text(author)}"
158
146
  end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "4.8.1"
3
+ VERSION = "4.9.1"
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.1
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-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '3.8'
139
+ - !ruby/object:Gem::Dependency
140
+ name: racc
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.8'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.8'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rubocop-rails
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -225,12 +239,14 @@ files:
225
239
  - gitlab-dangerfiles.gemspec
226
240
  - lefthook.yml
227
241
  - lib/danger/plugins/changelog.rb
242
+ - lib/danger/plugins/duo_code.rb
228
243
  - lib/danger/plugins/internal/helper.rb
229
244
  - lib/danger/plugins/roulette.rb
230
245
  - lib/danger/rules/changelog/Dangerfile
231
246
  - lib/danger/rules/changes_size/Dangerfile
232
247
  - lib/danger/rules/commit_messages/Dangerfile
233
248
  - lib/danger/rules/commits_counter/Dangerfile
249
+ - lib/danger/rules/duo_code_review/Dangerfile
234
250
  - lib/danger/rules/metadata/Dangerfile
235
251
  - lib/danger/rules/simple_roulette/Dangerfile
236
252
  - lib/danger/rules/type_label/Dangerfile
@@ -282,7 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
298
  - !ruby/object:Gem::Version
283
299
  version: '0'
284
300
  requirements: []
285
- rubygems_version: 3.3.27
301
+ rubygems_version: 3.5.22
286
302
  signing_key:
287
303
  specification_version: 4
288
304
  summary: This gem provides common Dangerfile and plugins for GitLab projects.