propel 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- propel (0.3.2)
4
+ propel (0.4.0)
5
5
  json
6
6
 
7
7
  GEM
@@ -2,5 +2,6 @@ require 'propel/configuration'
2
2
  require 'propel/git_repository'
3
3
  require 'propel/logger'
4
4
  require 'propel/option_parser'
5
+ require 'propel/propel'
5
6
  require 'propel/remote_build'
6
7
  require 'propel/runner'
@@ -44,7 +44,7 @@ module Propel
44
44
  end
45
45
 
46
46
  def parse(option_array)
47
- Propel::OptionParser.parse!(option_array)
47
+ ::Propel::OptionParser.parse!(option_array)
48
48
  end
49
49
  end
50
50
  end
@@ -1,57 +1,101 @@
1
1
  module Propel
2
2
  class GitRepository
3
+ Result = Struct.new(:result, :exitstatus)
4
+
5
+ attr_accessor :logger, :options
6
+
7
+ def initialize
8
+ @options = { :verbose => false }
9
+ end
10
+
3
11
  def self.changed?
4
12
  new.changed?
5
13
  end
6
14
 
7
15
  def project_root
8
- git("rev-parse --show-toplevel")
16
+ git("rev-parse --show-toplevel").result
9
17
  end
10
18
 
11
19
  def changed?
12
20
  local_last_commit != remote_last_commit
13
21
  end
14
22
 
23
+ def pull(rebase)
24
+ pull_cmd = 'pull'
25
+ pull_cmd << ' --rebase' if rebase
26
+ git pull_cmd
27
+ end
28
+
29
+ def push
30
+ logger.report_operation "Pushing to #{remote_config} #{merge_config}"
31
+
32
+ git(verbosity_for('push')).tap do |result|
33
+ if result.exitstatus != 0
34
+ logger.report_status("FAILING", :red)
35
+ exit_with_error "Your push failed! Please try again later."
36
+ end
37
+
38
+ logger.report_status('DONE', :green)
39
+ end
40
+ end
41
+
15
42
  def remote_config
16
- git("config branch.#{current_branch}.remote").tap do |remote|
43
+ git("config branch.#{current_branch}.remote").result.tap do |remote|
17
44
  if remote.empty?
18
- warn "We could not determine the remote repository for branch '#{current_branch}.' " +
19
- "Please set it with git config branch.#{current_branch}.remote REMOTE_REPO."
20
- exit 1
45
+ exit_with_error "We could not determine the remote repository for branch '#{current_branch}.' " +
46
+ "Please set it with git config branch.#{current_branch}.remote REMOTE_REPO."
21
47
  end
22
48
  end
23
49
  end
24
50
 
25
51
  def merge_config
26
- git("config branch.#{current_branch}.merge").tap do |merge|
52
+ git("config branch.#{current_branch}.merge").result.tap do |merge|
27
53
  if merge.empty?
28
- warn "We could not determine the remote branch for local branch '#{current_branch}.' " +
29
- "Please set it with git config branch.#{current_branch}.merge REMOTE_BRANCH."
30
- exit 1
54
+ exit_with_error "We could not determine the remote branch for local branch '#{current_branch}.' " +
55
+ "Please set it with git config branch.#{current_branch}.merge REMOTE_BRANCH."
31
56
  end
32
57
  end
33
58
  end
34
59
 
60
+ def fetch!
61
+ logger.report_operation "Retrieving remote objects"
62
+
63
+ git(verbosity_for('fetch')).tap do |result|
64
+ if result.exitstatus != 0
65
+ exit_with_error "Fetch of remote repository failed, exiting."
66
+ end
67
+
68
+ logger.report_status("DONE", :green)
69
+ end
70
+ end
71
+
35
72
  private
73
+ def exit_with_error(message)
74
+ warn message
75
+ exit 1
76
+ end
77
+
36
78
  def git git_args
37
- `git #{git_args}`.strip
79
+ output = `git #{git_args}`.strip
80
+ Result.new(output, $?)
38
81
  end
39
82
 
40
83
  def local_last_commit
41
- git("rev-parse HEAD")
84
+ git("rev-parse HEAD").result
42
85
  end
43
86
 
44
87
  def remote_last_commit
45
88
  fetch!
46
- git("ls-remote #{remote_config} #{merge_config}").gsub(/\t.*/, '')
89
+ git("ls-remote #{remote_config} #{merge_config}").result.gsub(/\t.*/, '')
47
90
  end
48
91
 
49
92
  def current_branch
50
- git("branch").split("\n").detect{|l| l =~ /^\*/ }.gsub(/^\* /, '')
93
+ # TODO - replace with git symbolic-ref HEAD
94
+ git("branch").result.split("\n").detect{|l| l =~ /^\*/ }.gsub(/^\* /, '')
51
95
  end
52
96
 
