gitlab-dangerfiles 3.4.3 → 3.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +0 -5
- data/.gitpod.yml +2 -0
- data/README.md +46 -3
- data/lib/danger/plugins/internal/helper.rb +1 -1
- data/lib/danger/plugins/roulette.rb +51 -11
- data/lib/danger/rules/commit_messages/Dangerfile +2 -2
- data/lib/danger/rules/subtype_label/Dangerfile +14 -0
- data/lib/danger/rules/type_label/Dangerfile +4 -4
- data/lib/gitlab/dangerfiles/teammate.rb +3 -3
- data/lib/gitlab/dangerfiles/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7263e8c2ab6ba97b10b3cddc96ff91061cd526aa90992a7bd2df469b37e5e217
|
4
|
+
data.tar.gz: e9b2cabb3d6819af138c2080dbca5658f404e6d7f8a71e7f51944bc32e350fde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e28612c099a81ec122a31d475880f121833741375bab94004ee647cb6ae467b074b53c07156ad4a25f361b72e9cfc54bc157b8f64ac8cc42ce4ac0b631efa229
|
7
|
+
data.tar.gz: a37e350cfc9bcb13277801fa72a9a7c5a92028004e02293c34a0c69b03e3d51d6a8359480bb9a716fc5ac27f2b17ae6375dcfe239217f66eab14411949f50c0c
|
data/.gitlab-ci.yml
CHANGED
@@ -63,11 +63,6 @@ gemnasium-dependency_scanning:
|
|
63
63
|
- if: '$CI_MERGE_REQUEST_IID'
|
64
64
|
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
65
65
|
|
66
|
-
bundler-audit-dependency_scanning:
|
67
|
-
rules:
|
68
|
-
- if: '$CI_MERGE_REQUEST_IID'
|
69
|
-
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
|
70
|
-
|
71
66
|
license_scanning:
|
72
67
|
rules:
|
73
68
|
- if: '$CI_MERGE_REQUEST_IID'
|
data/.gitpod.yml
ADDED
data/README.md
CHANGED
@@ -133,11 +133,17 @@ project. To use it in your project, perform the following steps:
|
|
133
133
|
end
|
134
134
|
```
|
135
135
|
|
136
|
+
#### `subtype_label`
|
137
|
+
|
138
|
+
This rule warns when the merge request is missing a [subtype label](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification).
|
139
|
+
|
140
|
+
If the `DANGER_ERROR_WHEN_SUBTYPE_LABEL_IS_MISSING` environment variable evaluates to `true`, Danger will error instead of warning when a subtype label is missing.
|
141
|
+
|
136
142
|
#### `type_label`
|
137
143
|
|
138
144
|
This rule warns when the merge request is missing a [type label](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification).
|
139
145
|
|
140
|
-
If the `DANGER_ERROR_WHEN_TYPE_LABEL_IS_MISSING` environment variable evaluates to `true`, Danger will error when a type label is missing.
|
146
|
+
If the `DANGER_ERROR_WHEN_TYPE_LABEL_IS_MISSING` environment variable evaluates to `true`, Danger will error instead of warning when a type label is missing.
|
141
147
|
|
142
148
|
If the `changelog` plugin is available, it also tries to infer a type label from the `Changelog` trailer of the MR.
|
143
149
|
|
@@ -221,13 +227,50 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
221
227
|
|
222
228
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
223
229
|
|
224
|
-
To release a new version, update the version number in `version.rb`, and get the MR merged by a maintainer. This will be then be packaged into a gem and pushed to [rubygems.org](https://rubygems.org) by the CI/CD.
|
225
|
-
|
226
230
|
### Activate lefthook locally
|
227
231
|
|
228
232
|
```shell
|
229
233
|
lefthook install
|
230
234
|
```
|
235
|
+
|
236
|
+
### Testing unreleased changes in merge requests
|
237
|
+
|
238
|
+
To test an unreleased change in an actual merge request, you can create a merge request that will install the unreleased version of `gitlab-dangerfiles`. Bundler can install gems by specifying a repository and a revision from Git.
|
239
|
+
|
240
|
+
For example, to test `gitlab-dangerfiles` changes from the `your-branch-name` branch in [`gitlab-org/gitlab`](https://gitlab.com/gitlab-org/gitlab), in the `Gemfile`:
|
241
|
+
|
242
|
+
```ruby
|
243
|
+
group :development, :test, :danger do
|
244
|
+
gem 'gitlab-dangerfiles', '~> 3.4.3', require: false,
|
245
|
+
git: 'https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles.git',
|
246
|
+
ref: 'your-branch-name'
|
247
|
+
end
|
248
|
+
```
|
249
|
+
|
250
|
+
See an [example](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/92580) for more details.
|
251
|
+
|
252
|
+
## Release
|
253
|
+
|
254
|
+
[Automated gem release process](https://gitlab.com/gitlab-org/quality/pipeline-common#release-process) is used to release new version of `gitlab-dangerfiles` through [pipelines](https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/blob/4f33cf30cab84f7e27ca0cb9a7c0da3ecc675c11/.gitlab-ci.yml#L51), and this will:
|
255
|
+
|
256
|
+
- Publish the gem: https://rubygems.org/gems/gitlab-dangerfiles
|
257
|
+
- Add a release in the `gitlab-dangerfiles` project: https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/releases
|
258
|
+
- Populate the release log with the API contents. For example: https://gitlab.com/api/v4/projects/19861191/repository/changelog?version=3.4.4
|
259
|
+
|
260
|
+
### Before release
|
261
|
+
|
262
|
+
Make sure to include a changelog entry in your commit message and read the [changelog entries section](https://docs.gitlab.com/ee/development/changelog.html).
|
263
|
+
|
264
|
+
If you forget to set the changelog entry in your commit messages, you can also edit the release notes after it's being released.
|
265
|
+
|
266
|
+
### Steps to release
|
267
|
+
|
268
|
+
Use a `Release` merge request template and create a merge requet to update the version number in `version.rb`, and get the merge request merged by a maintainer.
|
269
|
+
|
270
|
+
This will then be packaged into a gem and pushed to [rubygems.org](https://rubygems.org) by the CI/CD.
|
271
|
+
|
272
|
+
For example: [Bump version to 3.4.3](https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/-/merge_requests/149).
|
273
|
+
|
231
274
|
## Contributing
|
232
275
|
|
233
276
|
Bug reports and merge requests are welcome at https://gitlab.com/gitlab-org/gitlab-dangerfiles. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://gitlab.com/gitlab-org/gitlab-dangerfiles/blob/master/CODE_OF_CONDUCT.md).
|
@@ -234,7 +234,7 @@ module Danger
|
|
234
234
|
# @return [String] the GFM for a category label, making its best guess if it's not
|
235
235
|
# a category we know about.
|
236
236
|
def label_for_category(category)
|
237
|
-
CATEGORY_LABELS.fetch(category, "
|
237
|
+
CATEGORY_LABELS.fetch(category, %Q{~"#{category}"})
|
238
238
|
end
|
239
239
|
|
240
240
|
# @return [String] +""+ when not in the CI context, and the MR Source Project ID as a string otherwise.
|
@@ -43,7 +43,7 @@ module Danger
|
|
43
43
|
#
|
44
44
|
# @return [Array<Spin>]
|
45
45
|
def spin(project = nil, categories = [nil], timezone_experiment: false)
|
46
|
-
project = (project ||
|
46
|
+
project = (project || config_project_name).downcase
|
47
47
|
categories = categories.map { |category| category&.downcase }
|
48
48
|
categories.reject! { |category| integrations_reject_category?(category, project) }
|
49
49
|
|
@@ -90,6 +90,8 @@ module Danger
|
|
90
90
|
end
|
91
91
|
when :integrations_be, :integrations_fe
|
92
92
|
spin.optional_role = :maintainer
|
93
|
+
when :ux
|
94
|
+
spin.optional_role = :maintainer
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
@@ -101,15 +103,42 @@ module Danger
|
|
101
103
|
|
102
104
|
return [] unless approval_rules
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
-
|
106
|
+
required_approval_rules = unique_approval_rules(approval_rules)
|
107
|
+
required_approval_rules.filter_map do |rule|
|
108
|
+
spin_for_approval_rule?(rule) &&
|
107
109
|
Approval.from_approval_rule(rule, spin_for_approver(rule))
|
108
110
|
end
|
109
111
|
end
|
110
112
|
|
111
113
|
private
|
112
114
|
|
115
|
+
def spin_for_approval_rule?(rule)
|
116
|
+
rule["rule_type"] == "code_owner" &&
|
117
|
+
rule["approvals_required"] > 0 &&
|
118
|
+
# Exclude generic codeowners rule, which should be covered by others already
|
119
|
+
!generic_codeowners_rule?(rule)
|
120
|
+
end
|
121
|
+
|
122
|
+
def generic_codeowners_rule?(rule)
|
123
|
+
rule["section"] == "codeowners" && rule["name"] == "*"
|
124
|
+
end
|
125
|
+
|
126
|
+
# Returns an array containing all unique approval rules, based on on the section and eligible_approvers of the rules
|
127
|
+
#
|
128
|
+
# @param [Array<Hash>] approval rules
|
129
|
+
# @return [Array<Hash>]
|
130
|
+
def unique_approval_rules(approval_rules)
|
131
|
+
approval_rules.uniq do |rule|
|
132
|
+
section = rule["section"]
|
133
|
+
|
134
|
+
approvers = rule["eligible_approvers"].map do |approver|
|
135
|
+
approver["username"]
|
136
|
+
end
|
137
|
+
|
138
|
+
[section, approvers]
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
113
142
|
# @param [Gitlab::Dangerfiles::Teammate] person
|
114
143
|
# @return [Boolean]
|
115
144
|
def valid_person?(person)
|
@@ -168,11 +197,8 @@ module Danger
|
|
168
197
|
#
|
169
198
|
# @return [Gitlab::Dangerfiles::Teammate]
|
170
199
|
def spin_for_approver(rule)
|
171
|
-
# This will filter out approvers who are not even reviewers who
|
172
|
-
# don't show up in roulette data we're relying on.
|
173
|
-
# That's why `filter_map` is used.
|
174
200
|
approvers = rule["eligible_approvers"].filter_map do |approver|
|
175
|
-
find_member(approver["username"])
|
201
|
+
find_member(approver["username"], project: config_project_name.downcase)
|
176
202
|
end
|
177
203
|
|
178
204
|
spin_for_person(approvers) || spin_for_approver_fallback(rule)
|
@@ -250,8 +276,22 @@ module Danger
|
|
250
276
|
end
|
251
277
|
end
|
252
278
|
|
253
|
-
def find_member(username)
|
254
|
-
company_members.find
|
279
|
+
def find_member(username, project: nil)
|
280
|
+
company_members.find do |member|
|
281
|
+
member.username == username &&
|
282
|
+
if project
|
283
|
+
member.in_project?(project)
|
284
|
+
else
|
285
|
+
true
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
# Return the configured project name
|
291
|
+
#
|
292
|
+
# @return [String]
|
293
|
+
def config_project_name
|
294
|
+
helper.config.project_name
|
255
295
|
end
|
256
296
|
|
257
297
|
# Like +team+, but only returns teammates in the current project, based on
|
@@ -261,7 +301,7 @@ module Danger
|
|
261
301
|
def project_team(project_name)
|
262
302
|
company_members.select do |member|
|
263
303
|
member.in_project?(project_name) ||
|
264
|
-
member.in_project?("gitlab") # Used for
|
304
|
+
member.in_project?("gitlab") # Used for universal reviewer
|
265
305
|
end
|
266
306
|
rescue => err
|
267
307
|
warn("Reviewer roulette failed to load team data: #{err.message}")
|
@@ -54,7 +54,7 @@ def lint_commit(commit)
|
|
54
54
|
return linter if linter.fixup? && helper.squash_mr?
|
55
55
|
|
56
56
|
if linter.fixup?
|
57
|
-
msg = "Squash or fixup commits must be squashed before merge, or enable
|
57
|
+
msg = "Squash or fixup commits must be squashed before merge, or **edit** the merge request, enable **Squash commits when merge request is accepted** and re-run #{danger_job_link}."
|
58
58
|
if helper.draft_mr? || helper.squash_mr?
|
59
59
|
warn_commit(commit, msg, more_info: false)
|
60
60
|
else
|
@@ -68,7 +68,7 @@ def lint_commit(commit)
|
|
68
68
|
# Fail if a suggestion commit is used and squash is not enabled
|
69
69
|
if linter.suggestion?
|
70
70
|
unless helper.squash_mr?
|
71
|
-
fail_commit(commit, "If you are applying suggestions, enable
|
71
|
+
fail_commit(commit, "If you are applying suggestions, **edit** the merge request, enable **Squash commits when merge request is accepted** and re-run #{danger_job_link}.", more_info: false)
|
72
72
|
end
|
73
73
|
|
74
74
|
return linter
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
SUBTYPE_LABEL_MISSING_MESSAGE = "Please add a [merge request subtype](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification) to this merge request."
|
4
|
+
|
5
|
+
types = %w(bug feature maintenance)
|
6
|
+
types.each do |type|
|
7
|
+
return if helper.has_scoped_label_with_scope?(type)
|
8
|
+
end
|
9
|
+
|
10
|
+
if ENV['DANGER_ERROR_WHEN_SUBTYPE_LABEL_IS_MISSING'] == 'true'
|
11
|
+
fail SUBTYPE_LABEL_MISSING_MESSAGE
|
12
|
+
else
|
13
|
+
warn SUBTYPE_LABEL_MISSING_MESSAGE
|
14
|
+
end
|
@@ -4,14 +4,14 @@ TYPE_LABEL_MISSING_MESSAGE = "Please add a [merge request type](https://about.gi
|
|
4
4
|
|
5
5
|
require_relative "../../../gitlab/dangerfiles/type_label_guesser"
|
6
6
|
|
7
|
-
if
|
7
|
+
return if helper.has_scoped_label_with_scope?("type")
|
8
|
+
|
9
|
+
if respond_to?(:changelog)
|
8
10
|
type_label_guesser = Gitlab::Dangerfiles::TypeLabelGuesser.new
|
9
11
|
helper.labels_to_add.concat(type_label_guesser.labels_from_changelog_categories(changelog.categories))
|
10
12
|
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
if ENV["DANGER_ERROR_WHEN_TYPE_LABEL_IS_MISSING"]
|
14
|
+
if ENV['DANGER_ERROR_WHEN_TYPE_LABEL_IS_MISSING'] == 'true'
|
15
15
|
fail TYPE_LABEL_MISSING_MESSAGE
|
16
16
|
else
|
17
17
|
warn TYPE_LABEL_MISSING_MESSAGE
|
@@ -130,7 +130,7 @@ module Gitlab
|
|
130
130
|
area && labels.any?("devops::#{area.downcase}") if kind == :reviewer
|
131
131
|
when :tooling, :engineering_productivity # Deprecated as of 2.3.0 in favor of tooling
|
132
132
|
return true if capabilities(project).include?("#{kind} #{category}")
|
133
|
-
return false if
|
133
|
+
return false if %i[trainee_maintainer maintainer].include?(kind)
|
134
134
|
|
135
135
|
capabilities(project).include?("#{kind} backend") # fallback to backend reviewer
|
136
136
|
when :integrations_be
|
@@ -143,10 +143,10 @@ module Gitlab
|
|
143
143
|
capabilities(project).include?("#{kind}")
|
144
144
|
else
|
145
145
|
capabilities(project).include?("#{kind} #{category}")
|
146
|
-
end ||
|
146
|
+
end || has_universal_capability?(category, kind, labels)
|
147
147
|
end
|
148
148
|
|
149
|
-
def
|
149
|
+
def has_universal_capability?(category, kind, labels)
|
150
150
|
case category
|
151
151
|
when :ux
|
152
152
|
capacity = "#{kind} #{category}"
|
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.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitLab
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- ".gitlab/CODEOWNERS"
|
149
149
|
- ".gitlab/changelog_config.yml"
|
150
150
|
- ".gitlab/merge_request_templates/Release.md"
|
151
|
+
- ".gitpod.yml"
|
151
152
|
- ".rspec"
|
152
153
|
- ".yardopts"
|
153
154
|
- CODE_OF_CONDUCT.md
|
@@ -172,6 +173,7 @@ files:
|
|
172
173
|
- lib/danger/rules/commit_messages/Dangerfile
|
173
174
|
- lib/danger/rules/commits_counter/Dangerfile
|
174
175
|
- lib/danger/rules/simple_roulette/Dangerfile
|
176
|
+
- lib/danger/rules/subtype_label/Dangerfile
|
175
177
|
- lib/danger/rules/type_label/Dangerfile
|
176
178
|
- lib/danger/rules/z_add_labels/Dangerfile
|
177
179
|
- lib/danger/rules/z_retry_link/Dangerfile
|