gitlab-dangerfiles 3.4.0 → 3.4.1

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: 1d8182a9895b7c4ce505c6c31271030222ef4e3eefaee2569edccfe1a3ce892a
4
- data.tar.gz: 32f4cd7af125f0cf2a96f7bb000eb725f2c58a7a5576349fe3905dd93302c53d
3
+ metadata.gz: 17495e36a06253d291cf69ea61fd426ba3541738591873cfdef64e2c9132e8ee
4
+ data.tar.gz: 5e690f454e356ae1dd7e372ae16d9d8b99b32e1450a48560fe359dfcad20eab9
5
5
  SHA512:
6
- metadata.gz: fdb2baf7afe55ad315269cf4231efa717099dbb931ca5a6f3d7b268d9551b337fa5265627b8e134d739383a4cf72f5bf68588a19010bd4327c04297baaf3a49f
7
- data.tar.gz: bdfa7d3753215241101362459e869cf53b1b4f141e96c58f9a31aac02a1dcb4aadae2caf98115704e8814664f0b74c466781aafe8da02d8f0bd00793857ccfb8
6
+ metadata.gz: f96558f5954dea10cf802d32003045dcdcb6bccaa00c34b4079a654a275ec8dcb980ca84bf8116d87db1e0dc8a5e85a54b07ec05dc2dbcab4b2696e3e1532173
7
+ data.tar.gz: b112119bfbbff88bb66966bed0e5ee0cd32369b2eae89507e17f9e602a8c0a987bbd423aa1a4ed089479c1d9f6842f523db76e83c887676c9387cbd6da4db3e3
data/Gemfile CHANGED
@@ -7,6 +7,10 @@ gem "rake", "~> 12.0"
7
7
  gem "guard-rspec"
8
8
  gem "yard"
9
9
 
10
+ group :development do
11
+ gem "lefthook", require: false
12
+ end
13
+
10
14
  group :test do
11
15
  gem "pry-byebug", "~> 3.8", require: false
12
16
  end
data/README.md CHANGED
@@ -215,12 +215,19 @@ Latest documentation can be found at <https://www.rubydoc.info/gems/gitlab-dange
215
215
 
216
216
  ## Development
217
217
 
218
+ ### Initial setup
219
+
218
220
  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.
219
221
 
220
222
  To install this gem onto your local machine, run `bundle exec rake install`.
221
223
 
222
224
  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.
223
225
 
226
+ ### Activate lefthook locally
227
+
228
+ ```shell
229
+ lefthook install
230
+ ```
224
231
  ## Contributing
225
232
 
226
233
  Bug reports and merge requests are welcome at https://gitlab.com/gitlab-org/gitlab-dangerfiles. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://gitlab.com/gitlab-org/gitlab-dangerfiles/blob/master/CODE_OF_CONDUCT.md).
data/lefthook.yml ADDED
@@ -0,0 +1,11 @@
1
+ # EXAMPLE USAGE
2
+ # Refer for explanation to following link:
3
+ # https://github.com/evilmartians/lefthook/blob/master/docs/full_guide.md
4
+ #
5
+
6
+ pre-push:
7
+ commands:
8
+ # Runs RUby FOrmatter (rufo)
9
+ rufo:
10
+ run: bundle exec rufo --check .
11
+ glob: '*.rb'
@@ -162,12 +162,44 @@ module Danger
162
162
  end
163
163
  end
164
164
 
165
+ # Spin a reviewer for a particular approval rule
166
+ #
167
+ # @param [Hash] rule of approval
168
+ #
169
+ # @return [Gitlab::Dangerfiles::Teammate]
165
170
  def spin_for_approver(rule)
166
- approvers = rule["eligible_approvers"].map do |approver|
171
+ # This will filter out approvers who are not even reviewers who
172
+ # don't show up in roulette data we're relying on.
173
+ # That's why `filter_map` is used.
174
+ approvers = rule["eligible_approvers"].filter_map do |approver|
167
175
  find_member(approver["username"])
