gitlab-dangerfiles 2.3.1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab/CODEOWNERS +1 -0
- data/.gitlab/changelog_config.yml +13 -0
- data/.gitlab/merge_request_templates/Release.md +6 -28
- data/.gitlab-ci.yml +6 -0
- data/CONTRIBUTING.md +40 -0
- data/Dangerfile +5 -0
- data/Gemfile +4 -0
- data/README.md +61 -10
- data/lib/danger/plugins/helper.rb +14 -8
- data/lib/danger/plugins/roulette.rb +6 -1
- data/lib/danger/rules/simple_roulette/Dangerfile +61 -0
- data/lib/gitlab/dangerfiles/base_linter.rb +1 -1
- data/lib/gitlab/dangerfiles/config.rb +12 -0
- data/lib/gitlab/dangerfiles/teammate.rb +31 -6
- data/lib/gitlab/dangerfiles/version.rb +1 -1
- data/lib/gitlab/dangerfiles.rb +62 -17
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af398dd6651e65bb4716c5a2c1aee8ee93a9a98c68f4b71f5da3de3d83a2aff2
|
4
|
+
data.tar.gz: cb57a546b8f9c15b1c17ebe9fa6936e312c6f0345e74c6778220ceb56b884c6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b4df78cdb34004d811fbd711c251151820382a3ed4de31b26f46e90a8a9f121a2111b2d90de1aeaf390129fccb563bfa679ddc50ef84975a9f6da9ad3aeff6d
|
7
|
+
data.tar.gz: b88f6fb0e0e46d5f089651312fe45a7713ab6f732216d744bf8f24515d6471d08696cd1b2ee1b2290c881972b6ef8c5376a68a74d58fd0ec76e7620009074a16
|
data/.gitlab/CODEOWNERS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* @gl-quality/eng-prod
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
# Settings for generating changelogs using the GitLab API. See
|
3
|
+
# https://docs.gitlab.com/ee/api/repositories.html#generate-changelog-data for
|
4
|
+
# more information.
|
5
|
+
categories:
|
6
|
+
added: Added
|
7
|
+
fixed: Fixed
|
8
|
+
changed: Changed
|
9
|
+
deprecated: Deprecated
|
10
|
+
removed: Removed
|
11
|
+
security: Security
|
12
|
+
performance: Performance
|
13
|
+
other: Other
|
@@ -1,35 +1,13 @@
|
|
1
|
-
<!-- Replace
|
2
|
-
with the latest commit from
|
3
|
-
- Diff: https://gitlab.com/gitlab-org/gitlab-dangerfiles/compare/
|
4
|
-
|
5
|
-
- Release notes:
|
6
|
-
|
7
|
-
<!-- Keep the sections order but remove the empty sections -->
|
8
|
-
|
9
|
-
```markdown
|
10
|
-
### New features and features updates
|
11
|
-
|
12
|
-
- !aaa <Title of the aaa MR>.
|
13
|
-
|
14
|
-
### Fixes
|
15
|
-
|
16
|
-
- !bbb <Title of the bbb MR>.
|
17
|
-
|
18
|
-
### Doc changes
|
19
|
-
|
20
|
-
- !ccc <Title of the ccc MR>.
|
21
|
-
|
22
|
-
### Other changes (tooling, technical debt)
|
23
|
-
|
24
|
-
- !ddd <Title of the ddd MR>.
|
25
|
-
```
|
1
|
+
<!-- Replace `<NEW_VERSION>` with the previous release here, and `<COMMIT_UPDATING_VERSION>`
|
2
|
+
with the latest commit from this merge request. -->
|
3
|
+
- Diff: https://gitlab.com/gitlab-org/ruby/gems/gitlab-dangerfiles/compare/v<NEW_VERSION>...<COMMIT_UPDATING_VERSION>
|
26
4
|
|
27
5
|
- Checklist before merging:
|
28
6
|
- [ ] Diff link is up-to-date.
|
29
|
-
- [ ] Based on the diff, `
|
30
|
-
- [ ] Release notes are accurate.
|
7
|
+
- [ ] Based on the diff, `version.rb` is updated, according to [SemVer](https://semver.org).
|
31
8
|
|
32
9
|
- Checklist after merging:
|
33
10
|
- [ ] [Update the release notes for the newly created tag](docs/release_process.md#how-to).
|
11
|
+
- [ ] Check that automatic release notes (generated following the same process as https://docs.gitlab.com/ee/development/changelog.html) are correct.
|
34
12
|
|
35
|
-
/label ~"
|
13
|
+
/label ~"type::maintenance" ~"static code analysis"
|
data/.gitlab-ci.yml
CHANGED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
## Developer Certificate of Origin and License
|
2
|
+
|
3
|
+
By contributing to GitLab B.V., you accept and agree to the following terms and
|
4
|
+
conditions for your present and future contributions submitted to GitLab B.V.
|
5
|
+
Except for the license granted herein to GitLab B.V. and recipients of software
|
6
|
+
distributed by GitLab B.V., you reserve all right, title, and interest in and to
|
7
|
+
your Contributions.
|
8
|
+
|
9
|
+
All contributions are subject to the Developer Certificate of Origin and license set out at [docs.gitlab.com/ce/legal/developer_certificate_of_origin](https://docs.gitlab.com/ce/legal/developer_certificate_of_origin).
|
10
|
+
|
11
|
+
_This notice should stay as the first item in the CONTRIBUTING.md file._
|
12
|
+
|
13
|
+
## Code of conduct
|
14
|
+
|
15
|
+
As contributors and maintainers of this project, we pledge to respect all people
|
16
|
+
who contribute through reporting issues, posting feature requests, updating
|
17
|
+
documentation, submitting pull requests or patches, and other activities.
|
18
|
+
|
19
|
+
We are committed to making participation in this project a harassment-free
|
20
|
+
experience for everyone, regardless of level of experience, gender, gender
|
21
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
22
|
+
body size, race, ethnicity, age, or religion.
|
23
|
+
|
24
|
+
Examples of unacceptable behavior by participants include the use of sexual
|
25
|
+
language or imagery, derogatory comments or personal attacks, trolling, public
|
26
|
+
or private harassment, insults, or other unprofessional conduct.
|
27
|
+
|
28
|
+
Project maintainers have the right and responsibility to remove, edit, or reject
|
29
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
30
|
+
not aligned to this Code of Conduct. Project maintainers who do not follow the
|
31
|
+
Code of Conduct may be removed from the project team.
|
32
|
+
|
33
|
+
This code of conduct applies both within project spaces and in public spaces
|
34
|
+
when an individual is representing the project or its community.
|
35
|
+
|
36
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior can be
|
37
|
+
reported by emailing contact@gitlab.com.
|
38
|
+
|
39
|
+
This Code of Conduct is adapted from the [Contributor Covenant](https://contributor-covenant.org), version 1.1.0,
|
40
|
+
available at [https://contributor-covenant.org/version/1/1/0/](https://contributor-covenant.org/version/1/1/0/).
|
data/Dangerfile
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -26,22 +26,45 @@ $ gem install gitlab-dangerfiles
|
|
26
26
|
|
27
27
|
### Importing plugins and rules
|
28
28
|
|
29
|
-
In your project's `Dangerfile`, add the following
|
29
|
+
In your project's `Dangerfile`, add the following to import the plugins and rules from this gem:
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
require 'gitlab-dangerfiles'
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
Gitlab::Dangerfiles.for_project(self) do |dangerfiles|
|
35
|
+
# Import all plugins from the gem
|
36
|
+
dangerfiles.import_plugins
|
36
37
|
|
37
|
-
# Import all
|
38
|
-
|
38
|
+
# Import all rules from the gem
|
39
|
+
dangerfiles.import_dangerfiles
|
39
40
|
|
40
|
-
#
|
41
|
-
|
41
|
+
# Or import only a subset of rules
|
42
|
+
dangerfiles.import_dangerfiles(only: %w[changes_size])
|
42
43
|
|
43
|
-
# Or import a subset of rules
|
44
|
-
|
44
|
+
# Or import all rules except a subset of rules
|
45
|
+
dangerfiles.import_dangerfiles(except: %w[commit_messages])
|
46
|
+
|
47
|
+
# Or import only a subset of rules, except a subset of rules
|
48
|
+
dangerfiles.import_dangerfiles(only: %w[changes_size], except: %w[commit_messages])
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
For simple projects such as libraries, you can use the convenience method `import_defaults`:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
Gitlab::Dangerfiles.for_project(self) do |dangerfiles|
|
56
|
+
# Imports all plugins, rules and the default reviewer roulette
|
57
|
+
dangerfiles.import_defaults
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
You may optionally pass a project name; by default, `ENV['CI_PROJECT_NAME']` will be used:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
Gitlab::Dangerfiles.for_project(self, 'my-project') do |dangerfiles|
|
65
|
+
# Imports all plugins, rules and the default reviewer roulette
|
66
|
+
dangerfiles.import_defaults
|
67
|
+
end
|
45
68
|
```
|
46
69
|
|
47
70
|
### Plugins
|
@@ -53,8 +76,21 @@ Danger plugins are located under `lib/danger/plugins`.
|
|
53
76
|
|
54
77
|
For the full documentation about the plugins, please see https://www.rubydoc.info/gems/gitlab-dangerfiles.
|
55
78
|
|
56
|
-
###
|
79
|
+
### Configuration
|
80
|
+
|
81
|
+
Default configuration can be overriden in the form `helper.config.CONFIG_NAME = NEW_VALUE` (`CONFIG_NAME` being a value configuration key).
|
82
|
+
|
83
|
+
Alternatively, you can also get/set configuration on the engine directly via `Gitlab::Dangerfiles::Engine#config`.
|
57
84
|
|
85
|
+
#### Available general configurations
|
86
|
+
|
87
|
+
- `project_name`: The project name. Currently used by the Roulette plugin to fetch relevant
|
88
|
+
reviewers/maintainers based on the project name. Default to `ENV["CI_PROJECT_NAME"]`.
|
89
|
+
- `files_to_category`: A hash of the form `{ filename_regex => categories, [filename_regex, changes_regex] => categories }`.
|
90
|
+
`filename_regex` is the regex pattern to match file names. `changes_regex` is the regex pattern to
|
91
|
+
match changed lines in files that match `filename_regex`. Used in `helper.changes_by_category`, `helper.changes`, and `helper.categories_for_file`.
|
92
|
+
|
93
|
+
### Rules
|
58
94
|
|
59
95
|
Danger rules are located under `lib/danger/rules`.
|
60
96
|
|
@@ -73,6 +109,21 @@ Danger rules are located under `lib/danger/rules`.
|
|
73
109
|
- `max_commits_count`: The maximum number of allowed non-squashed/non-fixup commits for a given MR.
|
74
110
|
A warning is triggered if the MR has more commits.
|
75
111
|
|
112
|
+
### Reviewer Roulette
|
113
|
+
|
114
|
+
The library includes a simplified default reviewer roulette that you can use in your
|
115
|
+
project. To use it in your project, perform the following steps:
|
116
|
+
|
117
|
+
1. If not yet done, create a `Dangerfile` at the top-level of your project. Refer to [Usage](#usage) to
|
118
|
+
see how to set it up.
|
119
|
+
1. When using the default roulette, use `import_defaults` or import it manually when setting
|
120
|
+
up the gitlab-dangerfiles instance:
|
121
|
+
```ruby
|
122
|
+
Gitlab::Dangerfiles.for_project(self) do |dangerfiles|
|
123
|
+
dangerfiles.import_dangerfiles(only: %w[simple_roulette])
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
76
127
|
## Documentation
|
77
128
|
|
78
129
|
Latest documentation can be found at <https://www.rubydoc.info/gems/gitlab-dangerfiles>.
|
@@ -16,12 +16,15 @@ module Danger
|
|
16
16
|
docs: "~documentation", # Docs are reviewed along DevOps stages, so don't need roulette for now.
|
17
17
|
none: "",
|
18
18
|
qa: "~QA",
|
19
|
+
ux: "~UX",
|
19
20
|
test: "~test ~Quality for `spec/features/*`",
|
20
21
|
# Deprecated as of 2.3.0 in favor of tooling
|
21
22
|
engineering_productivity: '~"Engineering Productivity" for CI, Danger',
|
22
|
-
tooling: "
|
23
|
+
tooling: '~"type::tooling" for CI, Danger',
|
23
24
|
ci_template: '~"ci::templates"',
|
24
25
|
product_intelligence: '~"product intelligence"',
|
26
|
+
integrations_be: '~"group::integrations" (backend)',
|
27
|
+
integrations_fe: '~"group::integrations" (frontend)',
|
25
28
|
}.freeze
|
26
29
|
|
27
30
|
# Allows to set specific rule's configuration by passing a block.
|
@@ -172,7 +175,7 @@ module Danger
|
|
172
175
|
#
|
173
176
|
# @return [{Symbol => Array<String>}] a hash of the type +{ category1: ["file1", "file2"], category2: ["file3", "file4"] }+
|
174
177
|
# using filename regex (+filename_regex+) and specific change regex (+changes_regex+) from the given +categories+ hash.
|
175
|
-
def changes_by_category(categories)
|
178
|
+
def changes_by_category(categories = [])
|
176
179
|
all_changed_files.each_with_object(Hash.new { |h, k| h[k] = [] }) do |file, hash|
|
177
180
|
categories_for_file(file, categories).each { |category| hash[category] << file }
|
178
181
|
end
|
@@ -184,7 +187,7 @@ module Danger
|
|
184
187
|
#
|
185
188
|
# @return [Gitlab::Dangerfiles::Changes] a +Gitlab::Dangerfiles::Changes+ object that represents the changes of an MR
|
186
189
|
# using filename regex (+filename_regex+) and specific change regex (+changes_regex+) from the given +categories+ hash.
|
187
|
-
def changes(categories)
|
190
|
+
def changes(categories = [])
|
188
191
|
Gitlab::Dangerfiles::Changes.new([]).tap do |changes|
|
189
192
|
added_files.each do |file|
|
190
193
|
categories_for_file(file, categories).each { |category| changes << Gitlab::Dangerfiles::Change.new(file, :added, category) }
|
@@ -209,14 +212,17 @@ module Danger
|
|
209
212
|
end
|
210
213
|
|
211
214
|
# @param filename [String] A file name.
|
212
|
-
# @param
|
213
|
-
#
|
214
|
-
#
|
215
|
+
# @param files_to_category [{Regexp => Array<Symbol>}, {Array<Regexp> => Array<Symbol>}] A hash of the form +{ filename_regex => categories, [filename_regex, changes_regex] => categories }+.
|
216
|
+
# +filename_regex+ is the regex pattern to match file names. +changes_regex+ is the regex pattern to
|
217
|
+
# match changed lines in files that match +filename_regex+
|
215
218
|
#
|
216
219
|
# @return [Array<Symbol>] the categories a file is in, e.g., +[:frontend]+, +[:backend]+, or +%i[frontend tooling]+
|
217
220
|
# using filename regex (+filename_regex+) and specific change regex (+changes_regex+) from the given +categories+ hash.
|
218
|
-
def categories_for_file(filename,
|
219
|
-
|
221
|
+
def categories_for_file(filename, files_to_category = [])
|
222
|
+
files_to_category = Array(files_to_category).compact
|
223
|
+
files_to_category = helper.config.files_to_category if files_to_category.empty?
|
224
|
+
|
225
|
+
_, categories = files_to_category.find do |key, _|
|
220
226
|
filename_regex, changes_regex = Array(key)
|
221
227
|
|
222
228
|
found = filename_regex.match?(filename)
|
@@ -33,7 +33,10 @@ module Danger
|
|
33
33
|
# @param timezone_experiment [Boolean] Whether to select reviewers based in timezone or not.
|
34
34
|
#
|
35
35
|
# @return [Array<Spin>]
|
36
|
-
def spin(project, categories = [nil], timezone_experiment: false)
|
36
|
+
def spin(project = nil, categories = [nil], timezone_experiment: false)
|
37
|
+
project = (project || helper.config.project_name).downcase
|
38
|
+
categories = categories.map { |category| category&.downcase }
|
39
|
+
|
37
40
|
spins = categories.sort_by(&:to_s).map do |category|
|
38
41
|
including_timezone = INCLUDE_TIMEZONE_FOR_CATEGORY.fetch(category, timezone_experiment)
|
39
42
|
|
@@ -75,6 +78,8 @@ module Danger
|
|
75
78
|
# Fetch an already picked maintainer, or pick one otherwise
|
76
79
|
spin.maintainer = backend_spin&.maintainer || frontend_spin&.maintainer || spin_for_category(project, :backend, timezone_experiment: including_timezone).maintainer
|
77
80
|
end
|
81
|
+
when :integrations_be, :integrations_fe
|
82
|
+
spin.optional_role = :maintainer
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
PROJECT_NAME = helper.config.project_name
|
4
|
+
|
5
|
+
MESSAGE = <<MARKDOWN
|
6
|
+
## Reviewer roulette
|
7
|
+
|
8
|
+
Changes that require review have been detected! A merge request is normally
|
9
|
+
reviewed by both a reviewer and a maintainer in its primary category and by a
|
10
|
+
maintainer in all other categories.
|
11
|
+
MARKDOWN
|
12
|
+
|
13
|
+
TABLE_MARKDOWN = <<MARKDOWN
|
14
|
+
|
15
|
+
To spread load more evenly across eligible reviewers, Danger has picked a candidate for each
|
16
|
+
review slot. Feel free to
|
17
|
+
[override these selections](https://about.gitlab.com/handbook/engineering/projects/##{PROJECT_NAME})
|
18
|
+
if you think someone else would be better-suited.
|
19
|
+
|
20
|
+
To read more on how to use the reviewer roulette, please take a look at the
|
21
|
+
[Engineering workflow](https://about.gitlab.com/handbook/engineering/workflow/#basics)
|
22
|
+
and [code review guidelines](https://docs.gitlab.com/ee/development/code_review.html).
|
23
|
+
|
24
|
+
Once you've decided who will review this merge request, mention them as you
|
25
|
+
normally would! Danger does not automatically notify them for you.
|
26
|
+
|
27
|
+
| Reviewer | Maintainer |
|
28
|
+
| -------- | ---------- |
|
29
|
+
MARKDOWN
|
30
|
+
|
31
|
+
def note_for_spins_role(spins, role)
|
32
|
+
spins.each do |spin|
|
33
|
+
note = note_for_spin_role(spin, role)
|
34
|
+
|
35
|
+
return note if note
|
36
|
+
end
|
37
|
+
|
38
|
+
'No %{role} available' % { role: role }
|
39
|
+
end
|
40
|
+
|
41
|
+
def note_for_spin_role(spin, role)
|
42
|
+
spin.public_send(role)&.markdown_name(author: roulette.team_mr_author)
|
43
|
+
end
|
44
|
+
|
45
|
+
def markdown_row_for_spins(spins_array)
|
46
|
+
reviewer_note = note_for_spins_role(spins_array, :reviewer)
|
47
|
+
maintainer_note = note_for_spins_role(spins_array, :maintainer)
|
48
|
+
|
49
|
+
"#{reviewer_note} | #{maintainer_note} |"
|
50
|
+
end
|
51
|
+
|
52
|
+
if helper.changes.any?
|
53
|
+
random_roulette_spins = roulette.spin
|
54
|
+
|
55
|
+
rows = random_roulette_spins.map do |spin|
|
56
|
+
markdown_row_for_spins([spin])
|
57
|
+
end
|
58
|
+
|
59
|
+
markdown(MESSAGE)
|
60
|
+
markdown(TABLE_MARKDOWN + rows.join("\n")) unless rows.empty?
|
61
|
+
end
|
@@ -82,7 +82,7 @@ module Gitlab
|
|
82
82
|
return false if subject.empty?
|
83
83
|
return false if ("A".."Z").cover?(subject[0])
|
84
84
|
|
85
|
-
first_char = subject.sub(/\A(\[
|
85
|
+
first_char = subject.sub(/\A(\[[^\]]+\]|[^:\s]+:)\s/, "")[0]
|
86
86
|
first_char_downcased = first_char.downcase
|
87
87
|
return true unless ("a".."z").cover?(first_char_downcased)
|
88
88
|
|
@@ -3,6 +3,16 @@
|
|
3
3
|
module Gitlab
|
4
4
|
module Dangerfiles
|
5
5
|
class Config
|
6
|
+
# @!attribute project_name
|
7
|
+
# @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
|
+
attr_accessor :project_name
|
9
|
+
|
10
|
+
# @!attribute files_to_category
|
11
|
+
# @return [{Regexp => Array<Symbol>}, {Array<Regexp> => Array<Symbol>}] A hash of the form +{ filename_regex => categories, [filename_regex, changes_regex] => categories }+.
|
12
|
+
# +filename_regex+ is the regex pattern to match file names. +changes_regex+ is the regex pattern to
|
13
|
+
# match changed lines in files that match +filename_regex+. Used in `helper.changes_by_category`, `helper.changes`, and `helper.categories_for_file`.
|
14
|
+
attr_accessor :files_to_category
|
15
|
+
|
6
16
|
# @!attribute code_size_thresholds
|
7
17
|
# @return [{ high: Integer, medium: Integer }] a hash of the form +{ high: 42, medium: 12 }+ where +:high+ is the lines changed threshold which triggers an error, and +:medium+ is the lines changed threshold which triggers a warning. Also, see +DEFAULT_CHANGES_SIZE_THRESHOLDS+ for the format of the hash.
|
8
18
|
attr_accessor :code_size_thresholds
|
@@ -15,6 +25,8 @@ module Gitlab
|
|
15
25
|
DEFAULT_COMMIT_MESSAGES_MAX_COMMITS_COUNT = 10
|
16
26
|
|
17
27
|
def initialize
|
28
|
+
@files_to_category = []
|
29
|
+
@project_name = ENV["CI_PROJECT_NAME"]
|
18
30
|
@code_size_thresholds = DEFAULT_CHANGES_SIZE_THRESHOLDS
|
19
31
|
@max_commits_count = DEFAULT_COMMIT_MESSAGES_MAX_COMMITS_COUNT
|
20
32
|
end
|
@@ -12,7 +12,7 @@ module Gitlab
|
|
12
12
|
@name = options["name"]
|
13
13
|
@markdown_name = options["markdown_name"]
|
14
14
|
@role = options["role"]
|
15
|
-
@projects = options["projects"]
|
15
|
+
@projects = process_projects(options["projects"])
|
16
16
|
@available = options["available"]
|
17
17
|
@hungry = options["hungry"]
|
18
18
|
@reduced_capacity = options["reduced_capacity"]
|
@@ -49,6 +49,18 @@ module Gitlab
|
|
49
49
|
has_capability?(project, category, :maintainer, labels)
|
50
50
|
end
|
51
51
|
|
52
|
+
def integrations_be?(project, category, labels)
|
53
|
+
return false unless category == :integrations_be
|
54
|
+
|
55
|
+
has_capability?(project, category, :reviewer, labels)
|
56
|
+
end
|
57
|
+
|
58
|
+
def integrations_fe?(project, category, labels)
|
59
|
+
return false unless category == :integrations_fe
|
60
|
+
|
61
|
+
has_capability?(project, category, :reviewer, labels)
|
62
|
+
end
|
63
|
+
|
52
64
|
def markdown_name(author: nil)
|
53
65
|
"#{@markdown_name} (#{utc_offset_text(author)})"
|
54
66
|
end
|
@@ -67,6 +79,14 @@ module Gitlab
|
|
67
79
|
|
68
80
|
private
|
69
81
|
|
82
|
+
def process_projects(projects)
|
83
|
+
return nil unless projects
|
84
|
+
|
85
|
+
projects.each_with_object({}) do |(project, capabilities), all|
|
86
|
+
all[project.downcase] = Array(capabilities).map(&:downcase)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
70
90
|
def utc_offset_text(author = nil)
|
71
91
|
offset_text = if floored_offset_hours >= 0
|
72
92
|
"UTC+#{floored_offset_hours}"
|
@@ -96,11 +116,16 @@ module Gitlab
|
|
96
116
|
|
97
117
|
area && labels.any?("devops::#{area.downcase}") if kind == :reviewer
|
98
118
|
when :tooling, :engineering_productivity # Deprecated as of 2.3.0 in favor of tooling
|
99
|
-
return
|
100
|
-
return
|
101
|
-
|
102
|
-
|
103
|
-
|
119
|
+
return true if capabilities(project).include?("#{kind} #{category}")
|
120
|
+
return false if kind == :maintainer
|
121
|
+
|
122
|
+
capabilities(project).include?("#{kind} backend") # fallback to backend reviewer
|
123
|
+
when :integrations_be
|
124
|
+
kind == :reviewer &&
|
125
|
+
role.match?(/Backend Engineer.+Ecosystem:Integrations/)
|
126
|
+
when :integrations_fe
|
127
|
+
kind == :reviewer &&
|
128
|
+
role.match?(/Frontend Engineer.+Ecosystem:Integrations/)
|
104
129
|
when nil
|
105
130
|
capabilities(project).include?("#{kind}")
|
106
131
|
else
|
data/lib/gitlab/dangerfiles.rb
CHANGED
@@ -13,8 +13,24 @@ module Gitlab
|
|
13
13
|
commit_messages
|
14
14
|
].freeze
|
15
15
|
CI_ONLY_RULES = %w[
|
16
|
+
simple_roulette
|
16
17
|
].freeze
|
17
18
|
|
19
|
+
# Utility method to construct a [Gitlab::Dangerfiles::Engine] instance,
|
20
|
+
# which is yielded to the given block.
|
21
|
+
#
|
22
|
+
# @param dangerfile [Danger::Dangerfile] A +Danger::Dangerfile+ object.
|
23
|
+
# @param project_name An option string to set the project name. Defaults to +ENV['CI_PROJECT_NAME']+.
|
24
|
+
#
|
25
|
+
# @return [Gitlab::Dangerfiles::Engine]
|
26
|
+
def self.for_project(dangerfile, project_name = nil)
|
27
|
+
Engine.new(dangerfile).tap do |engine|
|
28
|
+
engine.config.project_name = project_name if project_name
|
29
|
+
|
30
|
+
yield engine
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
18
34
|
# This class provides utility methods to import plugins and dangerfiles easily.
|
19
35
|
class Engine
|
20
36
|
# @param dangerfile [Danger::Dangerfile] A +Danger::Dangerfile+ object.
|
@@ -32,35 +48,66 @@ module Gitlab
|
|
32
48
|
#
|
33
49
|
# @example
|
34
50
|
# # In your main Dangerfile:
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# dangerfiles.import_plugins
|
51
|
+
# Gitlab::Dangerfiles.for_project(self) do |dangerfiles|
|
52
|
+
# dangerfiles.import_plugins
|
53
|
+
# end
|
39
54
|
def import_plugins
|
40
55
|
danger_plugin.import_plugin(File.expand_path("../danger/plugins/*.rb", __dir__))
|
41
56
|
end
|
42
57
|
|
43
58
|
# Import available Dangerfiles.
|
44
59
|
#
|
60
|
+
# @deprecated
|
45
61
|
# @param rules [Symbol, Array<String>] Can be either +:all+ (default) to import all rules,
|
46
62
|
# or an array of rules.
|
47
63
|
# Available rules are: +changes_size+.
|
48
64
|
#
|
49
|
-
# @
|
50
|
-
#
|
51
|
-
# dangerfiles = Gitlab::Dangerfiles::Engine.new(self)
|
65
|
+
# @param only [Symbol, Array<String>] An array of rules to import (defaults to all rules).
|
66
|
+
# Available rules are: +changes_size+.
|
52
67
|
#
|
53
|
-
#
|
54
|
-
#
|
68
|
+
# @param except [Symbol, Array<String>] An array of rules to not import (defaults to []).
|
69
|
+
# Available rules are: +changes_size+.
|
55
70
|
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
|
59
|
-
|
71
|
+
# @example
|
72
|
+
# # In your main Dangerfile:
|
73
|
+
# Gitlab::Dangerfiles.for_project(self) do |dangerfiles|
|
74
|
+
# # Import all rules
|
75
|
+
# dangerfiles.import_dangerfiles
|
76
|
+
# # Or import only a subset of rules
|
77
|
+
# dangerfiles.import_dangerfiles(only: %w[changes_size])
|
78
|
+
# # Or import all rules except a subset of rules
|
79
|
+
# dangerfiles.import_dangerfiles(except: %w[commit_messages])
|
80
|
+
# # Or import only a subset of rules, except a subset of rules
|
81
|
+
# dangerfiles.import_dangerfiles(only: %w[changes_size], except: %w[commit_messages])
|
82
|
+
# end
|
83
|
+
def import_dangerfiles(rules: nil, only: nil, except: [])
|
84
|
+
puts "The `:rules` parameter is deprecated in favor of `:only`." unless rules.nil?
|
85
|
+
|
86
|
+
only ||= EXISTING_RULES if rules == :all
|
87
|
+
only ||= rules || EXISTING_RULES
|
88
|
+
|
89
|
+
filtered_rules(only, except).each do |rule|
|
60
90
|
danger_plugin.import_dangerfile(path: File.join(RULES_DIR, rule))
|
61
91
|
end
|
62
92
|
end
|
63
93
|
|
94
|
+
# Proxy method to +helper_plugin.config+.
|
95
|
+
def config
|
96
|
+
helper_plugin.config
|
97
|
+
end
|
98
|
+
|
99
|
+
# Imports all default plugins and rules.
|
100
|
+
#
|
101
|
+
# @example
|
102
|
+
# # In your main Dangerfile:
|
103
|
+
# Gitlab::Dangerfiles.for_project(self) do |dangerfiles|
|
104
|
+
# dangerfiles.import_defaults
|
105
|
+
# end
|
106
|
+
def import_defaults
|
107
|
+
import_plugins
|
108
|
+
import_dangerfiles
|
109
|
+
end
|
110
|
+
|
64
111
|
private
|
65
112
|
|
66
113
|
attr_reader :dangerfile
|
@@ -71,10 +118,8 @@ module Gitlab
|
|
71
118
|
helper_plugin.ci? ? LOCAL_RULES | CI_ONLY_RULES : LOCAL_RULES
|
72
119
|
end
|
73
120
|
|
74
|
-
def filtered_rules(
|
75
|
-
|
76
|
-
|
77
|
-
Array(rules).map(&:to_s) & EXISTING_RULES & allowed_rules
|
121
|
+
def filtered_rules(only, except)
|
122
|
+
(Array(only).map(&:to_s) & EXISTING_RULES & allowed_rules) - except
|
78
123
|
end
|
79
124
|
|
80
125
|
def danger_plugin
|
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: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitLab
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: danger-gitlab
|
@@ -131,10 +131,14 @@ extra_rdoc_files: []
|
|
131
131
|
files:
|
132
132
|
- ".gitignore"
|
133
133
|
- ".gitlab-ci.yml"
|
134
|
+
- ".gitlab/CODEOWNERS"
|
135
|
+
- ".gitlab/changelog_config.yml"
|
134
136
|
- ".gitlab/merge_request_templates/Release.md"
|
135
137
|
- ".rspec"
|
136
138
|
- ".yardopts"
|
137
139
|
- CODE_OF_CONDUCT.md
|
140
|
+
- CONTRIBUTING.md
|
141
|
+
- Dangerfile
|
138
142
|
- Gemfile
|
139
143
|
- Guardfile
|
140
144
|
- LICENSE.txt
|
@@ -149,6 +153,7 @@ files:
|
|
149
153
|
- lib/danger/plugins/roulette.rb
|
150
154
|
- lib/danger/rules/changes_size/Dangerfile
|
151
155
|
- lib/danger/rules/commit_messages/Dangerfile
|
156
|
+
- lib/danger/rules/simple_roulette/Dangerfile
|
152
157
|
- lib/gitlab-dangerfiles.rb
|
153
158
|
- lib/gitlab/Dangerfile
|
154
159
|
- lib/gitlab/dangerfiles.rb
|