gitlab-dangerfiles 4.8.0 → 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 +4 -4
- data/.gitlab/CODEOWNERS +1 -1
- data/.gitlab-ci.yml +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +75 -0
- data/lib/danger/plugins/duo_code.rb +12 -0
- data/lib/danger/plugins/internal/helper.rb +10 -2
- data/lib/danger/rules/commit_messages/Dangerfile +1 -1
- data/lib/danger/rules/duo_code_review/Dangerfile +10 -0
- data/lib/gitlab/dangerfiles/config.rb +19 -3
- data/lib/gitlab/dangerfiles/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98bba3bef6a0636a636a8b1e038baf11ac64f9b2139a7196990a093cd94c11e7
|
4
|
+
data.tar.gz: 6b65192e78b836b3efac843ea670560d2a169b3bd1135989bc968ce0fdc089a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f46e0a6ac334fe988c303bcb12b7bb58ecd2162fe5c5c3a8547b165e6037e535a4fa9308ec2503c421fdc3a09f8fd66d2702c79375585b99325d399bf65750f
|
7
|
+
data.tar.gz: d024b3cb5fc602e1811bb3692cd559119ae653827c06c9051c8e858f200c23f6a8f059193289d33d3e7e7d8f3ea247dee19fc9a20f96e66a0e8f1416bb29b9bf
|
data/.gitlab/CODEOWNERS
CHANGED
@@ -1 +1 @@
|
|
1
|
-
* @gl-
|
1
|
+
* @gl-dx/eng-prod
|
data/.gitlab-ci.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -69,6 +69,52 @@ end
|
|
69
69
|
|
70
70
|
Note that your custom plugins and rules (unless you exclude them with `except`) are automatically imported by the gem.
|
71
71
|
|
72
|
+
### Import and load order
|
73
|
+
|
74
|
+
Plugins are imported in alphabetical order. Gem plugins are loaded before
|
75
|
+
project-local plugins.
|
76
|
+
|
77
|
+
Gem and project-local rules are combined, filtered, and loaded in alphabetical order.
|
78
|
+
|
79
|
+
Because all rules are executed as soon as they are imported, you should move all
|
80
|
+
logic from your root `Dangerfile` to project-local rules in
|
81
|
+
`danger/*/Dangerfile`.
|
82
|
+
|
83
|
+
For example:
|
84
|
+
|
85
|
+
**Bad**
|
86
|
+
|
87
|
+
`Dangerfile`:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
Gitlab::Dangerfiles.for_project(self) do |dangerfiles|
|
91
|
+
dangerfiles.import_dangerfiles(only: %w[z_add_labels])
|
92
|
+
end
|
93
|
+
|
94
|
+
# Bad, because gem rule `z_add_labels` has already been executed with empty labels list.
|
95
|
+
helper.labels_to_add << 'important'
|
96
|
+
```
|
97
|
+
|
98
|
+
**Good**
|
99
|
+
|
100
|
+
`Dangerfile`:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
Gitlab::Dangerfiles.for_project(self) do |dangerfiles|
|
104
|
+
dangerfiles.import_dangerfiles(only: %w[z_add_labels])
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
`danger/labels/Dangerfile`:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
# Good. Execution order:
|
112
|
+
# * root `Dangerfile`
|
113
|
+
# * project-local `danger/my_labels/Dangerfile`
|
114
|
+
# * gem rule `danger/z_add_labels/Dangerfile`
|
115
|
+
helper.labels_to_add << 'important'
|
116
|
+
```
|
117
|
+
|
72
118
|
### Plugins
|
73
119
|
|
74
120
|
Danger plugins are located under `lib/danger/plugins`.
|
@@ -125,6 +171,15 @@ This rule ensures the merge request isn't too big to be reviewed, otherwise it s
|
|
125
171
|
|
126
172
|
This rule posts a failure if the merge request has more than 20 commits.
|
127
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
|
+
|
128
183
|
#### `metadata`
|
129
184
|
|
130
185
|
This rule ensures basic metadata such as assignee, milestone and description are set on the merge request.
|
@@ -148,6 +203,16 @@ project. To use it in your project, perform the following steps:
|
|
148
203
|
end
|
149
204
|
```
|
150
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
|
+
|
151
216
|
#### `type_label`
|
152
217
|
|
153
218
|
If the `changelog` plugin is available, it tries to infer a type label from the `Changelog` trailer of the MR.
|
@@ -235,6 +300,16 @@ To run the Danger Rake task in a project that doesn't have `master` as the defau
|
|
235
300
|
DANGER_LOCAL_BASE="origin/main" bundle exec rake danger_local
|
236
301
|
```
|
237
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
|
+
|
238
313
|
## Documentation
|
239
314
|
|
240
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
|
@@ -29,7 +29,8 @@ module Danger
|
|
29
29
|
import_integrate_fe: '~"group::import and integrate" (frontend)',
|
30
30
|
Authentication: '~"group::authentication"',
|
31
31
|
Authorization: '~"group::authorization"',
|
32
|
-
Compliance: '~"group::compliance"'
|
32
|
+
Compliance: '~"group::compliance"',
|
33
|
+
Verify: '~"devops::verify"'
|
33
34
|
}.freeze
|
34
35
|
# rubocop:enable Style/HashSyntax
|
35
36
|
|
@@ -243,7 +244,7 @@ module Danger
|
|
243
244
|
# @return [String] the GFM for a category label, making its best guess if it's not
|
244
245
|
# a category we know about.
|
245
246
|
def label_for_category(category)
|
246
|
-
CATEGORY_LABELS[category] ||
|
247
|
+
helper.config.custom_labels_for_categories[category] || CATEGORY_LABELS[category] ||
|
247
248
|
|
248
249
|
if category.start_with?("`")
|
249
250
|
category.to_s
|
@@ -287,6 +288,13 @@ module Danger
|
|
287
288
|
gitlab_helper.mr_json["assignees"]
|
288
289
|
end
|
289
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
|
+
|
290
298
|
# @return [String] +""+ when not in the CI context, and the MR title otherwise.
|
291
299
|
def mr_title
|
292
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, :
|
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
|
-
#
|
33
|
-
#
|
34
|
-
|
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
|
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.
|
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:
|
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.
|
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.
|