53
- def fetch!
54
- git("fetch")
97
+ def verbosity_for(git_operation)
98
+ @options[:verbose] ? git_operation : "#{git_operation} -q"
55
99
  end
56
100
  end
57
101
  end
@@ -18,11 +18,28 @@ module Propel
18
18
  end
19
19
 
20
20
  def puts(message, color_sym = nil)
21
- Kernel.puts color(message, color_sym) unless @configuration[:quiet]
21
+ Kernel.puts color(message, color_sym)
22
22
  end
23
23
 
24
24
  def warn(message, color_sym = nil)
25
- Kernel.warn color(message, color_sym) unless @configuration[:quiet]
25
+ Kernel.warn color(message, color_sym)
26
+ end
27
+
28
+ def report_operation(message)
29
+ if @configuration[:verbose]
30
+ Kernel.puts("#{message}...")
31
+ else
32
+ Kernel.print("%-60s" % "#{message}:")
33
+ STDOUT.flush
34
+ end
35
+ end
36
+
37
+ def report_status(message, color_sym)
38
+ if @configuration[:verbose]
39
+ Kernel.puts(color(message.capitalize, color_sym))
40
+ else
41
+ Kernel.puts("[ #{color(message.upcase, color_sym)} ]")
42
+ end
26
43
  end
27
44
 
28
45
  private
@@ -17,26 +17,26 @@ module Propel
17
17
  ::OptionParser.new do |parser|
18
18
  parser.banner = "Usage: propel [options]\n\n"
19
19
 
20
- parser.on('-c', '--[no-]color', '--[no-]colour', 'Turn on or off colored output. Color is off by default.') do |o|
20
+ parser.on('-c', '--[no-]color', '--[no-]colour', 'Toggle colored output. Color is off by default.') do |o|
21
21
  options[:color] = o
22
22
  end
23
23
 
24
- parser.on('-f', '--fix-ci', 'Use when fixing the CI build') do |o|
24
+ parser.on('-f', '--fix-ci', 'When CI is broken use --fix-ci to fix the build.') do |o|
25
25
  options[:fix_ci] = o
26
26
  end
27
27
 
28
- parser.on('-q', '--[no-]quiet', 'Silences normal output messages.') do |o|
29
- options[:quiet] = o
30
- end
31
-
32
- parser.on('-r', '--[no-]rebase', 'Use pull with --rebase. Rebase is used by default.') do |o|
28
+ parser.on('-r', '--[no-]rebase', 'Use --no-rebase when you don\'t want to rebase. Rebase is used by default.') do |o|
33
29
  options[:rebase] = o
34
30
  end
35
31
 
36
- parser.on('-s', '--status-url STATUS_URL', 'Location of build status feed') do |build_status_url|
32
+ parser.on('-s', '--status-url STATUS_URL', 'Location of build status feed.') do |build_status_url|
37
33
  options[:status_url] = build_status_url
38
34
  end
39
35
 
36
+ parser.on('-v', '--[no-]verbose', 'Turn on verbose output from git.') do |o|
37
+ options[:verbose] = o
38
+ end
39
+
40
40
  parser.on('-w', '--[no-]wait', 'Waits for fixes to remote build.') do |o|
41
41
  options[:wait] = o
42
42
  end
@@ -0,0 +1,17 @@
1
+ module Propel
2
+ class Propel
3
+ def initialize(repository, rebase)
4
+ @repository = repository
5
+ @rebase = rebase
6
+ end
7
+
8
+ def start
9
+ @repository.pull(@rebase) && rake && @repository.push
10
+ end
11
+
12
+ private
13
+ def rake
14
+ system('rake')
15
+ end
16
+ end
17
+ end
@@ -1,40 +1,42 @@
1
1
  module Propel
2
2
  class Runner
3
- attr_reader :logger
3
+ attr_reader :logger, :repository
4
4
 
5
5
  def initialize(args = [ ])
6
6
  @repository = GitRepository.new
7
7
  @options = Configuration.new(args, @repository).options
8
8
  @logger = Logger.new(@options)
9
+
10
+ @repository.logger = @logger
11
+ @repository.options = @options
9
12
  end
10
13
 
11
14
  def start
12
15
  if @repository.changed?
13
16
  if remote_build_configured?
14
-
17
+
15
18
  if @options[:fix_ci]
16
- @logger.puts("Thanks for trying to fix the build!", :green)
19
+ logger.puts("Thanks for trying to fix the build!", :green)
17
20
  else
18
21
  check_remote_build!
19
22
  end
20
23
 
21
24
  else
22
- @logger.warn "Remote build is not configured, you should point propel to the status URL of your CI server."
23
-
25
+ logger.warn "Remote build is not configured. You should point propel to the status URL of your CI server."
26
+
24
27
  end
25
28
 
26
29
  propel!
27
30
  else
