gitlab-dangerfiles 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf965c37aaf01dff0630442feecb4fbe6e8d96bb2c9f7f714c631487c9eb894e
4
- data.tar.gz: 720fe1ddfd202e0b199dfbd63fdb360a8a7e58d355182b7055ff0fdebb74c886
3
+ metadata.gz: 1d8182a9895b7c4ce505c6c31271030222ef4e3eefaee2569edccfe1a3ce892a
4
+ data.tar.gz: 32f4cd7af125f0cf2a96f7bb000eb725f2c58a7a5576349fe3905dd93302c53d
5
5
  SHA512:
6
- metadata.gz: 31a832aa516290296662a7949b01a13c7dd47e7c05ad6c6e78cb1f189f2190b99094e97a07875d65f4cb6b5504a8816d1a26aa39a618480899f2026c58c2c311
7
- data.tar.gz: 4f18f92c83494aff49ceec1a05f2b380bd9be7aee17a50a4126ec25c011cfc468a672da200d4a93420d4c47bbec19d6678dc389e083a56945d94d52a58862107
6
+ metadata.gz: fdb2baf7afe55ad315269cf4231efa717099dbb931ca5a6f3d7b268d9551b337fa5265627b8e134d739383a4cf72f5bf68588a19010bd4327c04297baaf3a49f
7
+ data.tar.gz: bdfa7d3753215241101362459e869cf53b1b4f141e96c58f9a31aac02a1dcb4aadae2caf98115704e8814664f0b74c466781aafe8da02d8f0bd00793857ccfb8
@@ -25,6 +25,7 @@ module Danger
25
25
  product_intelligence: '~"product intelligence"',
26
26
  integrations_be: '~"group::integrations" (backend)',
27
27
  integrations_fe: '~"group::integrations" (frontend)',
28
+ "Authentication and Authorization": '~"group::authentication and authorization"',
28
29
  }.freeze
29
30
 
30
31
  # Allows to set specific rule's configuration by passing a block.
@@ -299,6 +300,15 @@ module Danger
299
300
  gitlab_helper.mr_json["target_branch"]
300
301
  end
301
302
 
303
+ # @return [Hash] +{}+ when not in the CI context, and the merge request approval state otherwise.
304
+ def mr_approval_state
305
+ return {} unless ci?
306
+
307
+ gitlab_helper.api.merge_request_approval_state(
308
+ mr_target_project_id, mr_iid
309
+ )
310
+ end
311
+
302
312
  # @return [Boolean] +true+ when not in the CI context, and whether the MR is set to be squashed otherwise.
303
313
  def squash_mr?
304
314
  return true unless ci?
@@ -18,11 +18,20 @@ module Danger
18
18
  Spin = Struct.new(:category, :reviewer, :maintainer, :optional_role, :timezone_experiment)
19
19
  HTTPError = Class.new(StandardError)
20
20
 
21
+ Approval = Struct.new(:category, :spin) do
22
+ def self.from_approval_rule(rule, maintainer)
23
+ category = rule["section"].to_sym
24
+ spin = Spin.new(category, nil, maintainer, :reviewer)
25
+
26
+ new(category, spin)
27
+ end
28
+ end
29
+
21
30
  # Finds the +Gitlab::Dangerfiles::Teammate+ object whose username matches the MR author username.
22
31
  #
23
32
  # @return [Gitlab::Dangerfiles::Teammate]
24
33
  def team_mr_author
25
- @team_mr_author ||= company_members.find { |person| person.username == helper.mr_author }
34
+ @team_mr_author ||= find_member(helper.mr_author)
26
35
  end
27
36
 
28
37
  # Assigns GitLab team members to be reviewer and maintainer
@@ -87,6 +96,18 @@ module Danger
87
96
  spins
88
97
  end
89
98
 
99
+ def required_approvals
100
+ approval_rules = helper.mr_approval_state["rules"]
101
+
102
+ return [] unless approval_rules
103
+
104
+ approval_rules.filter_map do |rule|
105
+ rule["rule_type"] == "code_owner" &&
106
+ rule["approvals_required"] > 0 &&
107
+ Approval.from_approval_rule(rule, spin_for_approver(rule))
108
+ end
109
+ end
110
+
90
111
  private
91
112
 
92
113
  # @param [Gitlab::Dangerfiles::Teammate] person
@@ -115,8 +136,8 @@ module Danger
115
136
  team_mr_author&.integrations_fe?(project, category, helper.mr_labels)
116
137
  end
117
138
 
118
- def new_random(seed)
119
- Random.new(Digest::MD5.hexdigest(seed).to_i(16))
139
+ def random
140
+ @random ||= Random.new(Digest::MD5.hexdigest(helper.mr_source_branch).to_i(16))
120
141
  end
121
142
 
122
143
  def spin_role_for_category(team, role, project, category)
@@ -131,7 +152,7 @@ module Danger
131
152
  # @param [Array<Gitlab::Dangerfiles::Teammate>] people
132
153
  #
133
154
  # @return [Gitlab::Dangerfiles::Teammate]
134
- def spin_for_person(people, random:, timezone_experiment: false)
155
+ def spin_for_person(people, timezone_experiment: false)
135
156
  shuffled_people = people.shuffle(random: random)
136
157
 
137
158
  if timezone_experiment
@@ -141,6 +162,14 @@ module Danger
141
162
  end
142
163
  end
143
164
 
165
+ def spin_for_approver(rule)
166
+ approvers = rule["eligible_approvers"].map do |approver|
167
+ find_member(approver["username"])
168
+ end
169
+
170
+ spin_for_person(approvers)
171
+ end
172
+
144
173
  def spin_for_category(project, category, timezone_experiment: false)
145
174
  team = project_team(project)
146
175
  reviewers, traintainers, maintainers =
@@ -148,13 +177,11 @@ module Danger
148
177
  spin_role_for_category(team, role, project, category)
149
178
  end
150
179
 
151
- random = new_random(helper.mr_source_branch)
152
-
153
180
  weighted_reviewers = Gitlab::Dangerfiles::Weightage::Reviewers.new(reviewers, traintainers).execute
154
181
  weighted_maintainers = Gitlab::Dangerfiles::Weightage::Maintainers.new(maintainers).execute
155
182
 
156
- reviewer = spin_for_person(weighted_reviewers, random: random, timezone_experiment: timezone_experiment)
157
- maintainer = spin_for_person(weighted_maintainers, random: random, timezone_experiment: timezone_experiment)
183
+ reviewer = spin_for_person(weighted_reviewers, timezone_experiment: timezone_experiment)
184
+ maintainer = spin_for_person(weighted_maintainers, timezone_experiment: timezone_experiment)
158
185
 
159
186
  Spin.new(category, reviewer, maintainer, false, timezone_experiment)
160
187
  end
@@ -187,6 +214,10 @@ module Danger
187
214
  end
188
215
  end
189
216
 
217
+ def find_member(username)
218
+ company_members.find { |person| person.username == username }
219
+ end
220
+
190
221
  # Like +team+, but only returns teammates in the current project, based on
191
222
  # project_name.
192
223
  #
@@ -23,6 +23,10 @@ module Gitlab
23
23
  options
24
24
  end
25
25
 
26
+ def inspect
27
+ "#<#{self.class} @username=#{username.inspect}>"
28
+ end
29
+
26
30
  def ==(other)
27
31
  return false unless other.respond_to?(:username)
28
32
 
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "3.3.0"
3
+ VERSION = "3.4.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.3.0
4
+ version: 3.4.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-06-15 00:00:00.000000000 Z
11
+ date: 2022-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake