declarative_policy 1.0.0 → 2.0.1
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/CHANGELOG.md +20 -0
- data/CONTRIBUTING.md +41 -0
- data/LICENSE.txt +4 -1
- data/README.md +81 -12
- data/{declarative_policy.gemspec → declarative-policy.gemspec} +23 -8
- data/doc/caching.md +299 -1
- data/doc/defining-policies.md +76 -12
- data/doc/optimization.md +277 -0
- data/lib/declarative_policy/base.rb +61 -29
- data/lib/declarative_policy/cache.rb +1 -1
- data/lib/declarative_policy/condition.rb +26 -7
- data/lib/declarative_policy/configuration.rb +7 -1
- data/lib/declarative_policy/delegate_dsl.rb +1 -1
- data/lib/declarative_policy/policy_dsl.rb +2 -2
- data/lib/declarative_policy/preferred_scope.rb +1 -1
- data/lib/declarative_policy/rule.rb +5 -5
- data/lib/declarative_policy/rule_dsl.rb +1 -1
- data/lib/declarative_policy/runner.rb +58 -26
- data/lib/declarative_policy/version.rb +1 -1
- data/lib/declarative_policy.rb +30 -40
- metadata +117 -26
- data/.gitignore +0 -10
- data/.gitlab-ci.yml +0 -48
- data/.rspec +0 -4
- data/.rubocop.yml +0 -10
- data/Dangerfile +0 -16
- data/Gemfile +0 -24
- data/Gemfile.lock +0 -197
- data/Rakefile +0 -8
- data/danger/plugins/project_helper.rb +0 -58
- data/danger/roulette/Dangerfile +0 -97
data/Gemfile.lock
DELETED
@@ -1,197 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
declarative_policy (1.0.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
abstract_type (0.0.7)
|
10
|
-
activesupport (6.0.3.4)
|
11
|
-
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
-
i18n (>= 0.7, < 2)
|
13
|
-
minitest (~> 5.1)
|
14
|
-
tzinfo (~> 1.1)
|
15
|
-
zeitwerk (~> 2.2, >= 2.2.2)
|
16
|
-
adamantium (0.2.0)
|
17
|
-
ice_nine (~> 0.11.0)
|
18
|
-
memoizable (~> 0.4.0)
|
19
|
-
addressable (2.7.0)
|
20
|
-
public_suffix (>= 2.0.2, < 5.0)
|
21
|
-
ast (2.4.2)
|
22
|
-
binding_ninja (0.2.3)
|
23
|
-
byebug (11.1.3)
|
24
|
-
claide (1.0.3)
|
25
|
-
claide-plugins (0.9.2)
|
26
|
-
cork
|
27
|
-
nap
|
28
|
-
open4 (~> 1.3)
|
29
|
-
coderay (1.1.3)
|
30
|
-
colored2 (3.1.2)
|
31
|
-
concord (0.1.5)
|
32
|
-
adamantium (~> 0.2.0)
|
33
|
-
equalizer (~> 0.0.9)
|
34
|
-
concurrent-ruby (1.1.8)
|
35
|
-
cork (0.3.0)
|
36
|
-
colored2 (~> 3.1)
|
37
|
-
danger (8.2.3)
|
38
|
-
claide (~> 1.0)
|
39
|
-
claide-plugins (>= 0.9.2)
|
40
|
-
colored2 (~> 3.1)
|
41
|
-
cork (~> 0.1)
|
42
|
-
faraday (>= 0.9.0, < 2.0)
|
43
|
-
faraday-http-cache (~> 2.0)
|
44
|
-
git (~> 1.7)
|
45
|
-
kramdown (~> 2.3)
|
46
|
-
kramdown-parser-gfm (~> 1.0)
|
47
|
-
no_proxy_fix
|
48
|
-
octokit (~> 4.7)
|
49
|
-
terminal-table (>= 1, < 4)
|
50
|
-
danger-gitlab (8.0.0)
|
51
|
-
danger
|
52
|
-
gitlab (~> 4.2, >= 4.2.0)
|
53
|
-
diff-lcs (1.4.4)
|
54
|
-
equalizer (0.0.11)
|
55
|
-
faraday (1.1.0)
|
56
|
-
multipart-post (>= 1.2, < 3)
|
57
|
-
ruby2_keywords
|
58
|
-
faraday-http-cache (2.2.0)
|
59
|
-
faraday (>= 0.8)
|
60
|
-
git (1.7.0)
|
61
|
-
rchardet (~> 1.8)
|
62
|
-
gitlab (4.17.0)
|
63
|
-
httparty (~> 0.18)
|
64
|
-
terminal-table (~> 1.5, >= 1.5.1)
|
65
|
-
gitlab-dangerfiles (1.1.0)
|
66
|
-
danger-gitlab
|
67
|
-
gitlab-styles (6.1.0)
|
68
|
-
rubocop (~> 0.91, >= 0.91.1)
|
69
|
-
rubocop-gitlab-security (~> 0.1.1)
|
70
|
-
rubocop-performance (~> 1.9.2)
|
71
|
-
rubocop-rails (~> 2.9)
|
72
|
-
rubocop-rspec (~> 1.44)
|
73
|
-
httparty (0.18.1)
|
74
|
-
mime-types (~> 3.0)
|
75
|
-
multi_xml (>= 0.5.2)
|
76
|
-
i18n (1.8.9)
|
77
|
-
concurrent-ruby (~> 1.0)
|
78
|
-
ice_nine (0.11.2)
|
79
|
-
kramdown (2.3.1)
|
80
|
-
rexml
|
81
|
-
kramdown-parser-gfm (1.1.0)
|
82
|
-
kramdown (~> 2.0)
|
83
|
-
memoizable (0.4.2)
|
84
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
85
|
-
method_source (1.0.0)
|
86
|
-
mime-types (3.3.1)
|
87
|
-
mime-types-data (~> 3.2015)
|
88
|
-
mime-types-data (3.2020.1104)
|
89
|
-
minitest (5.14.3)
|
90
|
-
multi_xml (0.6.0)
|
91
|
-
multipart-post (2.1.1)
|
92
|
-
nap (1.1.0)
|
93
|
-
no_proxy_fix (0.1.2)
|
94
|
-
octokit (4.20.0)
|
95
|
-
faraday (>= 0.9)
|
96
|
-
sawyer (~> 0.8.0, >= 0.5.3)
|
97
|
-
open4 (1.3.4)
|
98
|
-
parallel (1.20.1)
|
99
|
-
parser (3.0.0.0)
|
100
|
-
ast (~> 2.4.1)
|
101
|
-
proc_to_ast (0.1.0)
|
102
|
-
coderay
|
103
|
-
parser
|
104
|
-
unparser
|
105
|
-
procto (0.0.3)
|
106
|
-
pry (0.13.1)
|
107
|
-
coderay (~> 1.1)
|
108
|
-
method_source (~> 1.0)
|
109
|
-
pry-byebug (3.9.0)
|
110
|
-
byebug (~> 11.0)
|
111
|
-
pry (~> 0.13.0)
|
112
|
-
public_suffix (4.0.6)
|
113
|
-
rack (2.2.3)
|
114
|
-
rainbow (3.0.0)
|
115
|
-
rake (12.3.3)
|
116
|
-
rchardet (1.8.0)
|
117
|
-
regexp_parser (1.8.2)
|
118
|
-
rexml (3.2.4)
|
119
|
-
rspec (3.10.0)
|
120
|
-
rspec-core (~> 3.10.0)
|
121
|
-
rspec-expectations (~> 3.10.0)
|
122
|
-
rspec-mocks (~> 3.10.0)
|
123
|
-
rspec-core (3.10.1)
|
124
|
-
rspec-support (~> 3.10.0)
|
125
|
-
rspec-expectations (3.10.1)
|
126
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
127
|
-
rspec-support (~> 3.10.0)
|
128
|
-
rspec-mocks (3.10.2)
|
129
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
130
|
-
rspec-support (~> 3.10.0)
|
131
|
-
rspec-parameterized (0.4.2)
|
132
|
-
binding_ninja (>= 0.2.3)
|
133
|
-
parser
|
134
|
-
proc_to_ast
|
135
|
-
rspec (>= 2.13, < 4)
|
136
|
-
unparser
|
137
|
-
rspec-support (3.10.2)
|
138
|
-
rubocop (0.93.1)
|
139
|
-
parallel (~> 1.10)
|
140
|
-
parser (>= 2.7.1.5)
|
141
|
-
rainbow (>= 2.2.2, < 4.0)
|
142
|
-
regexp_parser (>= 1.8)
|
143
|
-
rexml
|
144
|
-
rubocop-ast (>= 0.6.0)
|
145
|
-
ruby-progressbar (~> 1.7)
|
146
|
-
unicode-display_width (>= 1.4.0, < 2.0)
|
147
|
-
rubocop-ast (1.4.1)
|
148
|
-
parser (>= 2.7.1.5)
|
149
|
-
rubocop-gitlab-security (0.1.1)
|
150
|
-
rubocop (>= 0.51)
|
151
|
-
rubocop-performance (1.9.2)
|
152
|
-
rubocop (>= 0.90.0, < 2.0)
|
153
|
-
rubocop-ast (>= 0.4.0)
|
154
|
-
rubocop-rails (2.9.1)
|
155
|
-
activesupport (>= 4.2.0)
|
156
|
-
rack (>= 1.1)
|
157
|
-
rubocop (>= 0.90.0, < 2.0)
|
158
|
-
rubocop-rspec (1.44.1)
|
159
|
-
rubocop (~> 0.87)
|
160
|
-
rubocop-ast (>= 0.7.1)
|
161
|
-
ruby-progressbar (1.11.0)
|
162
|
-
ruby2_keywords (0.0.2)
|
163
|
-
sawyer (0.8.2)
|
164
|
-
addressable (>= 2.3.5)
|
165
|
-
faraday (> 0.8, < 2.0)
|
166
|
-
terminal-table (1.8.0)
|
167
|
-
unicode-display_width (~> 1.1, >= 1.1.1)
|
168
|
-
thread_safe (0.3.6)
|
169
|
-
tzinfo (1.2.9)
|
170
|
-
thread_safe (~> 0.1)
|
171
|
-
unicode-display_width (1.7.0)
|
172
|
-
unparser (0.4.7)
|
173
|
-
abstract_type (~> 0.0.7)
|
174
|
-
adamantium (~> 0.2.0)
|
175
|
-
concord (~> 0.1.5)
|
176
|
-
diff-lcs (~> 1.3)
|
177
|
-
equalizer (~> 0.0.9)
|
178
|
-
parser (>= 2.6.5)
|
179
|
-
procto (~> 0.0.2)
|
180
|
-
zeitwerk (2.4.2)
|
181
|
-
|
182
|
-
PLATFORMS
|
183
|
-
ruby
|
184
|
-
|
185
|
-
DEPENDENCIES
|
186
|
-
activesupport (>= 6.0)
|
187
|
-
declarative_policy!
|
188
|
-
gitlab-dangerfiles (~> 1.1.0)
|
189
|
-
gitlab-styles (~> 6.1.0)
|
190
|
-
pry-byebug
|
191
|
-
rake (~> 12.0)
|
192
|
-
rspec (~> 3.0)
|
193
|
-
rspec-parameterized
|
194
|
-
rubocop
|
195
|
-
|
196
|
-
BUNDLED WITH
|
197
|
-
2.1.4
|
data/Rakefile
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Danger
|
4
|
-
# Project specific configuration
|
5
|
-
class ProjectHelper < ::Danger::Plugin
|
6
|
-
LOCAL_RULES ||= %w[
|
7
|
-
changelog
|
8
|
-
documentation
|
9
|
-
].freeze
|
10
|
-
|
11
|
-
CI_ONLY_RULES ||= %w[
|
12
|
-
roulette
|
13
|
-
].freeze
|
14
|
-
|
15
|
-
MESSAGE_PREFIX = '==>'
|
16
|
-
|
17
|
-
# First-match win, so be sure to put more specific regex at the top...
|
18
|
-
# rubocop: disable Style/RegexpLiteral
|
19
|
-
CATEGORIES = {
|
20
|
-
%r{\A(\.gitlab-ci\.yml\z|\.gitlab/ci)} => :engineering_productivity,
|
21
|
-
%r{\Alefthook.yml\z} => :engineering_productivity,
|
22
|
-
%r{\A\.editorconfig\z} => :engineering_productivity,
|
23
|
-
%r{Dangerfile\z} => :engineering_productivity,
|
24
|
-
%r{\A(danger/|tooling/danger/)} => :engineering_productivity,
|
25
|
-
%r{\A?scripts/} => :engineering_productivity,
|
26
|
-
%r{\Atooling/} => :engineering_productivity,
|
27
|
-
%r{(CODEOWNERS)} => :engineering_productivity,
|
28
|
-
%r{\A(Gemfile|Gemfile.lock|Rakefile)\z} => :backend,
|
29
|
-
%r{\A\.rubocop((_manual)?_todo)?\.yml\z} => :backend,
|
30
|
-
%r{\.rb\z} => :backend,
|
31
|
-
%r{(
|
32
|
-
\.(md|txt)\z |
|
33
|
-
\.markdownlint\.json
|
34
|
-
)}x => :docs
|
35
|
-
}.freeze
|
36
|
-
# rubocop: enable Style/RegexpLiteral
|
37
|
-
|
38
|
-
def changes_by_category
|
39
|
-
helper.changes_by_category(CATEGORIES)
|
40
|
-
end
|
41
|
-
|
42
|
-
def changes
|
43
|
-
helper.changes(CATEGORIES)
|
44
|
-
end
|
45
|
-
|
46
|
-
def rule_names
|
47
|
-
helper.ci? ? LOCAL_RULES | CI_ONLY_RULES : LOCAL_RULES
|
48
|
-
end
|
49
|
-
|
50
|
-
def project_name
|
51
|
-
# 'declarative-policy'
|
52
|
-
# TODO: roulette uses the project name to find reviewers, but the gitlab team
|
53
|
-
# directory currently does not have any team members assigned to the declarative-policy
|
54
|
-
# project. We thus are piggybacking on 'gitlab' for now.
|
55
|
-
'gitlab'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
data/danger/roulette/Dangerfile
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'digest/md5'
|
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.
|
10
|
-
MARKDOWN
|
11
|
-
|
12
|
-
CATEGORY_TABLE_HEADER = <<MARKDOWN
|
13
|
-
|
14
|
-
To spread load more evenly across eligible reviewers, Danger has picked a
|
15
|
-
candidate for each review slot, based on their timezone. Feel free to
|
16
|
-
[override these selections](https://about.gitlab.com/handbook/engineering/projects/#gitlab) if
|
17
|
-
you think someone else would be better-suited or use the
|
18
|
-
[GitLab Review Workload Dashboard](https://gitlab-org.gitlab.io/gitlab-roulette/) to find other
|
19
|
-
available reviewers.
|
20
|
-
|
21
|
-
To read more on how to use the reviewer roulette, please take a look at the
|
22
|
-
[Engineering workflow](https://about.gitlab.com/handbook/engineering/workflow/#basics) and
|
23
|
-
[code review guidelines](https://docs.gitlab.com/ee/development/code_review.html). You may
|
24
|
-
consider assigning a reviewer or maintainer who is
|
25
|
-
a [domain expert](https://about.gitlab.com/handbook/engineering/projects/#gitlab) for
|
26
|
-
the `DeclarativePolicy` library.
|
27
|
-
|
28
|
-
Once you've decided who will review this merge request, assign them as a reviewer!
|
29
|
-
Danger does not automatically notify them for you.
|
30
|
-
|
31
|
-
| Category | Reviewer | Maintainer |
|
32
|
-
| -------- | -------- | ---------- |
|
33
|
-
MARKDOWN
|
34
|
-
|
35
|
-
UNKNOWN_FILES_MESSAGE = <<MARKDOWN
|
36
|
-
|
37
|
-
These files couldn't be categorised, so Danger was unable to suggest a reviewer.
|
38
|
-
Please consider creating a merge request
|
39
|
-
to [add support](https://gitlab.com/gitlab-org/gitlab/blob/master/tooling/danger/project_helper.rb)
|
40
|
-
for them.
|
41
|
-
MARKDOWN
|
42
|
-
|
43
|
-
OPTIONAL_REVIEW_TEMPLATE = '%{role} review is optional for %{category}'
|
44
|
-
NOT_AVAILABLE_TEMPLATE = 'No %{role} available'
|
45
|
-
|
46
|
-
def note_for_spins_role(spins, role)
|
47
|
-
spins.each do |spin|
|
48
|
-
note = note_for_spin_role(spin, role)
|
49
|
-
|
50
|
-
return note if note
|
51
|
-
end
|
52
|
-
|
53
|
-
format(NOT_AVAILABLE_TEMPLATE, role: role)
|
54
|
-
end
|
55
|
-
|
56
|
-
def note_for_spin_role(spin, role)
|
57
|
-
if spin.optional_role == role
|
58
|
-
return format(OPTIONAL_REVIEW_TEMPLATE, role: role.capitalize, category: helper.label_for_category(spin.category))
|
59
|
-
end
|
60
|
-
|
61
|
-
spin.public_send(role)&.markdown_name(author: roulette.team_mr_author) # rubocop:disable GitlabSecurity/PublicSend
|
62
|
-
end
|
63
|
-
|
64
|
-
def markdown_row_for_spins(category, spins_array)
|
65
|
-
reviewer_note = note_for_spins_role(spins_array, :reviewer)
|
66
|
-
maintainer_note = note_for_spins_role(spins_array, :maintainer)
|
67
|
-
|
68
|
-
"| #{helper.label_for_category(category)} | #{reviewer_note} | #{maintainer_note} |"
|
69
|
-
end
|
70
|
-
|
71
|
-
changes = project_helper.changes_by_category
|
72
|
-
|
73
|
-
# Ignore any files that are known but uncategorized. Prompt for any unknown files
|
74
|
-
changes.delete(:none)
|
75
|
-
# To reinstate roulette for documentation, remove this line.
|
76
|
-
changes.delete(:docs)
|
77
|
-
# No special review for changelog needed and changelog was never a label.
|
78
|
-
changes.delete(:changelog)
|
79
|
-
# No special review for feature flags needed.
|
80
|
-
changes.delete(:feature_flag)
|
81
|
-
categories = changes.keys.to_set.delete(:unknown)
|
82
|
-
|
83
|
-
if changes.any?
|
84
|
-
project = project_helper.project_name
|
85
|
-
|
86
|
-
random_roulette_spins = roulette.spin(project, categories, timezone_experiment: false)
|
87
|
-
|
88
|
-
rows = random_roulette_spins.map do |spin|
|
89
|
-
markdown_row_for_spins(spin.category, [spin])
|
90
|
-
end
|
91
|
-
|
92
|
-
markdown(MESSAGE)
|
93
|
-
markdown(CATEGORY_TABLE_HEADER + rows.join("\n")) unless rows.empty?
|
94
|
-
|
95
|
-
unknown = changes.fetch(:unknown, [])
|
96
|
-
markdown(UNKNOWN_FILES_MESSAGE + helper.markdown_list(unknown)) unless unknown.empty?
|
97
|
-
end
|