percy-cli 0.2.6 → 0.3.0

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: 8448bc82def2c998cb14e2423d4d0b69ec2b8a20
4
- data.tar.gz: 716dfc006d09195cabc054b8973fc2727c62b97e
3
+ metadata.gz: d4de0524f6c9f9e9a74c97ec4691d6ae6ed552dd
4
+ data.tar.gz: c989f4d7983a40f99b93aa969abd42341f56ec12
5
5
  SHA512:
6
- metadata.gz: 68d0ff2c3a015601944b6b926f6ab441f79b40bec9a4fbaa9288c3bf3d1d51e86e12f66c2f4efdbb052304f5bb4f3accaae18f808f2ec7c07c119ccb8aa6c1d8
7
- data.tar.gz: ec99b7a09a0ef1bc6fe1b25f7554198f1b8214be23fc7d3f727b47882fe224c0b50636d2064ff200a22e3d3b0b487f1a8b7cea7929c706def4af23a5e3783c2d
6
+ metadata.gz: eda54d6a7e2148a60446008c258b46a4d113d8c04df6bed75be400013f008e1fcc190ccbbfc2cb32c3a8566a542192e1732ab855df9c3765e2b76f749e697bc5
7
+ data.tar.gz: 9f89d396a58e54afec4bf169c28c13243131958e6dbadc430afdd077b31d2bed2d91073181ebd052cc7164c1d6222fa6ec0b66a6d7bfcdab0638e9abe4a52872
@@ -39,11 +39,16 @@ module Percy
39
39
  exit(-1)
40
40
  end
41
41
 
42
- say 'Creating build...'
43
- build = Percy.create_build(repo, resources: related_resources)
42
+ build = rescue_connection_failures do
43
+ say 'Creating build...'
44
+ build = Percy.create_build(repo, resources: related_resources)
44
45
 
45
- say 'Uploading build resources...'
46
- upload_missing_resources(build, build, all_resources, {num_threads: num_threads})
46
+ say 'Uploading build resources...'
47
+ upload_missing_resources(build, build, all_resources, {num_threads: num_threads})
48
+
49
+ build
50
+ end
51
+ return if failed?
47
52
 
48
53
  # Upload a snapshot for every root resource, and associate the related_resources.
49
54
  output_lock = Mutex.new
@@ -55,9 +60,11 @@ module Percy
55
60
  output_lock.synchronize do
56
61
  say "Uploading snapshot (#{i+1}/#{total}): #{root_resource.resource_url}"
57
62
  end
58
- snapshot = Percy.create_snapshot(build['data']['id'], [root_resource])
59
- upload_missing_resources(build, snapshot, all_resources, {num_threads: num_threads})
60
- Percy.finalize_snapshot(snapshot['data']['id'])
63
+ rescue_connection_failures do
64
+ snapshot = Percy.create_snapshot(build['data']['id'], [root_resource])
65
+ upload_missing_resources(build, snapshot, all_resources, {num_threads: num_threads})
66
+ Percy.finalize_snapshot(snapshot['data']['id'])
67
+ end
61
68
  end
62
69
  end
63
70
  snapshot_thread_pool.wait
@@ -65,13 +72,31 @@ module Percy
65
72
 
66
73
  # Finalize the build.
67
74
  say 'Finalizing build...'
68
- Percy.finalize_build(build['data']['id'])
75
+ rescue_connection_failures { Percy.finalize_build(build['data']['id']) }
76
+ return if failed?
69
77
  say "Done! Percy is now processing, you can view the visual diffs here:"
70
78
  say build['data']['attributes']['web-url']
71
79
  end
72
80
 
73
81
  private
74
82
 
83
+ def failed?
84
+ !!@failed
85
+ end
86
+
87
+ def rescue_connection_failures(&block)
88
+ raise ArgumentError.new('block is requried') if !block_given?
89
+ begin
90
+ block.call
91
+ rescue Percy::Client::HttpError,
92
+ Percy::Client::ConnectionFailed,
93
+ Percy::Client::TimeoutError => e
94
+ Percy.logger.error(e)
95
+ @failed = true
96
+ nil
97
+ end
98
+ end
99
+
75
100
  def find_root_paths(dir_path, options = {})
76
101
  snapshots_regex = options[:snapshots_regex] || DEFAULT_SNAPSHOTS_REGEX
77
102
 
@@ -1,5 +1,5 @@
1
1
  module Percy
2
2
  class Cli
3
- VERSION = '0.2.6'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
data/percy-cli.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'commander', '~> 4.3'
22
- spec.add_dependency 'percy-client', '>= 0.10.0'
22
+ spec.add_dependency 'percy-client', '>= 0.11.0'
23
23
  spec.add_dependency 'thread', '~> 0.2'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.7'
@@ -5,7 +5,41 @@ RSpec.describe Percy::Cli::Snapshot do
5
5
 
6
6
  describe '#run_snapshot' do
7
7
  xit 'snapshots a root directory of static files' do
8
- # TODO(fotinakis): tests for this.
8
+ # TODO(fotinakis): tests for the full flow.
9
+ end
10
+ end
11
+ describe '#rescue_connection_failures' do
12
+ let(:cli) { Percy::Cli.new }
13
+ it 'returns block result on success' do
14
+ result = cli.send(:rescue_connection_failures) do
15
+ true
16
+ end
17
+ expect(result).to eq(true)
18
+ expect(cli.send(:failed?)).to eq(false)
19
+ end
20
+ it 'makes block safe from HttpError' do
21
+ result = cli.send(:rescue_connection_failures) do
22
+ raise Percy::Client::HttpError.new(500, 'POST', '', '')
23
+ end
24
+ expect(result).to eq(nil)
25
+ expect(cli.send(:failed?)).to eq(true)
26
+ end
27
+ it 'makes block safe from ConnectionFailed' do
28
+ result = cli.send(:rescue_connection_failures) do
29
+ raise Percy::Client::ConnectionFailed
30
+ end
31
+ expect(result).to eq(nil)
32
+ expect(cli.send(:failed?)).to eq(true)
33
+ end
34
+ it 'makes block safe from TimeoutError' do
35
+ result = cli.send(:rescue_connection_failures) do
36
+ raise Percy::Client::TimeoutError
37
+ end
38
+ expect(result).to eq(nil)
39
+ expect(cli.send(:failed?)).to eq(true)
40
+ end
41
+ it 'requires a block' do
42
+ expect { cli.send(:rescue_connection_failures) }.to raise_error(ArgumentError)
9
43
  end
10
44
  end
11
45
  describe '#find_root_paths' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: percy-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Perceptual Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-08 00:00:00.000000000 Z
11
+ date: 2015-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.10.0
33
+ version: 0.11.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.10.0
40
+ version: 0.11.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: thread
43
43
  requirement: !ruby/object:Gem::Requirement