gitlab-dangerfiles 3.4.1 → 3.5.0
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 +25 -2
- data/lib/danger/rules/subtype_label/Dangerfile +14 -0
- data/lib/danger/rules/type_label/Dangerfile +4 -4
- data/lib/gitlab/dangerfiles/changes.rb +1 -1
- data/lib/gitlab/dangerfiles/teammate.rb +3 -3
- data/lib/gitlab/dangerfiles/version.rb +1 -1
- data/lib/gitlab/dangerfiles.rb +24 -25
- 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: d29ef356c65c4a2ceec87eccbe6d723ee26ae1175176b788d13c146b508ec9fb
|
4
|
+
data.tar.gz: fd15845d7c87873c15a8f144fa1bbca3801f0f45dc8e7363585110df07cbb11e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e14eb3849ed8da68ac7a716347ff89b4a2df7fbd47b014663807c913632fa6f6d363de94b94aa2df868335e6e5d5af0362f477c07b5d3519b5bd46219623150f
|
7
|
+
data.tar.gz: 6f233f7f4b679dcca8ab438f54fd0ff4a400e8527614d675562421b818ad1dfe505874259cfc7e718dbba665c6dde02551520168b71630b39ad2680949db2b1c
|
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.
|
@@ -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,7 +103,8 @@ module Danger
|
|
101
103
|
|
102
104
|
return [] unless approval_rules
|
103
105
|
|
104
|
-
|
106
|
+
required_approval_rules = unique_approval_rules(approval_rules)
|
107
|
+
required_approval_rules.filter_map do |rule|
|
105
108
|
rule["rule_type"] == "code_owner" &&
|
106
109
|
rule["approvals_required"] > 0 &&
|
107
110
|
Approval.from_approval_rule(rule, spin_for_approver(rule))
|
@@ -110,6 +113,22 @@ module Danger
|
|
110
113
|
|
111
114
|
private
|
112
115
|
|
116
|
+
# Returns an array containing all unique approval rules, based on on the section and eligible_approvers of the rules
|
117
|
+
#
|
118
|
+
# @param [Array<Hash>] approval rules
|
119
|
+
# @return [Array<Hash>]
|
120
|
+
def unique_approval_rules(approval_rules)
|
121
|
+
approval_rules.uniq do |rule|
|
122
|
+
section = rule["section"]
|
123
|
+
|
124
|
+
approvers = rule["eligible_approvers"].map do |approver|
|
125
|
+
approver["username"]
|
126
|
+
end
|
127
|
+
|
128
|
+
[section, approvers]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
113
132
|
# @param [Gitlab::Dangerfiles::Teammate] person
|
114
133
|
# @return [Boolean]
|
115
134
|
def valid_person?(person)
|
@@ -226,6 +245,10 @@ module Danger
|
|
226
245
|
def http_get_json(url)
|
227
246
|
rsp = Net::HTTP.get_response(URI.parse(url))
|
228
247
|
|
248
|
+
if rsp.is_a?(Net::HTTPRedirection)
|
249
|
+
raise "Redirection detected: #{rsp.header["location"]}"
|
250
|
+
end
|
251
|
+
|
229
252
|
unless rsp.is_a?(Net::HTTPOK)
|
230
253
|
raise HTTPError, "Failed to read #{url}: #{rsp.code} #{rsp.message}"
|
231
254
|
end
|
@@ -257,7 +280,7 @@ module Danger
|
|
257
280
|
def project_team(project_name)
|
258
281
|
company_members.select do |member|
|
259
282
|
member.in_project?(project_name) ||
|
260
|
-
member.in_project?("gitlab") # Used for
|
283
|
+
member.in_project?("gitlab") # Used for universal reviewer
|
261
284
|
end
|
262
285
|
rescue => err
|
263
286
|
warn("Reviewer roulette failed to load team data: #{err.message}")
|
@@ -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}"
|
data/lib/gitlab/dangerfiles.rb
CHANGED
@@ -58,7 +58,7 @@ module Gitlab
|
|
58
58
|
danger_plugin.import_plugin(File.expand_path("../danger/plugins/*.rb", __dir__))
|
59
59
|
|
60
60
|
Dir.glob(File.expand_path("danger/plugins/*.rb", config.project_root)).sort.each do |path|
|
61
|
-
puts "Importing plugin at #{path}" if
|
61
|
+
puts "Importing plugin at #{path}" if helper_plugin.ci?
|
62
62
|
danger_plugin.import_plugin(path)
|
63
63
|
end
|
64
64
|
end
|
@@ -87,10 +87,9 @@ module Gitlab
|
|
87
87
|
return if helper_plugin.release_automation?
|
88
88
|
|
89
89
|
rules = filtered_rules(only, except)
|
90
|
-
puts "Running rules: #{rules}\n" if dangerfile.verbose
|
91
90
|
|
92
91
|
rules.each do |rule, path|
|
93
|
-
puts "Importing rule #{rule} at #{path}" if
|
92
|
+
puts "Importing rule #{rule} at #{path}" if helper_plugin.ci?
|
94
93
|
danger_plugin.import_dangerfile(path: path)
|
95
94
|
end
|
96
95
|
end
|
@@ -116,45 +115,45 @@ module Gitlab
|
|
116
115
|
|
117
116
|
attr_reader :dangerfile
|
118
117
|
|
118
|
+
def filtered_rules(only_rules, except_rules)
|
119
|
+
only_rules = Array(only_rules).compact.map(&:to_s)
|
120
|
+
|
121
|
+
rules = allowed_rules_based_on_context.reject { |rule, _v| except_rules.include?(rule) }
|
122
|
+
|
123
|
+
if only_rules.any?
|
124
|
+
rules.select! { |rule, _v| only_rules.include?(rule) }
|
125
|
+
end
|
126
|
+
|
127
|
+
rules.sort.to_h
|
128
|
+
end
|
129
|
+
|
130
|
+
def allowed_rules_based_on_context
|
131
|
+
helper_plugin.ci? ? all_rules : local_rules
|
132
|
+
end
|
133
|
+
|
134
|
+
def all_rules
|
135
|
+
all_gem_rules.merge(custom_rules)
|
136
|
+
end
|
137
|
+
|
119
138
|
def all_gem_rules
|
120
|
-
@all_gem_rules ||= Dir.glob(File.join(RULES_DIR, "*")).
|
139
|
+
@all_gem_rules ||= Dir.glob(File.join(RULES_DIR, "*")).each_with_object({}) do |path, memo|
|
121
140
|
rule_name = File.basename(path)
|
122
141
|
memo[rule_name] = path if File.directory?(path) && File.exist?(File.join(path, "Dangerfile"))
|
123
142
|
end
|
124
143
|
end
|
125
144
|
|
126
145
|
def custom_rules
|
127
|
-
@custom_rules ||= Dir.glob(File.expand_path("danger/*", config.project_root)).
|
146
|
+
@custom_rules ||= Dir.glob(File.expand_path("danger/*", config.project_root)).each_with_object({}) do |path, memo|
|
128
147
|
rule_name = File.basename(path)
|
129
148
|
memo[rule_name] = path if File.directory?(path) && File.exist?(File.join(path, "Dangerfile"))
|
130
149
|
end
|
131
150
|
end
|
132
151
|
|
133
|
-
def all_rules
|
134
|
-
all_gem_rules.merge(custom_rules)
|
135
|
-
end
|
136
|
-
|
137
152
|
def local_rules
|
138
153
|
ci_only_rules = CI_ONLY_RULES | config.ci_only_rules
|
139
154
|
all_rules.reject { |rule, _v| ci_only_rules.include?(rule) }
|
140
155
|
end
|
141
156
|
|
142
|
-
def allowed_rules_based_on_context
|
143
|
-
helper_plugin.ci? ? all_rules : local_rules
|
144
|
-
end
|
145
|
-
|
146
|
-
def filtered_rules(only_rules, except_rules)
|
147
|
-
only_rules = Array(only_rules).compact.map(&:to_s)
|
148
|
-
|
149
|
-
rules = allowed_rules_based_on_context.reject { |rule, _v| except_rules.include?(rule) }
|
150
|
-
|
151
|
-
if only_rules.any?
|
152
|
-
rules.select! { |rule, _v| only_rules.include?(rule) }
|
153
|
-
end
|
154
|
-
|
155
|
-
rules
|
156
|
-
end
|
157
|
-
|
158
157
|
def danger_plugin
|
159
158
|
@danger_plugin ||= dangerfile.plugins[Danger::DangerfileDangerPlugin]
|
160
159
|
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: 3.
|
4
|
+
version: 3.5.0
|
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-07-25 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
|