168
176
  end
169
177
 
170
- spin_for_person(approvers)
178
+ spin_for_person(approvers) || spin_for_approver_fallback(rule)
179
+ end
180
+
181
+ # It can be possible that we don't have a valid reviewer for approval.
182
+ # In this case, we sample again without considering:
183
+ #
184
+ # * If they're available
185
+ # * If they're an actual reviewer from roulette data
186
+ #
187
+ # We do this because we strictly require an approval from the approvers.
188
+ #
189
+ # @param [Hash] rule of approval
190
+ #
191
+ # @return [Gitlab::Dangerfiles::Teammate]
192
+ def spin_for_approver_fallback(rule)
193
+ fallback_approvers = rule["eligible_approvers"].map do |approver|
194
+ find_member(approver["username"]) ||
195
+ Gitlab::Dangerfiles::Teammate.new(approver)
196
+ end
197
+
198
+ # Intentionally not using `spin_for_person` to skip `valid_person?`.
199
+ # This should strictly return someone so we don't filter anything,
200
+ # and it's a fallback mechanism which should not happen often that
201
+ # deserves a complex algorithm.
202
+ fallback_approvers.sample(random: random)
171
203
  end
172
204
 
173
205
  def spin_for_category(project, category, timezone_experiment: false)
@@ -10,7 +10,8 @@ module Gitlab
10
10
  @options = options
11
11
  @username = options["username"]
12
12
  @name = options["name"]
13
- @markdown_name = options["markdown_name"]
13
+ @markdown_name = options["markdown_name"] ||
14
+ default_markdown_name(*options.values_at("username", "name"))
14
15
  @role = options["role"]
15
16
  @projects = process_projects(options["projects"])
16
17
  @available = options["available"]
@@ -66,7 +67,7 @@ module Gitlab
66
67
  end
67
68
 
68
69
  def markdown_name(author: nil)
69
- "#{@markdown_name} (#{utc_offset_text(author)})"
70
+ "#{@markdown_name}#{utc_offset_text(author)}"
70
71
  end
71
72
 
72
73
  def local_hour
@@ -83,6 +84,10 @@ module Gitlab
83
84
 
84
85
  private
85
86
 
87
+ def default_markdown_name(username, name)
88
+ "[#{name}](https://gitlab.com/#{username}) (`@#{username}`)"
89
+ end
90
+
86
91
  def process_projects(projects)
87
92
  return nil unless projects
88
93
 
@@ -92,15 +97,19 @@ module Gitlab
92
97
  end
93
98
 
94
99
  def utc_offset_text(author = nil)
100
+ return unless tz_offset_hours
101
+
95
102
  offset_text = if floored_offset_hours >= 0
96
103
  "UTC+#{floored_offset_hours}"
97
104
  else
98
105
  "UTC#{floored_offset_hours}"
99
106
  end
100
107
 
101
- return offset_text unless author
102
-
103
- "#{offset_text}, #{offset_diff_compared_to_author(author)}"
108
+ if author
109
+ " (#{offset_text}, #{offset_diff_compared_to_author(author)})"
110
+ else
111
+ " (#{offset_text})"
112
+ end
104
113
  end
105
114
 
106
115
  def offset_diff_compared_to_author(author)
@@ -1,5 +1,5 @@
1
1
  module Gitlab
2
2
  module Dangerfiles
3
- VERSION = "3.4.0"
3
+ VERSION = "3.4.1"
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.4.0
4
+ version: 3.4.1
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-16 00:00:00.000000000 Z
11
+ date: 2022-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -163,6 +163,7 @@ files:
163
163
  - fixtures/emojis/aliases.json
164
164
  - fixtures/emojis/digests.json
165
165
  - gitlab-dangerfiles.gemspec
166
+ - lefthook.yml
166
167
  - lib/danger/plugins/changelog.rb
167
168
  - lib/danger/plugins/internal/helper.rb
168
169
  - lib/danger/plugins/roulette.rb