gitlab-dangerfiles 2.11.0 → 3.2.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: 708f86af0c7d76e5df58d4ea85223461f39f1f7fb4248b3236d7baa92b626ccf
4
- data.tar.gz: 22f2ee0d777dbc7ab95956f5bf2191c03449bc170baf9c9bacbd1e1e4a32ed69
3
+ metadata.gz: b25f2e8617ff29a3ea964b59774b02c395127c4800bfa1552affd2e71bf62a89
4
+ data.tar.gz: 813ca1c6dbd433cd43f1f5ef0efc44a514af3edf7cf7ed07d75eea50640817da
5
5
  SHA512:
6
- metadata.gz: ad25c4c671fcde850a9c1740fb4e8dc847e4593cff3a55b4ef502bcb902cf84d5ddb4c7a0e64063371d252624f506b47047d32d292efa6ebee92f6db948162c5
7
- data.tar.gz: '066975079aae0a2307c5b2a5734f4ff43d6556bd149c4dcdcac3586646e416c2abc1234ff3833359f24b4e5f19a1eece8af66c7c32b5b813df79cc5fb93bfbe6'
6
+ metadata.gz: d5208cc7b7c588c5fe7403f3b79631313a71c64007ed572fe8a5848a1c229f59f9e653f0b263c5c73efc85a1339fda852d2f44f376cca19f2d2ecac8e406b111
7
+ data.tar.gz: 4b31682875c0c7f5037463d035a57cb9ccd4215d68879105ce4a369539d1e155b6da7b620f942611d9d0fc92251bf58338614230bd16008dbd715974ffee57d9
data/README.md CHANGED
@@ -67,6 +67,8 @@ Gitlab::Dangerfiles.for_project(self, 'my-project') do |dangerfiles|
67
67
  end
68
68
  ```
69
69
 
70
+ Note that your custom plugins and rules (unless you exclude them with `except`) are automatically imported by the gem.
71
+
70
72
  ### Plugins
71
73
 
72
74
  Danger plugins are located under `lib/danger/plugins`.
@@ -85,8 +87,10 @@ Alternatively, you can also get/set configuration on the engine directly via `Gi
85
87
 
86
88
  #### Available general configurations
87
89
 
90
+ - `project_root`: The project root path. You shouldn't have to override it.
88
91
  - `project_name`: The project name. Currently used by the Roulette plugin to fetch relevant
89
92
  reviewers/maintainers based on the project name. Default to `ENV["CI_PROJECT_NAME"]`.
93
+ - `ci_only_rules`: A list of rules that cannot run locally.
90
94
  - `files_to_category`: A hash of the form `{ filename_regex => categories, [filename_regex, changes_regex] => categories }`.
91
95
  `filename_regex` is the regex pattern to match file names. `changes_regex` is the regex pattern to
92
96
  match changed lines in files that match `filename_regex`. Used in `helper.changes_by_category`, `helper.changes`, and `helper.categories_for_file`.
@@ -131,7 +135,9 @@ project. To use it in your project, perform the following steps:
131
135
 
132
136
  #### `type_label`
133
137
 
134
- This rule ensures the merge request has a proper [type label](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification) set.
138
+ This rule warns when the merge request is missing a [type label](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification).
139
+
140
+ If the `DANGER_ERROR_WHEN_TYPE_LABEL_IS_MISSING` environment variable evaluates to `true`, Danger will error when a type label is missing.
135
141
 
136
142
  If the `changelog` plugin is available, it also tries to infer a type label from the `Changelog` trailer of the MR.
137
143
 
@@ -166,6 +172,43 @@ include:
166
172
 
167
173
  See a [real world example](https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/merge_requests/105).
168
174
 
