shipit-engine 0.42.0 → 0.42.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92deb69f7e1cf311777e4de1f80c95055d85b13bf28bba0cfa867d998a469620
4
- data.tar.gz: d201434b2619d1d1cd5b089656b5acbeeadc842cab75da2d4051f51a2013d497
3
+ metadata.gz: c95a2e049279a481503f3ed07a634d3926c1533ddd3b228cde55c3b324df1af1
4
+ data.tar.gz: b33f1940ee6d4f3909fca272a439604740899a37caa5f11f875ffe543d4332df
5
5
  SHA512:
6
- metadata.gz: 701903483ad7438eb46f1624c75bdcc893d9be84cf2f3926c0987cc257bd55b95e4c4e0703c85bf2db8c0ae7429c4e03ae1fe28e294a24cdca26f4d321e82d11
7
- data.tar.gz: 80a26fdee216be7713a1aa6389e3ec9b304f494514eed6d14d24bf7dd6b4466821ce8b54c12d4a3e291f49bfc20585a178d2eef581e74f846ac1c532e00d9b35
6
+ metadata.gz: d89afad83961d8ef42c6011116451e2025719345d4aa753a62dae3dac0f59370d33ed71261e812f6bd16bf20583cd29c300023d833db4dda8e851ff5ac068f3e
7
+ data.tar.gz: f3c90b17a66f5a14e2489869c636206cd5f5a55465d2bd58ab4a947cb82d4fe99cbd1cb057d4d1f8a195417d8964b2d3c66a65c1a115f381cb63b20f4b6aa298
@@ -173,23 +173,21 @@ module Shipit
173
173
  stack.github_api.check_runs(github_repo_name, sha, per_page: 100)
174
174
  end
175
175
 
176
- return response if stack.github_api.last_response.rels[:next].nil?
176
+ yield response.check_runs
177
177
 
178
- loop do
178
+ until stack.github_api.last_response.rels[:next].nil?
179
179
  page = stack.handle_github_redirections do
180
180
  stack.github_api.get(stack.github_api.last_response.rels[:next].href)
181
181
  end
182
- response.check_runs.concat(page.check_runs)
183
- break if stack.github_api.last_response.rels[:next].nil?
182
+ yield page.check_runs
184
183
  end
185
-
186
- response
187
184
  end
188
185
 
189
186
  def refresh_check_runs!
190
- response = paginated_check_runs
191
- response.check_runs.each do |check_run|
192
- create_or_update_check_run_from_github!(check_run)
187
+ paginated_check_runs do |check_runs|
188
+ check_runs.each do |check_run|
189
+ create_or_update_check_run_from_github!(check_run)
190
+ end
193
191
  end
194
192
  end
195
193
 
@@ -35,11 +35,18 @@ module Shipit
35
35
  private
36
36
 
37
37
  def base_env
38
- @base_env ||= Shipit.env.merge(
39
- 'GITHUB_DOMAIN' => github.domain,
40
- 'GITHUB_TOKEN' => github.token,
41
- 'GIT_ASKPASS' => Shipit::Engine.root.join('lib', 'snippets', 'git-askpass').realpath.to_s
42
- )
38
+ @base_env ||= begin
39
+ env = Shipit.env.merge(
40
+ 'GITHUB_DOMAIN' => github.domain,
41
+ 'GITHUB_TOKEN' => github.token
42
+ )
43
+
44
+ unless Rails.env.development? || Rails.env.test?
45
+ env['GIT_ASKPASS'] = Shipit::Engine.root.join('lib', 'snippets', 'git-askpass').realpath.to_s
46
+ end
47
+
48
+ env
49
+ end
43
50
  end
44
51
 
45
52
  def github
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shipit
4
- VERSION = '0.42.0'
4
+ VERSION = '0.42.1'
5
5
  end
@@ -367,6 +367,75 @@ module Shipit
367
367
  assert_equal 'success', @commit.check_runs.first.state
368
368
  end
369
369
 
370
+ test "refresh_check_runs! handles paginated responses from github" do
371
+ # First page check runs
372
+ check_run1 = mock(
373
+ id: 111_111_111_111_111,
374
+ name: 'Test suite 1',
375
+ conclusion: 'success',
376
+ details_url: 'https://example.com/details/1',
377
+ html_url: 'https://example.com/run/1',
378
+ output: mock(
379
+ title: 'Tests build 1 ran successfully'
380
+ ),
381
+ completed_at: Time.now,
382
+ started_at: Time.now - 1.minute
383
+ )
384
+ check_run2 = mock(
385
+ id: 222_222_222_222_222,
386
+ name: 'Test suite 2',
387
+ conclusion: 'failure',
388
+ details_url: 'https://example.com/details/2',
389
+ html_url: 'https://example.com/run/2',
390
+ output: mock(
391
+ title: 'Tests build 2 failed'
392
+ ),
393
+ completed_at: Time.now,
394
+ started_at: Time.now - 2.minutes
395
+ )
396
+
397
+ # Second page check runs
398
+ check_run3 = mock(
399
+ id: 333_333_333_333_333,
400
+ name: 'Test suite 3',
401
+ conclusion: 'success',
402
+ details_url: 'https://example.com/details/3',
403
+ html_url: 'https://example.com/run/3',
404
+ output: mock(
405
+ title: 'Tests build 3 skipped'
406
+ ),
407
+ completed_at: Time.now,
408
+ started_at: Time.now - 3.minutes
409
+ )
410
+
411
+ next_link = stub(href: 'https://api.github.com/repos/test/repo/check-runs?page=2')
412
+ first_response = stub(rels: { next: next_link }, data: mock(check_runs: [check_run1, check_run2]))
413
+ second_response = stub(rels: {}, data: mock(check_runs: [check_run3]))
414
+
415
+ call_sequence = sequence('api_calls')
416
+ Shipit.github.api.expects(:check_runs).with(@stack.github_repo_name, @commit.sha, per_page: 100).returns(first_response.data).in_sequence(call_sequence)
417
+ Shipit.github.api.expects(:last_response).returns(first_response).in_sequence(call_sequence)
418
+ Shipit.github.api.expects(:last_response).returns(first_response).in_sequence(call_sequence)
419
+ Shipit.github.api.expects(:get).with(next_link.href).returns(second_response.data).in_sequence(call_sequence)
420
+ Shipit.github.api.expects(:last_response).returns(second_response).in_sequence(call_sequence)
421
+
422
+ assert_difference -> { @commit.check_runs.count }, 3 do
423
+ @commit.refresh_check_runs!
424
+ end
425
+
426
+ check1 = @commit.check_runs.find_by(github_id: 111_111_111_111_111)
427
+ assert_not_nil check1
428
+ assert_equal 'success', check1.state
429
+
430
+ check2 = @commit.check_runs.find_by(github_id: 222_222_222_222_222)
431
+ assert_not_nil check2
432
+ assert_equal 'failure', check2.state
433
+
434
+ check3 = @commit.check_runs.find_by(github_id: 333_333_333_333_333)
435
+ assert_not_nil check3
436
+ assert_equal 'success', check3.state
437
+ end
438
+
370
439
  test "#creating a commit update the undeployed_commits_count" do
371
440
  walrus = shipit_users(:walrus)
372
441
  assert_equal 2, @stack.undeployed_commits_count
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shipit-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.42.0
4
+ version: 0.42.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier