gitlab-dangerfiles 3.6.7 → 3.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/README.md +11 -1
- data/lib/danger/plugins/changelog.rb +2 -2
- data/lib/danger/plugins/internal/helper.rb +21 -0
- data/lib/danger/rules/commits_counter/Dangerfile +28 -2
- data/lib/danger/rules/metadata/Dangerfile +11 -0
- data/lib/gitlab/dangerfiles/category.rb +36 -1
- data/lib/gitlab/dangerfiles/teammate.rb +3 -2
- data/lib/gitlab/dangerfiles/version.rb +1 -1
- data/lib/gitlab/dangerfiles.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcee2fd2dd96522a7b1a5d1f906bc7fccfa28c9d6e9f61d6843c1fcd22dee884
|
4
|
+
data.tar.gz: c433e7fd8d3fd698c1eb71e5291f24a191ee2c4a86d376bae6f18b0735352f2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c014e0cf3905380549a0f088c5685b7e1251643f5bbdd3e5362e4cf3c0ca0c0e4a1456599db66eabd3dad006547b70010716a2ab5b9aa2318e573ced7bd3680d
|
7
|
+
data.tar.gz: 0311fcec0f9cd30684470739798c5ab9c296d2c3cfb22d7e73a98f2c644b6db373edd752587a134199a366372b877bca4d3f198aed89f133483db45a2d5979e6
|
data/.rubocop.yml
CHANGED
@@ -38,6 +38,10 @@ Style/StringLiterals:
|
|
38
38
|
Style/TrailingCommaInHashLiteral:
|
39
39
|
EnforcedStyleForMultiline: consistent_comma
|
40
40
|
|
41
|
+
# To respect rufo formatting
|
42
|
+
Style/TrailingCommaInArguments:
|
43
|
+
Enabled: false
|
44
|
+
|
41
45
|
# To respect rufo formatting
|
42
46
|
Layout/MultilineOperationIndentation:
|
43
47
|
Enabled: false
|
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
|
|
@@ -134,10 +134,10 @@ module Danger
|
|
134
134
|
def critical_checks
|
135
135
|
check_result = ChangelogCheckResult.empty
|
136
136
|
|
137
|
-
check_result.
|
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
|
-
|
4
|
-
|
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?
|
@@ -92,11 +92,46 @@ module Gitlab
|
|
92
92
|
class UX < Category
|
93
93
|
private
|
94
94
|
|
95
|
+
def has_particular_capability?(teammate)
|
96
|
+
if labels.any?("Community contribution")
|
97
|
+
can_review_wider_community_contribution?(teammate)
|
98
|
+
else
|
99
|
+
super
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
95
103
|
def has_universal_capability?(teammate)
|
96
|
-
|
104
|
+
# No universal reviewer for community contribution.
|
105
|
+
# If we do, then picking from corresponding group won't be accurate.
|
106
|
+
# After solving the following issue, then we can revisit this:
|
107
|
+
# https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/issues/58
|
108
|
+
return false if labels.any?("Community contribution")
|
109
|
+
|
110
|
+
teammate.projects.each_value.any? do |capabilities|
|
97
111
|
capabilities.include?(capability)
|
98
112
|
end
|
99
113
|
end
|
114
|
+
|
115
|
+
def can_review_wider_community_contribution?(teammate)
|
116
|
+
# Pick corresponding group for community contribution
|
117
|
+
# Role can be:
|
118
|
+
# Product Designer, Create:Source Code
|
119
|
+
# Product Designer, Verify:Pipeline Insights, Verify:Runner
|
120
|
+
# Product Designer, Release
|
121
|
+
# Specialty can be:
|
122
|
+
# Source Code
|
123
|
+
# [Growth: Activation, Growth: Expansion]
|
124
|
+
# Runner
|
125
|
+
areas = teammate.role[/Product Designer(?:.*?, (.+))/, 1]&.split(",")
|
126
|
+
|
127
|
+
group_labels = [*teammate.specialty, *areas].map do |field|
|
128
|
+
group = field.strip.sub(/^.+: ?/, "").downcase
|
129
|
+
|
130
|
+
"group::#{group}"
|
131
|
+
end
|
132
|
+
|
133
|
+
(group_labels & labels).any?
|
134
|
+
end
|
100
135
|
end
|
101
136
|
end
|
102
137
|
end
|
@@ -5,10 +5,10 @@ require_relative "category"
|
|
5
5
|
module Gitlab
|
6
6
|
module Dangerfiles
|
7
7
|
class Teammate
|
8
|
-
attr_reader :options, :username, :name, :role, :projects, :available, :hungry, :reduced_capacity, :tz_offset_hours,
|
8
|
+
attr_reader :options, :username, :name, :role, :specialty, :projects, :available, :hungry, :reduced_capacity, :tz_offset_hours,
|
9
9
|
:only_maintainer_reviews
|
10
10
|
|
11
|
-
# The options data are produced by https://gitlab.com/gitlab-org/gitlab-roulette/-/blob/
|
11
|
+
# The options data are produced by https://gitlab.com/gitlab-org/gitlab-roulette/-/blob/main/lib/team_member.rb
|
12
12
|
def initialize(options = {})
|
13
13
|
@options = options
|
14
14
|
@username = options["username"]
|
@@ -16,6 +16,7 @@ module Gitlab
|
|
16
16
|
@markdown_name = options["markdown_name"] ||
|
17
17
|
default_markdown_name(*options.values_at("username", "name"))
|
18
18
|
@role = options["role"]
|
19
|
+
@specialty = options["specialty"]
|
19
20
|
@projects = process_projects(options["projects"])
|
20
21
|
@available = options["available"]
|
21
22
|
@hungry = options["hungry"]
|
data/lib/gitlab/dangerfiles.rb
CHANGED
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.
|
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-
|
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
|