28
- @logger.puts("There is nothing to propel - your HEAD is identical to #{@repository.remote_config} #{@repository.merge_config}.", :green)
29
-
31
+ logger.puts("There is nothing to propel - your HEAD is identical to #{@repository.remote_config} #{@repository.merge_config}.", :green)
32
+
30
33
  end
31
34
  end
32
35
 
33
36
  private
34
37
 
35
38
  def check_remote_build!
36
- @logger.print "CI server status:\t"
37
- STDOUT.flush
39
+ logger.report_operation "CI server status"
38
40
 
39
41
  waited_for_build = false
40
42
  if @options[:wait]
@@ -42,10 +44,10 @@ module Propel
42
44
  waited_for_build = true
43
45
 
44
46
  say_duration do
45
- @logger.puts("FAILING", :red)
46
- @logger.puts "Waiting until the CI build is green."
47
+ logger.report_status("FAILING", :red)
48
+ logger.puts "Waiting until the CI build is green."
47
49
  wait until remote_build_green?
48
- @logger.puts("\nThe CI build has been fixed.", :green)
50
+ logger.puts("\nThe CI build has been fixed.", :green)
49
51
  end
50
52
  end
51
53
 
@@ -54,25 +56,25 @@ module Propel
54
56
  alert_broken_build_and_exit unless remote_build_green?
55
57
  end
56
58
 
57
- @logger.puts("PASSING", :green) unless waited_for_build
59
+ logger.report_status("PASSING", :green) unless waited_for_build
58
60
  end
59
61
 
60
62
  def say_duration
61
63
  start_time = Time.now
62
64
  yield
63
65
  end_time = Time.now
64
- @logger.puts("We waited for #{(end_time - start_time).round} seconds while the build was failing.")
66
+ logger.puts("We waited for #{(end_time - start_time).round} seconds while the build was failing.")
65
67
  end
66
68
 
67
69
  def alert_broken_build_and_exit
68
- @logger.puts("FAILING", :red)
70
+ logger.puts("FAILING", :red)
69
71
 
70
72
  msg = <<-EOS
71
73
  The remote build is broken. If your commit fixes the build, run propel with --fix-ci (-f).
72
74
  If you're waiting for someone else to fix the build, use propel with --wait (-w).
73
75
  EOS
74
76
 
75
- @logger.puts("")
77
+ logger.puts("")
76
78
  warn msg
77
79
  exit 1
78
80
  end
@@ -82,7 +84,7 @@ If you're waiting for someone else to fix the build, use propel with --wait (-w)
82
84
  end
83
85
 
84
86
  def wait
85
- @logger.print(".", :yellow)
87
+ logger.print(".", :yellow)
86
88
  sleep 5
87
89
  end
88
90
 
@@ -91,9 +93,7 @@ If you're waiting for someone else to fix the build, use propel with --wait (-w)
91
93
  end
92
94
 
93
95
  def propel!
94
- pull_cmd = 'git pull'
95
- pull_cmd << ' --rebase' if @options[:rebase]
96
- system [ pull_cmd, 'rake', 'git push' ].join(' && ')
96
+ Propel.new(@repository, @options[:rebase]).start
97
97
  end
98
98
  end
99
99
  end
@@ -1,3 +1,3 @@
1
1
  module Propel
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -24,7 +24,7 @@ describe Propel::Configuration do
24
24
  end
25
25
 
26
26
  it "should correct the color setting if on a Windows 32 system that does not support color" do
27
- configuration = Propel::Configuration.new(['--color', '--quiet'], Propel::GitRepository.new)
27
+ configuration = Propel::Configuration.new(['--color'], Propel::GitRepository.new)
28
28
  configuration.stub(:ruby_platform).and_return('mswin')
29
29
  configuration.stub!(:warn)
30
30
  configuration.options[:color].should be_false
@@ -1,13 +1,56 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Propel::GitRepository do
4
- describe ".changed?" do
5
- it "should call #changed? on a new instance of the GitRepository" do
4
+ describe "#pull" do
5
+ it "should use --rebase when argument is true" do
6
6
  git_repository = Propel::GitRepository.new
7
- git_repository.should_receive(:changed?)
8
- Propel::GitRepository.should_receive(:new).and_return git_repository
7
+ git_repository.should_receive(:git).with("pull --rebase")
8
+ git_repository.pull(true)
9
+ end
10
+
11
+ it "should not use --rebase when argument as false" do
12
+ git_repository = Propel::GitRepository.new
13
+ git_repository.should_receive(:git).with("pull")
14
+ git_repository.pull(false)
15
+ end
16
+ end
17
+
18
+ describe "#push" do
19
+ it "should call 'push -q' by default" do
20
+ git_repository = Propel::GitRepository.new
21
+ git_repository.logger = stub_logger
22
+
23
+ git_repository.should_receive(:git).with('push -q').and_return(Propel::GitRepository::Result.new('all good', 0))
24
+ git_repository.stub!(:remote_config)
25
+ git_repository.stub!(:merge_config)
26
+
27
+ git_repository.push
28
+ end
29
+
30
+ it "should call push without -q if --verbose is specified" do
31
+ git_repository = Propel::GitRepository.new
32
+ git_repository.logger = stub_logger
33
+ git_repository.options = {:verbose => true}
9
34
 
