gitlab-dangerfiles 3.4.3 → 3.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '098225565fa51922d5b158fa2da0a4e3aa7420c3fca45e3acee1c3b3cfaa1ba0'
4
- data.tar.gz: ca80ccfdc03823eff324d59faff1eac19ed1e93798ff0833feef5d7b414c5e45
3
+ metadata.gz: d29ef356c65c4a2ceec87eccbe6d723ee26ae1175176b788d13c146b508ec9fb
4
+ data.tar.gz: fd15845d7c87873c15a8f144fa1bbca3801f0f45dc8e7363585110df07cbb11e
5
5
  SHA512:
6
- metadata.gz: cae6d044924941d20f295da7b5b01aa77ba848a5a87c3894e5c9d8e0894499bdfd03425be5412960daa3724eba5dad11f3f3be02ee8dff80e83ca3b503a86f5f
7
- data.tar.gz: 4903888e704177bb13b9ba3d5a207201ae703bebe047fc4f9f27483f36ba4f0aa5af2c5e5a5d72478c67c51a06319046bb1ba6f6bad52ba14cb18642f178972e
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
@@ -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.
@@ -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)
@@ -261,7 +280,7 @@ module Danger
261
280
  def project_team(project_name)
262
281
  company_members.select do |member|
263
282
  member.in_project?(project_name) ||
264
- member.in_project?("gitlab") # Used for backup reviewer
283
+ member.in_project?("gitlab") # Used for universal reviewer
265
284
  end
266
285
  rescue => err
267
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 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
@@ -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.3"
3
+ VERSION = "3.5.0"
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.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-07-07 00:00:00.000000000 Z
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