gitlab-dangerfiles 2.10.1 → 3.0.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 +4 -4
- data/README.md +16 -0
- data/gitlab-dangerfiles.gemspec +2 -1
- data/lib/danger/plugins/changelog.rb +11 -8
- data/lib/danger/plugins/internal/helper.rb +5 -5
- data/lib/danger/rules/commit_messages/Dangerfile +1 -1
- data/lib/danger/rules/type_label/Dangerfile +1 -1
- data/lib/gitlab/dangerfiles/config.rb +10 -0
- data/lib/gitlab/dangerfiles/spec_helper.rb +3 -1
- data/lib/gitlab/dangerfiles/task_loader.rb +15 -0
- data/lib/gitlab/dangerfiles/tasks/main.rake +12 -0
- data/lib/gitlab/dangerfiles/version.rb +1 -1
- data/lib/gitlab/dangerfiles.rb +52 -26
- metadata +20 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bcd8631096b4c3a5c7c6df1c8a1c49fda0a4b4936c9f815996ca7702be99f3e
|
4
|
+
data.tar.gz: ce6a7cc2c2b69e49a262882eddba550d4245c578bfc235be594a27cd0d04d737
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60b36a45528577103064018e02315f365f729c4842f77ef794001fe4697760f2baf60ecaf29a19c5a1c0be25c239832b5d93908a4d6ddb5df7dc22380968f317
|
7
|
+
data.tar.gz: f1591f53f037986f147f9549bfe98faeecee825c20d916e4370d9f76d562a18456fe8ac993e507987013bdaa52b95845776bac3c66fe6ab844d2f74b13084339
|
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`.
|
@@ -166,6 +170,18 @@ include:
|
|
166
170
|
|
167
171
|
See a [real world example](https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles/-/merge_requests/105).
|
168
172
|
|
173
|
+
## Rake tasks
|
174
|
+
|
175
|
+
You can import this gem's Rake tasks by adding the following to your project's `Rakefile`:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
require 'gitlab-dangerfiles'
|
179
|
+
|
180
|
+
Gitlab::Dangerfiles.load_tasks
|
181
|
+
```
|
182
|
+
|
183
|
+
That will add the `danger_local` Rake task that allows to run Danger locally.
|
184
|
+
|
169
185
|
## Documentation
|
170
186
|
|
171
187
|
Latest documentation can be found at <https://www.rubydoc.info/gems/gitlab-dangerfiles>.
|
data/gitlab-dangerfiles.gemspec
CHANGED
@@ -27,8 +27,9 @@ 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
|
-
spec.add_dependency "danger", ">= 8.
|
32
|
+
spec.add_dependency "danger", ">= 8.4.5"
|
32
33
|
|
33
34
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
35
|
spec.add_development_dependency "rspec-parameterized"
|
@@ -4,9 +4,9 @@ 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
|
-
"
|
8
|
-
"
|
9
|
-
"
|
7
|
+
"maintenance::refactor",
|
8
|
+
"maintenance::pipelines",
|
9
|
+
"maintenance::workflow",
|
10
10
|
"ci-build",
|
11
11
|
"meta",
|
12
12
|
].freeze
|
@@ -40,7 +40,6 @@ module Danger
|
|
40
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).
|
41
41
|
MSG
|
42
42
|
}.freeze
|
43
|
-
CHANGELOG_CONFIG_FILE = "#{ENV["CI_PROJECT_DIR"]}/.gitlab/changelog_config.yml"
|
44
43
|
DEFAULT_CHANGELOG_CATEGORIES = %w[
|
45
44
|
added
|
46
45
|
fixed
|
@@ -236,21 +235,25 @@ module Danger
|
|
236
235
|
|
237
236
|
private
|
238
237
|
|
238
|
+
def changelog_config_file
|
239
|
+
@changelog_config_file ||= File.join(helper.config.project_root, ".gitlab/changelog_config.yml")
|
240
|
+
end
|
241
|
+
|
239
242
|
def valid_categories
|
240
243
|
return @categories if defined?(@categories)
|
241
244
|
|
242
|
-
@categories = if File.exist?(
|
245
|
+
@categories = if File.exist?(changelog_config_file)
|
243
246
|
begin
|
244
247
|
YAML
|
245
|
-
.load_file(
|
248
|
+
.load_file(changelog_config_file)
|
246
249
|
.fetch("categories")
|
247
250
|
.keys
|
248
251
|
.freeze
|
249
252
|
rescue Psych::SyntaxError, Psych::DisallowedClass => ex
|
250
|
-
puts "#{
|
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}"
|
251
254
|
DEFAULT_CHANGELOG_CATEGORIES
|
252
255
|
rescue => ex
|
253
|
-
puts "Received an unexpected failure while trying to fetch categories at #{
|
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}"
|
254
257
|
DEFAULT_CHANGELOG_CATEGORIES
|
255
258
|
end
|
256
259
|
else
|
@@ -20,7 +20,7 @@ module Danger
|
|
20
20
|
test: "~test ~Quality 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
|
-
tooling: '~"
|
23
|
+
tooling: '~"maintenance::workflow" / ~"maintenance::pipelines" for CI, Danger',
|
24
24
|
ci_template: '~"ci::templates"',
|
25
25
|
product_intelligence: '~"product intelligence"',
|
26
26
|
integrations_be: '~"group::integrations" (backend)',
|
@@ -142,7 +142,7 @@ module Danger
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def release_automation?
|
145
|
-
|
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.
|
@@ -282,7 +282,7 @@ module Danger
|
|
282
282
|
def mr_labels
|
283
283
|
return [] unless ci?
|
284
284
|
|
285
|
-
(gitlab_helper.mr_labels + labels_to_add
|
285
|
+
(gitlab_helper.mr_labels + labels_to_add).uniq
|
286
286
|
end
|
287
287
|
|
288
288
|
# @return [String] +`git rev-parse --abbrev-ref HEAD`+ when not in the CI context, and the MR source branch otherwise.
|
@@ -409,9 +409,9 @@ module Danger
|
|
409
409
|
# itself. Without this method, the first rule wouldn't know that the label would be applied and would ask
|
410
410
|
# for it anyway.
|
411
411
|
#
|
412
|
-
# @return [
|
412
|
+
# @return [Array<String>] the list of labels that Danger will add
|
413
413
|
def labels_to_add
|
414
|
-
@labels_to_add ||=
|
414
|
+
@labels_to_add ||= []
|
415
415
|
end
|
416
416
|
|
417
417
|
private
|
@@ -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(
|
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
|
@@ -4,7 +4,7 @@ require_relative "../../../gitlab/dangerfiles/type_label_guesser"
|
|
4
4
|
|
5
5
|
if respond_to?(:changelog) && !helper.has_scoped_label_with_scope?("type")
|
6
6
|
type_label_guesser = Gitlab::Dangerfiles::TypeLabelGuesser.new
|
7
|
-
helper.labels_to_add.
|
7
|
+
helper.labels_to_add.concat(type_label_guesser.labels_from_changelog_categories(changelog.categories))
|
8
8
|
end
|
9
9
|
|
10
10
|
unless helper.has_scoped_label_with_scope?("type")
|
@@ -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
|
data/lib/gitlab/dangerfiles.rb
CHANGED
@@ -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(
|
91
|
-
|
86
|
+
def import_dangerfiles(only: nil, except: [])
|
87
|
+
return if helper_plugin.release_automation?
|
92
88
|
|
93
|
-
|
94
|
-
|
89
|
+
rules = filtered_rules(only, except)
|
90
|
+
puts "Running rules: #{rules}\n" if dangerfile.verbose
|
95
91
|
|
96
|
-
|
97
|
-
|
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
|
123
|
-
|
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
|
-
|
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
|
129
|
-
|
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:
|
4
|
+
version: 3.0.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-
|
11
|
+
date: 2022-03-22 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
|
@@ -30,14 +44,14 @@ dependencies:
|
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 8.
|
47
|
+
version: 8.4.5
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 8.
|
54
|
+
version: 8.4.5
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,6 +183,8 @@ files:
|
|
169
183
|
- lib/gitlab/dangerfiles/emoji_checker.rb
|
170
184
|
- lib/gitlab/dangerfiles/merge_request_linter.rb
|
171
185
|
- lib/gitlab/dangerfiles/spec_helper.rb
|
186
|
+
- lib/gitlab/dangerfiles/task_loader.rb
|
187
|
+
- lib/gitlab/dangerfiles/tasks/main.rake
|
172
188
|
- lib/gitlab/dangerfiles/teammate.rb
|
173
189
|
- lib/gitlab/dangerfiles/title_linting.rb
|
174
190
|
- lib/gitlab/dangerfiles/type_label_guesser.rb
|