10
- Propel::GitRepository.changed?
35
+ git_repository.should_receive(:git).with('push').and_return(Propel::GitRepository::Result.new('all good', 0))
36
+ git_repository.stub!(:remote_config)
37
+ git_repository.stub!(:merge_config)
38
+ git_repository.push
39
+ end
40
+
41
+ it "should warn the user and exit with a status of 1 if the push fails" do
42
+ git_repository = Propel::GitRepository.new
43
+ git_repository.logger = stub_logger
44
+
45
+ git_repository.should_receive(:git).with('push -q').and_return(Propel::GitRepository::Result.new('bad!', 1))
46
+
47
+ git_repository.stub!(:remote_config)
48
+ git_repository.stub!(:merge_config)
49
+
50
+ git_repository.should_receive(:warn).with("Your push failed! Please try again later.")
51
+ git_repository.should_receive(:exit).with(1)
52
+
53
+ git_repository.push
11
54
  end
12
55
  end
13
56
 
@@ -17,18 +60,52 @@ describe Propel::GitRepository do
17
60
  Propel::GitRepository.new.project_root.should == project_root
18
61
  end
19
62
  end
20
-
63
+
64
+ describe ".changed?" do
65
+ it "should call #changed? on a new instance of the GitRepository" do
66
+ git_repository = Propel::GitRepository.new
67
+ git_repository.should_receive(:changed?)
68
+ Propel::GitRepository.should_receive(:new).and_return git_repository
69
+
70
+ Propel::GitRepository.changed?
71
+ end
72
+ end
73
+
74
+ describe "#fetch!" do
75
+ it "should exit with a not-0 status and warn the user if the fetch fails" do
76
+ git_repository = Propel::GitRepository.new
77
+ git_repository.logger = stub_logger
78
+
79
+ git_repository.should_receive(:git).with('fetch -q').and_return(Propel::GitRepository::Result.new('', 1))
80
+
81
+ git_repository.should_receive(:exit).with(1)
82
+ git_repository.should_receive(:warn).with('Fetch of remote repository failed, exiting.')
83
+
84
+ git_repository.fetch!
85
+ end
86
+
87
+ it "should call fetch without the quiet option (-q) if --verbose is specified" do
88
+ git_repository = Propel::GitRepository.new
89
+ git_repository.logger = stub_logger
90
+ git_repository.options = {:verbose => true}
91
+
92
+ git_repository.should_receive(:git).with('fetch').and_return(Propel::GitRepository::Result.new('', 0))
93
+
94
+ git_repository.fetch!
95
+ end
96
+ end
97
+
21
98
  describe "#changed?" do
22
99
  it "should return false when the remote branch has the same SHA1 as the local HEAD" do
23
100
  git_repository = Propel::GitRepository.new
24
101
  git_repository.stub!(:fetch!)
25
- git_repository.stub!(:git).with("branch").and_return("* master\n testbranch")
102
+ git_repository.stub!(:git).with("branch").and_return(Propel::GitRepository::Result.new("* master\n testbranch", 0))
26
103
 
27
- git_repository.should_receive(:git).with("rev-parse HEAD").and_return("ef2c8125b1923950a9cd776298516ad9ed3eb568")
28
- git_repository.should_receive(:git).with("config branch.master.remote").and_return("origin")
29
- git_repository.should_receive(:git).with("config branch.master.merge").and_return("refs/heads/master")
104
+ git_repository.should_receive(:git).with("rev-parse HEAD").and_return(Propel::GitRepository::Result.new("ef2c8125b1923950a9cd776298516ad9ed3eb568", 0))
105
+ git_repository.should_receive(:git).with("config branch.master.remote").and_return(Propel::GitRepository::Result.new("origin", 0))
106
+ git_repository.should_receive(:git).with("config branch.master.merge").and_return(Propel::GitRepository::Result.new("refs/heads/master", 0))
30
107
 
31
- git_repository.should_receive(:git).with("ls-remote origin refs/heads/master").and_return("ef2c8125b1923950a9cd776298516ad9ed3eb568\trefs/heads/master")
108
+ git_repository.should_receive(:git).with("ls-remote origin refs/heads/master").and_return(Propel::GitRepository::Result.new("ef2c8125b1923950a9cd776298516ad9ed3eb568\trefs/heads/master", 0))
32
109
 
33
110
  git_repository.should_not be_changed
34
111
  end
