shipit-engine 0.8.8 → 0.8.9

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
  SHA1:
3
- metadata.gz: ee64f554f8b69bafd115203bc2cecc33521d5a7a
4
- data.tar.gz: 7c8029319509f59e820d7923e9ecc6eaf226d8e2
3
+ metadata.gz: e8a76aee01307d253747b6e49c6c7be3bb4c3cf2
4
+ data.tar.gz: 511372e610c0dfcdad6038607733841ee2752d0b
5
5
  SHA512:
6
- metadata.gz: 950959a1195778f0e3113db087b7e999866467ad79a095a70843a309f09bd212566e2d91679ee1b72d85854ae2b00a54189b33433051d46461f6aa880652af4e
7
- data.tar.gz: 5a9a53f97e460c4fc189220b6f028d9a2851bd6298542491a295fe1a7949fe981b3090dee882960b49aa05b275d9a70cfdec0142a761efab06fdd4bb29332f97
6
+ metadata.gz: ed8a88d84aa2f2d6e845fadad57c9aa39ebb78986f60ccd351a502bc6f5753c9a17e99bb7e3baf2c5b9e9c6fe716d3358c65bf704c7dbf4bffed69ae5c8595f3
7
+ data.tar.gz: d9bf4e7c3550d38705f5482971f84177eb64cddc42248e42c5197009d6fa12bbdc0914360c722fa7298b4d596e7e8a0c44f00d3af8ba2c2f4cbb0c119e222ae9
@@ -80,7 +80,8 @@ module Shipit
80
80
  end
81
81
 
82
82
  def refresh_statuses!
83
- Shipit.github_api.statuses(github_repo_name, sha).each do |status|
83
+ github_statuses = stack.handle_github_redirections { Shipit.github_api.statuses(github_repo_name, sha) }
84
+ github_statuses.each do |status|
84
85
  statuses.replicate_from_github!(status)
85
86
  end
86
87
  end
@@ -215,7 +215,28 @@ module Shipit
215
215
  end
216
216
 
217
217
  def github_commits
218
- Shipit.github_api.commits(github_repo_name, sha: branch)
218
+ handle_github_redirections do
219
+ Shipit.github_api.commits(github_repo_name, sha: branch)
220
+ end
221
+ end
222
+
223
+ def handle_github_redirections
224
+ # https://developer.github.com/v3/#http-redirects
225
+ resource = yield
226
+ if resource.try(:message) == 'Moved Permanently'
227
+ refresh_repository!
228
+ yield
229
+ else
230
+ resource
231
+ end
232
+ end
233
+
234
+ def refresh_repository!
235
+ resource = Shipit.github_api.repo(github_repo_name)
236
+ if resource.try(:message) == 'Moved Permanently'
237
+ resource = Shipit.github_api.get(resource.url)
238
+ end
239
+ update!(repo_owner: resource.owner.login, repo_name: resource.name)
219
240
  end
220
241
 
221
242
  def active_task?
@@ -1,3 +1,3 @@
1
1
  module Shipit
2
- VERSION = '0.8.8'
2
+ VERSION = '0.8.9'
3
3
  end
Binary file
@@ -417,5 +417,26 @@ module Shipit
417
417
 
418
418
  assert_equal 'pending', @stack.merge_status
419
419
  end
420
+
421
+ test "#handle_github_redirections update the stack if the repository was renamed" do
422
+ repo_permalink = 'https://api.github.com/repositories/42'
423
+
424
+ commits_redirection = stub(message: 'Moved Permanently', url: File.join(repo_permalink, '/commits'))
425
+ Shipit.github_api.expects(:commits).with(@stack.github_repo_name, sha: 'master').returns(commits_redirection)
426
+
427
+ repo_redirection = stub(message: 'Moved Permanently', url: repo_permalink)
428
+ Shipit.github_api.expects(:repo).with('shopify/shipit-engine').returns(repo_redirection)
429
+
430
+ repo_resource = stub(name: 'shipster', owner: stub(login: 'george'))
431
+ Shipit.github_api.expects(:get).with(repo_permalink).returns(repo_resource)
432
+
433
+ commits_resource = stub
434
+ Shipit.github_api.expects(:commits).with('george/shipster', sha: 'master').returns(commits_resource)
435
+
436
+ assert_equal 'shopify/shipit-engine', @stack.github_repo_name
437
+ assert_equal commits_resource, @stack.github_commits
438
+ @stack.reload
439
+ assert_equal 'george/shipster', @stack.github_repo_name
440
+ end
420
441
  end
421
442
  end
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.8.8
4
+ version: 0.8.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier