gitlab-dangerfiles 3.4.2 → 3.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bcb56a4513a5f26239f800a2692bd8feedc8fed15bd2d4d2d93d9d2203e0df70
4
- data.tar.gz: 0fd4fd6f9cacee27bf394c2b5ef17a7fee6b34b45b215e08524d5641fc0b092d
3
+ metadata.gz: 725c7feec8f29334e0ead741012d5b8d375cd026659853b78647c6508dcc6036
4
+ data.tar.gz: 1fc53d98126dee2a149b2ed57261b4652735729da94443371adc1c632a1d7217
5
5
  SHA512:
6
- metadata.gz: 8bcfa9f04ce155b7e77393c9d8e2eef9ab6534111f2ce5eaa33d484ed5e811827172ba90f40589b81f1987fd35277eab91afcd5365282e4deb94de92752d5054
7
- data.tar.gz: 526c301f0e148a4ed6faf4dcffb3afa4d142ab828eb36eb8e745783ba80964a769a4e3456683ad1898d0d4328bc3f25f5847557042fad7ae9f53b20b7d2e22e1
6
+ metadata.gz: 60608ce5de5def782566653bfaeb9e036f95ff36d0a9a1fc57a7cbff663a8ca83b7769bc47751ec3a1dcb26ab7daf82ba39274753bf928d0f55708e2cfd65fec
7
+ data.tar.gz: 88eaaa34e4594faea4972fb762b1f8ba609a073b6a9940a3bd77ca350022535d3ddb2d20997c87c5283af5f85245e50af56ed744897f304cfed66c575ab95944
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
@@ -0,0 +1,2 @@
1
+ tasks:
2
+ - init: bin/setup
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, "~#{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 || helper.config.project_name).downcase
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,7 +103,8 @@ module Danger
101
103
 
102
104
  return [] unless approval_rules
103
105
 
104
- approval_rules.filter_map do |rule|
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)
@@ -168,11 +187,8 @@ module Danger
168
187
  #
169
188
  # @return [Gitlab::Dangerfiles::Teammate]
170
189
  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
190
  approvers = rule["eligible_approvers"].filter_map do |approver|
175
- find_member(approver["username"])
191
+ find_member(approver["username"], project: config_project_name.downcase)
176
192
  end
177
193
 
178
194
  spin_for_person(approvers) || spin_for_approver_fallback(rule)
@@ -250,8 +266,22 @@ module Danger
250
266
  end
251
267
  end
252
268
 
253
- def find_member(username)
254
- company_members.find { |person| person.username == username }
269
+ def find_member(username, project: nil)
270
+ company_members.find do |member|
271
+ member.username == username &&
272
+ if project
273
+ member.in_project?(project)
274
+ else
275
+ true
276
+ end
277
+ end
278
+ end
279
+
280
+ # Return the configured project name
281
+ #
282
+ # @return [String]
283
+ def config_project_name
284
+ helper.config.project_name
255
285
  end
256
286
 
257
287
  # Like +team+, but only returns teammates in the current project, based on
@@ -261,7 +291,7 @@ module Danger
261
291
  def project_team(project_name)
262
292
  company_members.select do |member|
263
293
  member.in_project?(project_name) ||
264
- member.in_project?("gitlab") # Used for backup reviewer
294
+ member.in_project?("gitlab") # Used for universal reviewer
265
295
  end
266
296
  rescue => err
267
297
  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 squash merge option and re-run #{danger_job_link}."
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 squash in the merge request and re-run #{danger_job_link}.", more_info: false)
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 respond_to?(:changelog) && !helper.has_scoped_label_with_scope?("type")
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
- return if helper.has_scoped_label_with_scope?("type")
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
@@ -62,7 +62,7 @@ module Gitlab
62
62
 
63
63
  # @return [Array<String>] an array of the changed files.
64
64
  def files
65
- map(&:file)
65
+ map(&:file).uniq
66
66
  end
67
67
 
68
68
  private
@@ -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 kind == :maintainer
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 || has_backup_capability?(category, kind, labels)
146
+ end || has_universal_capability?(category, kind, labels)
147
147
  end
148
148
 
149
- def has_backup_capability?(category, kind, labels)
149
+ def has_universal_capability?(category, kind, labels)
150
150
  case category
151
151
  when :ux
152
152
  capacity = "#{kind} #{category}"
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "3.4.2"
3
+ VERSION = "3.5.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: 3.4.2
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-30 00:00:00.000000000 Z
11
+ date: 2022-08-11 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