propel 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- propel (0.0.3)
4
+ propel (0.0.4)
5
5
  json
6
6
 
7
7
  GEM
data/lib/propel/runner.rb CHANGED
@@ -8,7 +8,13 @@ module Propel
8
8
  git_repository = GitRepository.new
9
9
 
10
10
  if git_repository.changed?
11
- check_remote_build! unless ignore_remote_build?
11
+ if remote_build_configured?
12
+ check_remote_build! unless ignore_remote_build?
13
+
14
+ else
15
+ puts "Remote build is not configured, skipping check." if @options[:verbose]
16
+ end
17
+
12
18
  propel!
13
19
  else
14
20
  puts "There is nothing to propel - your HEAD is identical to #{git_repository.remote_config} #{git_repository.merge_config}."
@@ -18,17 +24,42 @@ module Propel
18
24
  private
19
25
 
20
26
  def check_remote_build!
21
- if remote_build_configured?
22
-
23
- if !remote_build_passing?
24
- raise "The remote build is broken. If your commit fixes the build, run propel with the --force (-f) option."
27
+ if @options[:wait]
28
+ unless remote_build_green?
29
+ wait_with_notice do
30
+ log_wait_notice
31
+ wait until remote_build_green?
32
+ puts "\nThe build has been fixed."
33
+ end
25
34
  end
26
35
 
27
36
  else
28
- puts "Remote build is not configured, skipping check." if @options[:verbose]
37
+
38
+ alert_broken_build_and_exit unless remote_build_green?
29
39
  end
30
40
  end
31
41
 
42
+ def wait_with_notice
43
+ start_time = Time.now
44
+ yield
45
+ end_time = Time.now
46
+ puts "We waited for #{(end_time - start_time).round} seconds while the build was failing."
47
+ end
48
+
49
+ def log_wait_notice
50
+ puts "The remote build is failing, waiting until it is green to proceed."
51
+ end
52
+
53
+ def alert_broken_build_and_exit
54
+ msg = <<-EOS
55
+ The remote build is broken. If your commit fixes the build, run propel with the --force (-f) option.
56
+ If you're waiting for someone else to fix the build, use propel with --wait (-w).
57
+ EOS
58
+
59
+ $stderr.puts msg.split("\n").map(&:strip)
60
+ exit 1
61
+ end
62
+
32
63
  def ignore_remote_build?
33
64
  @options[:force]
34
65
  end
@@ -37,17 +68,10 @@ module Propel
37
68
  !@options[:status_url].nil?
38
69
  end
39
70
 
40
- def remote_build_passing?
41
- if @options[:wait]
42
- until remote_build_green? do
43
- print "."
44
- sleep 10
45
- end
46
-
47
- true
48
- else
49
- remote_build_green?
50
- end
71
+ def wait
72
+ print "."
73
+ STDOUT.flush
74
+ sleep 5
51
75
  end
52
76
 
53
77
  def remote_build_green?
@@ -1,3 +1,3 @@
1
1
  module Propel
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -29,8 +29,8 @@ describe Propel::Runner do
29
29
 
30
30
  it "should call propel! if the remote build is configured and passing" do
31
31
  runner = Propel::Runner.new(%w[ --status-url http://ci.example.com/status ])
32
- runner.stub!(:remote_build_passing?).and_return(true)
33
32
  runner.stub!(:remote_build_configured?).and_return(true)
33
+ runner.stub!(:remote_build_green?).and_return(true)
34
34
 
35
35
  runner.should_receive(:propel!)
36
36
 
@@ -45,16 +45,18 @@ describe Propel::Runner do
45
45
  runner.start
46
46
  end
47
47
 
48
- it "should raise an error and not call propel! if the remote build is configured but not passing" do
48
+ class TestError < StandardError ; end
49
+ it "should send an alert about the broken build if the remote build is configured but not passing" do
49
50
  runner = Propel::Runner.new
50
51
  runner.stub!(:remote_build_configured?).and_return true
51
- runner.stub!(:remote_build_passing?).and_return false
52
-
52
+ runner.stub!(:remote_build_green?).and_return false
53
+
54
+ runner.should_receive(:alert_broken_build_and_exit).and_raise(TestError.new("Execution should be aborted here"))
53
55
  runner.should_not_receive(:propel!)
54
56
 
55
57
  lambda {
56
58
  runner.start
57
- }.should raise_error(RuntimeError, "The remote build is broken. If your commit fixes the build, run propel with the --force (-f) option.")
59
+ }.should raise_error(TestError)
58
60
  end
59
61
 
60
62
  it "should call propel! when the remote build is failing if --force is specified" do
@@ -94,8 +96,13 @@ describe Propel::Runner do
94
96
 
95
97
  runner.should_receive(:remote_build_green?).twice.and_return(false, true)
96
98
 
99
+ runner.should_receive(:log_wait_notice)
100
+
101
+ runner.should_receive(:wait_with_notice).and_yield
102
+
103
+ runner.stub!(:puts)
97
104
  runner.stub!(:print).with('.')
98
- runner.stub!(:sleep).with(10)
105
+ runner.stub!(:sleep).with(5)
99
106
 
100
107
  runner.should_receive(:propel!)
101
108
  runner.start
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin Leitgeb