gitlab-dangerfiles 3.4.0 → 3.4.3

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: '098225565fa51922d5b158fa2da0a4e3aa7420c3fca45e3acee1c3b3cfaa1ba0'
4
+ data.tar.gz: ca80ccfdc03823eff324d59faff1eac19ed1e93798ff0833feef5d7b414c5e45
5
5
  SHA512:
6
- metadata.gz: fdb2baf7afe55ad315269cf4231efa717099dbb931ca5a6f3d7b268d9551b337fa5265627b8e134d739383a4cf72f5bf68588a19010bd4327c04297baaf3a49f
7
- data.tar.gz: bdfa7d3753215241101362459e869cf53b1b4f141e96c58f9a31aac02a1dcb4aadae2caf98115704e8814664f0b74c466781aafe8da02d8f0bd00793857ccfb8
6
+ metadata.gz: cae6d044924941d20f295da7b5b01aa77ba848a5a87c3894e5c9d8e0894499bdfd03425be5412960daa3724eba5dad11f3f3be02ee8dff80e83ca3b503a86f5f
7
+ data.tar.gz: 4903888e704177bb13b9ba3d5a207201ae703bebe047fc4f9f27483f36ba4f0aa5af2c5e5a5d72478c67c51a06319046bb1ba6f6bad52ba14cb18642f178972e
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)
@@ -194,6 +226,10 @@ module Danger
194
226
  def http_get_json(url)
195
227
  rsp = Net::HTTP.get_response(URI.parse(url))
196
228
 
229
+ if rsp.is_a?(Net::HTTPRedirection)
230
+ raise "Redirection detected: #{rsp.header["location"]}"
231
+ end
232
+
197
233
  unless rsp.is_a?(Net::HTTPOK)
198
234
  raise HTTPError, "Failed to read #{url}: #{rsp.code} #{rsp.message}"
199
235
  end
@@ -62,7 +62,7 @@ module Gitlab
62
62
 
63
63
  # @return [Array<String>] an array of the changed files.
64
64
  def files
65
- map(&:file)
65
+ map(&:file).uniq
66
66
  end
67
67
 
68
68
  private
@@ -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.3"
4
4
  end
5
5
  end
@@ -58,7 +58,7 @@ module Gitlab
58
58
  danger_plugin.import_plugin(File.expand_path("../danger/plugins/*.rb", __dir__))
59
59
 
60
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
61
+ puts "Importing plugin at #{path}" if helper_plugin.ci?
62
62
  danger_plugin.import_plugin(path)
63
63
  end
64
64
  end
@@ -87,10 +87,9 @@ module Gitlab
87
87
  return if helper_plugin.release_automation?
88
88
 
89
89
  rules = filtered_rules(only, except)
90
- puts "Running rules: #{rules}\n" if dangerfile.verbose
91
90
 
92
91
  rules.each do |rule, path|
93
- puts "Importing rule #{rule} at #{path}" if dangerfile.verbose
92
+ puts "Importing rule #{rule} at #{path}" if helper_plugin.ci?
94
93
  danger_plugin.import_dangerfile(path: path)
95
94
  end
96
95
  end
@@ -116,45 +115,45 @@ module Gitlab
116
115
 
117
116
  attr_reader :dangerfile
118
117
 
118
+ def filtered_rules(only_rules, except_rules)
119
+ only_rules = Array(only_rules).compact.map(&:to_s)
120
+
121
+ rules = allowed_rules_based_on_context.reject { |rule, _v| except_rules.include?(rule) }
122
+
123
+ if only_rules.any?
124
+ rules.select! { |rule, _v| only_rules.include?(rule) }
125
+ end
126
+
127
+ rules.sort.to_h
128
+ end
129
+
130
+ def allowed_rules_based_on_context
131
+ helper_plugin.ci? ? all_rules : local_rules
132
+ end
133
+
134
+ def all_rules
135
+ all_gem_rules.merge(custom_rules)
136
+ end
137
+
119
138
  def all_gem_rules
120
- @all_gem_rules ||= Dir.glob(File.join(RULES_DIR, "*")).sort.each_with_object({}) do |path, memo|
139
+ @all_gem_rules ||= Dir.glob(File.join(RULES_DIR, "*")).each_with_object({}) do |path, memo|
121
140
  rule_name = File.basename(path)
122
141
  memo[rule_name] = path if File.directory?(path) && File.exist?(File.join(path, "Dangerfile"))
123
142
  end
124
143
  end
125
144
 
126
145
  def custom_rules
127
- @custom_rules ||= Dir.glob(File.expand_path("danger/*", config.project_root)).sort.each_with_object({}) do |path, memo|
146
+ @custom_rules ||= Dir.glob(File.expand_path("danger/*", config.project_root)).each_with_object({}) do |path, memo|
128
147
  rule_name = File.basename(path)
129
148
  memo[rule_name] = path if File.directory?(path) && File.exist?(File.join(path, "Dangerfile"))
130
149
  end
131
150
  end
132
151
 
133
- def all_rules
134
- all_gem_rules.merge(custom_rules)
135
- end
136
-
137
152
  def local_rules
138
153
  ci_only_rules = CI_ONLY_RULES | config.ci_only_rules
139
154
  all_rules.reject { |rule, _v| ci_only_rules.include?(rule) }
140
155
  end
141
156
 
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
156
- end
157
-
158
157
  def danger_plugin
159
158
  @danger_plugin ||= dangerfile.plugins[Danger::DangerfileDangerPlugin]
160
159
  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.3
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-07-07 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