@@ -36,13 +113,13 @@ describe Propel::GitRepository do
36
113
  it "should return true when the remote branch has a different SHA1 than the local HEAD" do
37
114
  git_repository = Propel::GitRepository.new
38
115
  git_repository.stub!(:fetch!)
39
- git_repository.stub!(:git).with("branch").and_return("* master\n testbranch")
116
+ git_repository.stub!(:git).with("branch").and_return(Propel::GitRepository::Result.new("* master\n testbranch", 0))
40
117
 
41
- git_repository.should_receive(:git).with("rev-parse HEAD").and_return("ef2c8125b1923950a9cd776298516ad9ed3eb568")
42
- git_repository.should_receive(:git).with("config branch.master.remote").and_return("origin")
43
- git_repository.should_receive(:git).with("config branch.master.merge").and_return("refs/heads/master")
118
+ git_repository.should_receive(:git).with("rev-parse HEAD").and_return(Propel::GitRepository::Result.new("ef2c8125b1923950a9cd776298516ad9ed3eb568", 0))
119
+ git_repository.should_receive(:git).with("config branch.master.remote").and_return(Propel::GitRepository::Result.new("origin", 0))
120
+ git_repository.should_receive(:git).with("config branch.master.merge").and_return(Propel::GitRepository::Result.new("refs/heads/master", 0))
44
121
 
45
- git_repository.should_receive(:git).with("ls-remote origin refs/heads/master").and_return("bf2c8125b1923950a9cd776298516ad9ed3eb568\trefs/heads/master")
122
+ git_repository.should_receive(:git).with("ls-remote origin refs/heads/master").and_return(Propel::GitRepository::Result.new("bf2c8125b1923950a9cd776298516ad9ed3eb568\trefs/heads/master", 0))
46
123
 
47
124
  git_repository.should be_changed
48
125
  end
@@ -51,8 +128,8 @@ describe Propel::GitRepository do
51
128
  describe "#remote_config" do
52
129
  it "should call the git command to determine the remote repository" do
53
130
  git_repository = Propel::GitRepository.new
54
- git_repository.stub!(:git).with("branch").and_return("* master\n testbranch")
55
- git_repository.should_receive(:git).with("config branch.master.remote").and_return("origin")
131
+ git_repository.stub!(:git).with("branch").and_return(Propel::GitRepository::Result.new("* master\n testbranch", 0))
132
+ git_repository.should_receive(:git).with("config branch.master.remote").and_return(Propel::GitRepository::Result.new("origin", 0))
56
133
 
57
134
  git_repository.remote_config.should == 'origin'
58
135
  end
@@ -60,8 +137,8 @@ describe Propel::GitRepository do
60
137
  it "should raise an error if the remote repository cannot be determined" do
61
138
  git_repository = Propel::GitRepository.new
62
139
 
63
- git_repository.stub!(:git).with("branch").and_return("* foo\n testbranch")
64
- git_repository.stub!(:git).with("config branch.foo.remote").and_return("")
140
+ git_repository.stub!(:git).with("branch").and_return(Propel::GitRepository::Result.new("* foo\n testbranch", 0))
141
+ git_repository.stub!(:git).with("config branch.foo.remote").and_return(Propel::GitRepository::Result.new("", 0))
65
142
 
66
143
  git_repository.should_receive(:warn).with("We could not determine the remote repository for branch 'foo.' Please set it with git config branch.foo.remote REMOTE_REPO.")
67
144
  git_repository.should_receive(:exit).with(1)
@@ -73,8 +150,8 @@ describe Propel::GitRepository do
73
150
  describe "#merge_config" do
74
151
  it "should call the git command to determine the remote branch" do
75
152
  git_repository = Propel::GitRepository.new
76
- git_repository.stub!(:git).with("branch").and_return("* master\n testbranch")
77
- git_repository.should_receive(:git).with("config branch.master.merge").and_return("refs/heads/master")
153
+ git_repository.stub!(:git).with("branch").and_return(Propel::GitRepository::Result.new("* master\n testbranch", 0))
154
+ git_repository.should_receive(:git).with("config branch.master.merge").and_return(Propel::GitRepository::Result.new("refs/heads/master", 0))
78
155
 
79
156
  git_repository.merge_config.should == 'refs/heads/master'
80
157
  end
@@ -82,8 +159,8 @@ describe Propel::GitRepository do
82
159
  it "should raise an error if the remote branch cannot be determined" do
83
160
  git_repository = Propel::GitRepository.new
84
161
 
85
- git_repository.stub!(:git).with("branch").and_return("* foo\n testbranch")
86
- git_repository.stub!(:git).with("config branch.foo.merge").and_return("")
162
+ git_repository.stub!(:git).with("branch").and_return(Propel::GitRepository::Result.new("* foo\n testbranch", 0))
163
+ git_repository.stub!(:git).with("config branch.foo.merge").and_return(Propel::GitRepository::Result.new("", 0))
87
164
 
