rspec-mergify 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 379b00755c80dfcba26213f7747fd42f2739c39f2cc450e36123e1703b9312f4
4
- data.tar.gz: 979aaf645e9f2ad882dd00f900a5168be6f5c3ff041360e79698860e7be3790d
3
+ metadata.gz: 968b0ced5510f59941eb189080af9e540dc8cd2799757bb16f0dbe746204471e
4
+ data.tar.gz: 307dff0317e1abf576472b0428a1e3f0f8d7f1b1b9257c84ecfd81f0fac9152c
5
5
  SHA512:
6
- metadata.gz: dc0c1dae123ed41a0ca6290ed79d4bcd82ec79989f8d8cf3e232e3e505592bd791d3387435d99721f5c42218839990e609d4d595ba4317e544e3b65255ed14c8
7
- data.tar.gz: 1827d2eefe6a13d8efb9b6e10cc99da36e6e64b842cfee830cc872d687caabb72881b61cdffb496d74e6e8cf91ccfaf44f7bee866f31858fafc8998e23488016
6
+ metadata.gz: 23673868ac2acd11145346748cea2e5c1cae71cb6c55371ad1440a2f9bdf3436ddf0ebaaef9ae2bfd7a56e5d435b67c3f449b3161201becbd3a7b864dea8d2ad
7
+ data.tar.gz: 2d676dd9fc25b6383db1013e42513d5f70208a6796f4fe4fa5544493d123736871b6d7617c9590c7f8fc8fd2fa4ffb99cf1b683c9cf6df0d124c6a8a27822c05
@@ -145,7 +145,6 @@ module Mergify
145
145
  # rubocop:disable Metrics/MethodLength
146
146
  def load_flaky_detector
147
147
  return unless @token && @repo_name
148
- return unless Utils.env_truthy?('_MERGIFY_TEST_NEW_FLAKY_DETECTION')
149
148
 
150
149
  require_relative 'flaky_detection'
151
150
  mode = @base_branch_name ? 'new' : 'unhealthy'
@@ -155,6 +154,10 @@ module Mergify
155
154
  full_repository_name: @repo_name,
156
155
  mode: mode
157
156
  )
157
+ rescue FlakyDetectionDisabledError
158
+ # The repository has not opted into flaky detection, or has no baseline
159
+ # yet. Both are expected; skip without surfacing an error.
160
+ nil
158
161
  rescue StandardError => e
159
162
  @flaky_detector_error_message = "Could not load flaky detector: #{e.message}"
160
163
  end
@@ -8,6 +8,12 @@ require_relative 'utils'
8
8
 
9
9
  module Mergify
10
10
  module RSpec
11
+ # Signals that flaky detection must not run for this session, and that this
12
+ # is expected rather than a failure: the repository has not opted in (the
13
+ # server responds with 404) or there is no baseline of recorded tests yet.
14
+ # Callers skip silently instead of surfacing an error banner.
15
+ class FlakyDetectionDisabledError < StandardError; end
16
+
11
17
  # Manages intelligent test rerunning with budget constraints for flaky detection.
12
18
  # rubocop:disable Metrics/ClassLength
13
19
  class FlakyDetector
@@ -193,7 +199,7 @@ module Mergify
193
199
 
194
200
  private
195
201
 
196
- # rubocop:disable Metrics/AbcSize
202
+ # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
197
203
  def fetch_context
198
204
  owner, repo = Utils.split_full_repo_name(@full_repository_name)
199
205
  uri = URI("#{@url}/v1/ci/#{owner}/repositories/#{repo}/flaky-detection-context")
@@ -207,9 +213,18 @@ module Mergify
207
213
  request['Authorization'] = "Bearer #{@token}"
208
214
 
209
215
  response = http.request(request)
210
- parse_context(response.body)
216
+ case response.code.to_i
217
+ when 200
218
+ parse_context(response.body)
219
+ when 404
220
+ # A 404 means the repository has not opted into flaky detection; this
221
+ # is the expected default, not an error.
222
+ raise FlakyDetectionDisabledError
223
+ else
224
+ raise "Mergify API returned HTTP #{response.code}"
225
+ end
211
226
  end
212
- # rubocop:enable Metrics/AbcSize
227
+ # rubocop:enable Metrics/AbcSize,Metrics/MethodLength
213
228
 
214
229
  # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
215
230
  def parse_context(body)
@@ -231,7 +246,9 @@ module Mergify
231
246
  def validate!
232
247
  return unless @mode == 'new' && @context[:existing_test_names].empty?
233
248
 
234
- raise 'Cannot use "new" mode without existing test names in the context'
249
+ # Without a baseline, `new` mode would treat every test as new and rerun
250
+ # the whole suite. Skip instead of surfacing an error.
251
+ raise FlakyDetectionDisabledError
235
252
  end
236
253
 
237
254
  def remaining_budget
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-mergify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mergify