175
+ #### Without `Gemfile`
176
+
177
+ Danger is a Ruby project and uses [`bundler`](https://bundler.io/) to manage
178
+ its dependencies. This requires a project to have a `Gemfile` and
179
+ `Gemfile.lock` commited. This is helpful especially if Danger is also used
180
+ locally - with `lefthook`, for example.
181
+
182
+ In order to skip Ruby and `bundler` dependency in a project, use `bundle` commands directly
183
+ in the CI configuration:
184
+
185
+ ```yaml
186
+ include:
187
+ - project: 'gitlab-org/quality/pipeline-common'
188
+ file: '/ci/danger-review.yml'
189
+
190
+ danger-review:
191
+ before_script:
192
+ - bundle init
193
+ # For latest version
194
+ - bundle add gitlab-dangerfiles
195
+ # OR
196
+ # For a pinned version
197
+ - bundle add gitlab-dangerfiles --version 3.1.0
198
+ ```
199
+
200
+ ## Rake tasks
201
+
202
+ You can import this gem's Rake tasks by adding the following to your project's `Rakefile`:
203
+
204
+ ```ruby
205
+ require 'gitlab-dangerfiles'
206
+
207
+ Gitlab::Dangerfiles.load_tasks
208
+ ```
209
+
210
+ That will add the `danger_local` Rake task that allows to run Danger locally.
211
+
169
212
  ## Documentation
170
213
 
171
214
  Latest documentation can be found at <https://www.rubydoc.info/gems/gitlab-dangerfiles>.
@@ -174,7 +217,9 @@ Latest documentation can be found at <https://www.rubydoc.info/gems/gitlab-dange
174
217
 
175
218
  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.
176
219
 
177
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
220
+ To install this gem onto your local machine, run `bundle exec rake install`.
221
+
222
+ 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.
178
223
 
179
224
  ## Contributing
180
225
 
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
+ spec.add_dependency "rake", ">= 0"
30
31
  spec.add_dependency "danger-gitlab", ">= 8.0.0"
31
32
  spec.add_dependency "danger", ">= 8.4.5"
32
33
 
@@ -4,6 +4,7 @@ module Danger
4
4
  # Contains method to check the presense and validity of changelogs.
5
5
  class Changelog < Danger::Plugin
6
6
  NO_CHANGELOG_LABELS = [
7
+ "maintenance::refactor",
7
8
  "maintenance::pipelines",
8
9
  "maintenance::workflow",
9
10
  "ci-build",
@@ -39,7 +40,6 @@ module Danger
39
40
  This merge request requires a changelog entry because it [%<reason>s](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry).
40
41
  MSG
41
42
  }.freeze
42
- CHANGELOG_CONFIG_FILE = "#{ENV["CI_PROJECT_DIR"]}/.gitlab/changelog_config.yml"
43
43
  DEFAULT_CHANGELOG_CATEGORIES = %w[
44
44
  added
45
45
  fixed
@@ -235,21 +235,25 @@ module Danger
235
235
 
236
236
  private
237
237
 
238
+ def changelog_config_file
239
+ @changelog_config_file ||= File.join(helper.config.project_root, ".gitlab/changelog_config.yml")
240
+ end
241
+
238
242
  def valid_categories
239
243
  return @categories if defined?(@categories)
240
244
 
241
- @categories = if File.exist?(CHANGELOG_CONFIG_FILE)
245
+ @categories = if File.exist?(changelog_config_file)
242
246
  begin
243
247
  YAML
244
- .load_file(CHANGELOG_CONFIG_FILE)
248
+ .load_file(changelog_config_file)
245
249
  .fetch("categories")
246
250
  .keys
247
251
  .freeze
248
252
  rescue Psych::SyntaxError, Psych::DisallowedClass => ex
249
- puts "#{CHANGELOG_CONFIG_FILE} doesn't seem to be a valid YAML file:\n#{ex.message}\nFallbacking to the default categories: #{DEFAULT_CHANGELOG_CATEGORIES}"
253
+ puts "#{changelog_config_file} doesn't seem to be a valid YAML file:\n#{ex.message}\nFallbacking to the default categories: #{DEFAULT_CHANGELOG_CATEGORIES}"
250
254
  DEFAULT_CHANGELOG_CATEGORIES
251
255
  rescue => ex
252
- puts "Received an unexpected failure while trying to fetch categories at #{CHANGELOG_CONFIG_FILE}:\n#{ex.message}\nFallbacking to the default categories: #{DEFAULT_CHANGELOG_CATEGORIES}"
256
+ puts "Received an unexpected failure while trying to fetch categories at #{changelog_config_file}:\n#{ex.message}\nFallbacking to the default categories: #{DEFAULT_CHANGELOG_CATEGORIES}"
253
257
  DEFAULT_CHANGELOG_CATEGORIES
254
258
  end
255
259
  else
@@ -17,7 +17,7 @@ module Danger
17
17
  none: "",
18
18
  qa: "~QA",
19
19
  ux: "~UX",
20
- test: "~test ~Quality for `spec/features/*`",
20
+ test: "~test for `spec/features/*`",
21
21
  # Deprecated as of 2.3.0 in favor of tooling
22
22
  engineering_productivity: '~"Engineering Productivity" for CI, Danger',
23
23
  tooling: '~"maintenance::workflow" / ~"maintenance::pipelines" for CI, Danger',
@@ -142,7 +142,7 @@ module Danger
142
142
  end
143
143
 
144
144
  def release_automation?
145
- gitlab_helper&.mr_author == RELEASE_TOOLS_BOT
145
+ mr_author == RELEASE_TOOLS_BOT
146
146
  end
147
147
 
148
148
  # @param items [Array<String>] An array of items to transform into a bullet list.
@@ -97,7 +97,7 @@ def lint_commits(commits)
97
97
  warn_or_fail_commits(multi_line_commit_linter)
98
98
  commit_linters.delete(multi_line_commit_linter) # Don't show an error (here) and a warning (below)
99
99
  elsif helper.ci? # We don't have access to the MR title locally
100
- title_linter = lint_mr_title(gitlab.mr_json['title'])
100
+ title_linter = lint_mr_title(helper.mr_title)
101
101
  if title_linter.failed?
102
102
  warn_or_fail_commits(title_linter)
103
103
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ if git.commits.size > 20
4
+ failure 'This MR has more than 20 commits. You need to rebase this branch to have fewer commits.'
5
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ TYPE_LABEL_MISSING_MESSAGE = "Please add a [merge request type](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification) to this merge request."
4
+
3
5
  require_relative "../../../gitlab/dangerfiles/type_label_guesser"
4
6
 
5
7
  if respond_to?(:changelog) && !helper.has_scoped_label_with_scope?("type")
@@ -7,6 +9,10 @@ if respond_to?(:changelog) && !helper.has_scoped_label_with_scope?("type")
7
9
  helper.labels_to_add.concat(type_label_guesser.labels_from_changelog_categories(changelog.categories))
8
10
  end
9
11
 
10
- unless helper.has_scoped_label_with_scope?("type")
11
- warn "Please add a [merge request type](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification) to this merge request."
12
+ return if helper.has_scoped_label_with_scope?("type")
13
+
14
+ if ENV["DANGER_ERROR_WHEN_TYPE_LABEL_IS_MISSING"]
15
+ fail TYPE_LABEL_MISSING_MESSAGE
16
+ else
17
+ warn TYPE_LABEL_MISSING_MESSAGE
12
18
  end
@@ -3,10 +3,18 @@
3
3
  module Gitlab
4
4
  module Dangerfiles
5
5
  class Config
6
+ # @!attribute project_root
7
+ # @return [String] the project root folder path.
8
+ attr_accessor :project_root
9
+
6
10
  # @!attribute project_name
7
11
  # @return [String] the project name. Currently used by the Roulette plugin to fetch relevant reviewers/maintainers based on the project name. Default to +ENV["CI_PROJECT_NAME"]+.
8
12
  attr_accessor :project_name
9
13
 
14
+ # @!attribute ci_only_rules
15
+ # @return [Array<String>] rules that cannot be run locally.
16
+ attr_accessor :ci_only_rules
17
+
10
18
  # @!attribute files_to_category
11
19
  # @return [{Regexp => Array<Symbol>}, {Array<Regexp> => Array<Symbol>}] A hash of the form +{ filename_regex => categories, [filename_regex, changes_regex] => categories }+.
12
20
  # +filename_regex+ is the regex pattern to match file names. +changes_regex+ is the regex pattern to
@@ -26,7 +34,9 @@ module Gitlab
26
34
 
27
35
  def initialize
28
36
  @files_to_category = {}
37
+ @project_root = nil
29
38
  @project_name = ENV["CI_PROJECT_NAME"]
39
+ @ci_only_rules = []
30
40
  @code_size_thresholds = DEFAULT_CHANGES_SIZE_THRESHOLDS
31
41
  @max_commits_count = DEFAULT_COMMIT_MESSAGES_MAX_COMMITS_COUNT
32
42
  end
@@ -24,7 +24,9 @@ module DangerSpecHelper
24
24
  # A stubbed out Dangerfile for use in tests
25
25
  def self.testing_dangerfile
26
26
  env = Danger::EnvironmentManager.new(testing_env)
27
- Danger::Dangerfile.new(env, testing_ui)
27
+ Danger::Dangerfile.new(env, testing_ui).tap do |dangerfile|
28
+ dangerfile.defined_in_file = Dir.pwd
29
+ end
28
30
  end
29
31
 
30
32
  def self.fake_danger
@@ -0,0 +1,15 @@
1
+ require "rake"
2
+
3
+ module Gitlab
4
+ module Dangerfiles
5
+ module TaskLoader
6
+ module_function
7
+
8
+ TASKS_DIR = File.expand_path("tasks", __dir__)
9
+
10
+ def load_tasks
11
+ Rake.application.add_import(*Dir.glob(File.join(TASKS_DIR, "*.rake")))
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc "Run local Danger rules"
4
+ task :danger_local do
5
+ require "open3"
6
+
7
+ stdout, stderr, status = Open3.capture3({}, *%w{bundle exec danger dry_run})
8
+
9
+ puts("#{stdout}#{stderr}")
10
+
11
+ exit(status.exitstatus.to_i)
12
+ end
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "2.11.0"
3
+ VERSION = "3.2.0"
4
4
  end
5
5
  end
@@ -13,15 +13,15 @@ module Gitlab
13
13
  # | reduced capacity reviewer | 1 |
14
14
  # | reviewer | 2 |
15
15
  # | hungry reviewer | 4 |
16
- # | reduced capacity traintainer | 3 |
17
- # | traintainer | 6 |
18
- # | hungry traintainer | 8 |
16
+ # | reduced capacity traintainer | 1 |
17
+ # | traintainer | 2 |
18
+ # | hungry traintainer | 6 |
19
19
  # +------------------------------+--------------------------------+
20
20
  #
21
21
  # @api private
22
22
  class Reviewers
23
23
  DEFAULT_REVIEWER_WEIGHT = Gitlab::Dangerfiles::Weightage::CAPACITY_MULTIPLIER * Gitlab::Dangerfiles::Weightage::BASE_REVIEWER_WEIGHT
24
- TRAINTAINER_WEIGHT = 3
24
+ TRAINTAINER_WEIGHT = 2
25
25
 
26
26
  def initialize(reviewers, traintainers)
27
27
  @reviewers = reviewers
@@ -32,6 +32,8 @@ module Gitlab
32
32
  # TODO: take CODEOWNERS into account?
33
33
  # https://gitlab.com/gitlab-org/gitlab/issues/26723
34
34
 
35
+ remove_traintainers_from_reviewers!
36
+
35
37
  weighted_reviewers + weighted_traintainers
36
38
  end
37
39
 
@@ -39,25 +41,33 @@ module Gitlab
39
41
 
40
42
  attr_reader :reviewers, :traintainers
41
43
 
44
+ def remove_traintainers_from_reviewers!
45
+ # Sometimes folks will add themselves as traintainers and not remove themselves as reviewers.
46
+ # There seems no way currently to ensure only one of these entries exists for a person.
47
+ # We need to protect ourselves from that scenario here as the code assumes a reviewer will only
48
+ # appear in reviewers or traintainers, not both.
49
+ reviewers.reject! { |reviewer| traintainers.include?(reviewer) }
50
+ end
51
+
42
52
  def weighted_reviewers
43
53
  reviewers.each_with_object([]) do |reviewer, total_reviewers|
44
- add_weighted_reviewer(total_reviewers, reviewer, Gitlab::Dangerfiles::Weightage::BASE_REVIEWER_WEIGHT)
54
+ add_weighted_reviewer(total_reviewers, reviewer, DEFAULT_REVIEWER_WEIGHT)
45
55
  end
46
56
  end
47
57
 
48
58
  def weighted_traintainers
49
59
  traintainers.each_with_object([]) do |reviewer, total_traintainers|
50
- add_weighted_reviewer(total_traintainers, reviewer, TRAINTAINER_WEIGHT)
60
+ add_weighted_reviewer(total_traintainers, reviewer, DEFAULT_REVIEWER_WEIGHT + TRAINTAINER_WEIGHT)
51
61
  end
52
62
  end
53
63
 
54
- def add_weighted_reviewer(reviewers, reviewer, weight)
64
+ def add_weighted_reviewer(reviewers, reviewer, added_weight_for_hungry)
55
65
  if reviewer.reduced_capacity
56
- reviewers.fill(reviewer, reviewers.size, weight)
66
+ reviewers.fill(reviewer, reviewers.size, Gitlab::Dangerfiles::Weightage::BASE_REVIEWER_WEIGHT)
57
67
  elsif reviewer.hungry
58
- reviewers.fill(reviewer, reviewers.size, weight * Gitlab::Dangerfiles::Weightage::CAPACITY_MULTIPLIER + DEFAULT_REVIEWER_WEIGHT)
68
+ reviewers.fill(reviewer, reviewers.size, DEFAULT_REVIEWER_WEIGHT + added_weight_for_hungry)
59
69
  else
60
- reviewers.fill(reviewer, reviewers.size, weight * Gitlab::Dangerfiles::Weightage::CAPACITY_MULTIPLIER)
70
+ reviewers.fill(reviewer, reviewers.size, DEFAULT_REVIEWER_WEIGHT)
61
71
  end
62
72
  end
63
73
  end
@@ -1,18 +1,9 @@
1
1
  require "gitlab/dangerfiles/version"
2
+ require "gitlab/dangerfiles/task_loader"
2
3
 
3
4
  module Gitlab
4
5
  module Dangerfiles
5
6
  RULES_DIR = File.expand_path("../danger/rules", __dir__)
6
- EXISTING_RULES = Dir.glob(File.join(RULES_DIR, "*")).each_with_object([]) do |path, memo|
7
- if File.directory?(path)
8
- memo << File.basename(path)
9
- end
10
- end
11
- LOCAL_RULES = %w[
12
- changelog
13
- changes_size
14
- commit_messages
15
- ].freeze
16
7
  CI_ONLY_RULES = %w[
17
8
  simple_roulette
18
9
  type_label
@@ -20,6 +11,10 @@ module Gitlab
20
11
  z_retry_link
21
12
  ].freeze
22
13
 
14
+ def self.load_tasks
15
+ TaskLoader.load_tasks
16
+ end
17
+
23
18
  # Utility method to construct a [Gitlab::Dangerfiles::Engine] instance,
24
19
  # which is yielded to the given block.
25
20
  #
@@ -29,6 +24,7 @@ module Gitlab
29
24
  # @return [Gitlab::Dangerfiles::Engine]
30
25
  def self.for_project(dangerfile, project_name = nil)
31
26
  Engine.new(dangerfile).tap do |engine|
27
+ engine.config.project_root = Pathname.new(File.dirname(dangerfile.defined_in_file))
32
28
  engine.config.project_name = project_name if project_name
33
29
 
34
30
  yield engine
@@ -60,15 +56,15 @@ module Gitlab
60
56
  # end
61
57
  def import_plugins
62
58
  danger_plugin.import_plugin(File.expand_path("../danger/plugins/*.rb", __dir__))
59
+
60
+ Dir.glob(File.expand_path("danger/plugins/*.rb", config.project_root)).sort.each do |path|
61
+ puts "Importing plugin at #{path}" if dangerfile.verbose
62
+ danger_plugin.import_plugin(path)
63
+ end
63
64
  end
64
65
 
65
66
  # Import available Dangerfiles.
66
67
  #
67
- # @deprecated
68
- # @param rules [Symbol, Array<String>] Can be either +:all+ (default) to import all rules,
69
- # or an array of rules.
70
- # Available rules are: +changes_size+.
71
- #
72
68
  # @param only [Symbol, Array<String>] An array of rules to import (defaults to all rules).
73
69
  # Available rules are: +changes_size+.
74
70
  #
@@ -87,14 +83,15 @@ module Gitlab
87
83
  # # Or import only a subset of rules, except a subset of rules
88
84
  # dangerfiles.import_dangerfiles(only: %w[changes_size], except: %w[commit_messages])
89
85
  # end
90
- def import_dangerfiles(rules: nil, only: nil, except: [])
91
- puts "The `:rules` parameter is deprecated in favor of `:only`." unless rules.nil?
86
+ def import_dangerfiles(only: nil, except: [])
87
+ return if helper_plugin.release_automation?
92
88
 
93
- only ||= EXISTING_RULES if rules == :all
94
- only ||= rules || EXISTING_RULES
89
+ rules = filtered_rules(only, except)
90
+ puts "Running rules: #{rules}\n" if dangerfile.verbose
95
91
 
96
- filtered_rules(only, except).each do |rule|
97
- danger_plugin.import_dangerfile(path: File.join(RULES_DIR, rule))
92
+ rules.each do |rule, path|
93
+ puts "Importing rule #{rule} at #{path}" if dangerfile.verbose
94
+ danger_plugin.import_dangerfile(path: path)
98
95
  end
99
96
  end
100
97
 
@@ -119,14 +116,43 @@ module Gitlab
119
116
 
120
117
  attr_reader :dangerfile
121
118
 
122
- def allowed_rules
123
- return LOCAL_RULES unless helper_plugin.respond_to?(:ci?)
119
+ def all_gem_rules
120
+ @all_gem_rules ||= Dir.glob(File.join(RULES_DIR, "*")).sort.each_with_object({}) do |path, memo|
121
+ rule_name = File.basename(path)
122
+ memo[rule_name] = path if File.directory?(path) && File.exist?(File.join(path, "Dangerfile"))
123
+ end
124
+ end
125
+
126
+ def custom_rules
127
+ @custom_rules ||= Dir.glob(File.expand_path("danger/*", config.project_root)).sort.each_with_object({}) do |path, memo|
128
+ rule_name = File.basename(path)
129
+ memo[rule_name] = path if File.directory?(path) && File.exist?(File.join(path, "Dangerfile"))
130
+ end
131
+ end
132
+
133
+ def all_rules
134
+ all_gem_rules.merge(custom_rules)
135
+ end
124
136
 
125
- helper_plugin.ci? ? LOCAL_RULES | CI_ONLY_RULES : LOCAL_RULES
137
+ def local_rules
138
+ ci_only_rules = CI_ONLY_RULES | config.ci_only_rules
139
+ all_rules.reject { |rule, _v| ci_only_rules.include?(rule) }
126
140
  end
127
141
 
128
- def filtered_rules(only, except)
129
- (Array(only).map(&:to_s) & EXISTING_RULES & allowed_rules) - except
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
130
156
  end
131
157
 
132
158
  def danger_plugin
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-dangerfiles
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 3.2.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-03-15 00:00:00.000000000 Z
11
+ date: 2022-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: danger-gitlab
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -155,6 +169,7 @@ files:
155
169
  - lib/danger/rules/changelog/Dangerfile
156
170
  - lib/danger/rules/changes_size/Dangerfile
157
171
  - lib/danger/rules/commit_messages/Dangerfile
172
+ - lib/danger/rules/commits_counter/Dangerfile
158
173
  - lib/danger/rules/simple_roulette/Dangerfile
159
174
  - lib/danger/rules/type_label/Dangerfile
160
175
  - lib/danger/rules/z_add_labels/Dangerfile
@@ -169,6 +184,8 @@ files:
169
184
  - lib/gitlab/dangerfiles/emoji_checker.rb
170
185
  - lib/gitlab/dangerfiles/merge_request_linter.rb
171
186
  - lib/gitlab/dangerfiles/spec_helper.rb
187
+ - lib/gitlab/dangerfiles/task_loader.rb
188
+ - lib/gitlab/dangerfiles/tasks/main.rake
172
189
  - lib/gitlab/dangerfiles/teammate.rb
173
190
  - lib/gitlab/dangerfiles/title_linting.rb
174
191
  - lib/gitlab/dangerfiles/type_label_guesser.rb