88
165
  git_repository.should_receive(:warn).with("We could not determine the remote branch for local branch 'foo.' Please set it with git config branch.foo.merge REMOTE_BRANCH.")
89
166
  git_repository.should_receive(:exit).with(1)
@@ -2,22 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Propel::Logger do
4
4
  describe "#print" do
5
- it "should print the message when quiet mode is disabled" do
6
- logger = Propel::Logger.new({:quiet => false})
7
- Kernel.should_receive(:print).with('Hi')
8
-
9
- logger.print('Hi')
10
- end
11
-
12
- it "should not print the message when quiet mode is enabled" do
13
- logger = Propel::Logger.new({:quiet => true})
14
- Kernel.should_not_receive(:print).with('Hi')
15
-
16
- logger.print('Hi')
17
- end
18
-
19
5
  it "should colorize the method when color is enabled and a color is provided" do
20
- logger = Propel::Logger.new({:quiet => false, :color => true})
6
+ logger = Propel::Logger.new({:color => true})
21
7
  Kernel.should_receive(:print).with("\e[32mHi\e[0m")
22
8
 
23
9
  logger.print('Hi', :green)
@@ -25,22 +11,8 @@ describe Propel::Logger do
25
11
  end
26
12
 
27
13
  describe "#puts" do
28
- it "should puts the message when quiet mode is disabled" do
29
- logger = Propel::Logger.new({:quiet => false})
30
- Kernel.should_receive(:puts).with('Hi')
31
-
32
- logger.puts('Hi')
33
- end
34
-
35
- it "should not puts the message when quiet mode is enabled" do
36
- logger = Propel::Logger.new({:quiet => true})
37
- Kernel.should_not_receive(:puts).with('Hi')
38
-
39
- logger.puts('Hi')
40
- end
41
-
42
14
  it "should colorize the method when color is enabled and a color is provided" do
43
- logger = Propel::Logger.new({:quiet => false, :color => true})
15
+ logger = Propel::Logger.new({:color => true})
44
16
  Kernel.should_receive(:puts).with("\e[31mHi\e[0m")
45
17
 
46
18
  logger.puts('Hi', :red)
@@ -48,25 +20,39 @@ describe Propel::Logger do
48
20
  end
49
21
 
50
22
  describe "#warn" do
51
- it "should warn the message when quiet mode is disabled" do
52
- logger = Propel::Logger.new({:quiet => false})
53
- Kernel.should_receive(:warn).with('Hi')
23
+ it "should colorize the method when color is enabled and a color is provided" do
24
+ logger = Propel::Logger.new({:color => true})
25
+ Kernel.should_receive(:warn).with("\e[33mHi\e[0m")
54
26
 
55
- logger.warn('Hi')
56
- end
27
+ logger.warn('Hi', :yellow)
28
+ end
29
+ end
57
30
 
58
- it "should not warn the message when quiet mode is enabled" do
59
- logger = Propel::Logger.new({:quiet => true})
60
- Kernel.should_not_receive(:warn).with('Hi')
31
+ describe "#report_operation" do
32
+ it "should return a formatted string by default" do
33
+ logger = Propel::Logger.new({:color => true})
34
+ Kernel.should_receive(:print).with("Doing something: ")
35
+ logger.report_operation('Doing something')
36
+ end
61
37
 
62
- logger.warn('Hi')
38
+ it "should print a string with an ellipsis at the end when verbose is true" do
39
+ logger = Propel::Logger.new({:verbose => true})
40
+ Kernel.should_receive(:puts).with("Doing something...")
41
+ logger.report_operation('Doing something')
63
42
  end
43
+ end
64
44
 
65
- it "should colorize the method when color is enabled and a color is provided" do
66
- logger = Propel::Logger.new({:quiet => false, :color => true})
67
- Kernel.should_receive(:warn).with("\e[33mHi\e[0m")
45
+ describe "#report_status" do
46
+ it "should return a formatted, colorized string" do
47
+ logger = Propel::Logger.new({:color => true})
48
+ Kernel.should_receive(:puts).with("[ \e[31mDONE\e[0m ]")
49
+ logger.report_status('done', :red)
50
+ end
68
51
 
69
- logger.warn('Hi', :yellow)
70
- end
52
+ it "should print a string that can appear on its own output line when verbose is true" do
53
+ logger = Propel::Logger.new({:color => true, :verbose => true})
54
+ Kernel.should_receive(:puts).with("\e[31mDone\e[0m")
55
+ logger.report_status('done', :red)
56
+ end
71
57
  end
72
58
  end
@@ -14,8 +14,8 @@ describe Propel::OptionParser do
14
14
  Propel::OptionParser.parse!(['--wait'])[:wait].should be_true
15
15
  end
16
16
 
17
- it "should set quiet to true when given as an option" do
18
- Propel::OptionParser.parse!(['--quiet'])[:quiet].should be_true
17
+ it "should set verbose to true when given as an option" do
18
+ Propel::OptionParser.parse!(['--verbose'])[:verbose].should be_true
19
19
  end
20
20
 
21
21
  it "should set the status url based on the given parameters" do
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Propel::Propel do
4
+ describe "#start" do
5
+ before do
6
+ @repository = Propel::GitRepository.new
7
+ end
8
+
9
+ it "should call pull on the repository with rebase when rebase is true" do
10
+ propel = Propel::Propel.new(@repository, true)
11
+ @repository.should_receive(:pull).with(true)
12
+
13
+ propel.start
14
+ end
15
+
16
+ it "should call pull on the repository without rebase when rebase is false" do
17
+ propel = Propel::Propel.new(@repository, false)
18
+ @repository.should_receive(:pull).with(false).and_return(false)
19
+
20
+ propel.start
21
+ end
22
+
23
+ it"should call rake if the pull passes" do
24
+ propel = Propel::Propel.new(@repository, true)
25
+ @repository.should_receive(:pull).and_return(true)
26
+ propel.should_receive(:rake).and_return(false)
27
+
28
+ propel.start
29
+ end
30
+
31
+ it "should not call rake if the pull fails" do
32
+ propel = Propel::Propel.new(@repository, true)
33
+ @repository.should_receive(:pull).and_return(false)
34
+ propel.should_not_receive(:rake)
35
+
36
+ propel.start
37
+ end
38
+
39
+ it"should call push if rake passes" do
40
+ propel = Propel::Propel.new(@repository, true)
41
+ @repository.should_receive(:pull).and_return(true)
42
+ propel.should_receive(:rake).and_return(true)
43
+ @repository.should_receive(:push)
44
+
45
+ propel.start
46
+ end
47
+
48
+ it "should not call push if rake fails" do
49
+ propel = Propel::Propel.new(@repository, true)
50
+ @repository.should_receive(:pull).and_return(true)
51
+ propel.should_receive(:rake).and_return(false)
52
+ @repository.should_not_receive(:push)
53
+
54
+ propel.start
55
+ end
56
+ end
57
+ end
@@ -9,14 +9,17 @@ describe Propel::Runner do
9
9
 
10
10
  describe ".start" do
11
11
  it "should not call propel! if there is nothing to push" do
12
- runner = Propel::Runner.new(%w[--quiet])
12
+ runner = Propel::Runner.new
13
+ runner.stub!(:logger).and_return(stub_logger)
14
+
13
15
  @git_repository.should_receive(:changed?).and_return(false)
14
16
  runner.should_not_receive(:propel!)
15
17
  runner.start
16
18
  end
17
19
 
18
20
  it "should call propel! if there are changes to the current branch" do
19
- runner = Propel::Runner.new(%w[--quiet])
21
+ runner = Propel::Runner.new
22
+ runner.stub!(:logger).and_return(stub_logger)
20
23
 
21
24
  @git_repository.stub!(:changed?).and_return(true)
22
25
  @git_repository.stub!(:remote_config).and_return('origin')
@@ -27,33 +30,39 @@ describe Propel::Runner do
27
30
  end
28
31
 
29
32
  it "should call propel! if the remote build is configured and passing" do
30
- runner = Propel::Runner.new(%w[ --status-url http://ci.example.com/status --quiet ])
33
+ runner = Propel::Runner.new(%w[ --status-url http://ci.example.com/status ])
31
34
 
32
35
  runner.stub!(:remote_build_configured?).and_return(true)
33
36
  runner.stub!(:remote_build_green?).and_return(true)
34
37
 
38
+ runner.stub!(:logger).and_return(stub_logger)
39
+
35
40
  runner.should_receive(:propel!)
36
41
  runner.start
37
42
  end
38
43
 
39
44
  it "should call propel! if the remote build is not configured" do
40
- runner = Propel::Runner.new(%w[--quiet])
45
+ runner = Propel::Runner.new
41
46
  runner.stub!(:remote_build_configured?).and_return false
42
47
  runner.should_receive(:propel!)
43
- runner.logger.should_receive(:warn).with("Remote build is not configured, you should point propel to the status URL of your CI server.")
48
+ runner.stub!(:logger).and_return(stub_logger)
49
+
50
+ runner.logger.should_receive(:warn).with("Remote build is not configured. You should point propel to the status URL of your CI server.")
44
51
 
45
52
  runner.start
46
53
  end
47
54
 
48
55
  class TestError < StandardError ; end
49
56
  it "should send an alert about the broken build if the remote build is configured but not passing" do
50
- runner = Propel::Runner.new(%w[--quiet])
57
+ runner = Propel::Runner.new
51
58
  runner.stub!(:remote_build_configured?).and_return true
52
59
  runner.stub!(:remote_build_green?).and_return false
53
60
 
54
61
  runner.should_receive(:alert_broken_build_and_exit).and_raise(TestError.new("Execution should be aborted here"))
55
62
  runner.should_not_receive(:propel!)
56
63
 
64
+ runner.stub!(:logger).and_return(stub_logger)
65
+
57
66
  lambda {
58
67
  runner.start
59
68
  }.should raise_error(TestError)
@@ -73,33 +82,17 @@ describe Propel::Runner do
73
82
  runner = Propel::Runner.new %w[ --fix-ci ]
74
83
  runner.stub!(:remote_build_configured?).and_return false
75
84
 
76
- runner.logger.should_receive(:warn).with("Remote build is not configured, you should point propel to the status URL of your CI server.")
85
+ runner.logger.should_receive(:warn).with("Remote build is not configured. You should point propel to the status URL of your CI server.")
77
86
  runner.should_receive(:propel!)
78
87
 
79
88
  runner.start
80
89
  end
81
90
 
82
- it "should run a command using pull --rebase by default" do
83
- runner = Propel::Runner.new(%w[--quiet])
84
-
85
- runner.logger.should_receive(:warn).with("Remote build is not configured, you should point propel to the status URL of your CI server.")
86
-
87
- runner.should_receive(:system).with("git pull --rebase && rake && git push")
88
- runner.start
89
- end
90
-
91
- it "should run a command using pull without --rebase when --no-rebase is specified" do
92
- runner = Propel::Runner.new(['--no-rebase'])
93
- runner.should_receive(:system).with("git pull && rake && git push")
94
- runner.logger.should_receive(:warn).with("Remote build is not configured, you should point propel to the status URL of your CI server.")
95
-
96
- runner.start
97
- end
98
-
99
91
  it "should wait for the build to pass if the user specifies the --wait option" do
100
- runner = Propel::Runner.new(%w[--wait --quiet])
92
+ runner = Propel::Runner.new(%w[--wait])
101
93
  runner.stub!(:remote_build_configured?).and_return true
102
-
94
+ runner.stub!(:logger).and_return(stub_logger)
95
+
103
96
  runner.should_receive(:remote_build_green?).twice.and_return(false, true)
104
97
 
105
98
  runner.should_receive(:say_duration).and_yield
@@ -3,4 +3,8 @@ Bundler.setup
3
3
 
4
4
  $:.unshift(File.dirname(__FILE__) + '/../lib')
5
5
 
6
- require 'propel'
6
+ require 'propel'
7
+
8
+ def stub_logger
9
+ double('logger', :report_operation => true, :report_status => true, :puts => true, :warn => true)
10
+ end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 3
10
- version: 0.3.3
5
+ version: 0.4.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Justin Leitgeb
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-05-03 00:00:00 -05:00
13
+ date: 2011-05-04 00:00:00 -05:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,9 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
24
  version: "0"
33
25
  type: :runtime
34
26
  version_requirements: *id001
@@ -40,11 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ~>
42
34
  - !ruby/object:Gem::Version
43
- hash: 27
44
- segments:
45
- - 2
46
- - 5
47
- - 0
48
35
  version: 2.5.0
49
36
  type: :development
50
37
  version_requirements: *id002
@@ -71,6 +58,7 @@ files:
71
58
  - lib/propel/git_repository.rb
72
59
  - lib/propel/logger.rb
73
60
  - lib/propel/option_parser.rb
61
+ - lib/propel/propel.rb
74
62
  - lib/propel/remote_build.rb
75
63
  - lib/propel/runner.rb
76
64
  - lib/propel/version.rb
@@ -85,6 +73,7 @@ files:
85
73
  - spec/propel/git_repository_spec.rb
86
74
  - spec/propel/logger_spec.rb
87
75
  - spec/propel/option_parser_spec.rb
76
+ - spec/propel/propel_spec.rb
88
77
  - spec/propel/remote_build_spec.rb
89
78
  - spec/propel/runner_spec.rb
90
79
  - spec/spec_helper.rb
@@ -102,23 +91,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
91
  requirements:
103
92
  - - ">="
104
93
  - !ruby/object:Gem::Version
105
- hash: 3
106
- segments:
107
- - 0
108
94
  version: "0"
109
95
  required_rubygems_version: !ruby/object:Gem::Requirement
110
96
  none: false
111
97
  requirements:
112
98
  - - ">="
113
99
  - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
100
  version: "0"
118
101
  requirements: []
119
102
 
120
103
  rubyforge_project:
121
- rubygems_version: 1.6.2
104
+ rubygems_version: 1.5.2
122
105
  signing_key:
123
106
  specification_version: 3
124
107
  summary: Propel helps you to follow best practices for pushing code to a remote git repo