Class: ConditionalDcommit::Command
- Inherits:
-
Object
- Object
- ConditionalDcommit::Command
- Defined in:
- lib/conditional_dcommit/command.rb
Instance Attribute Summary collapse
-
#status_code ⇒ Object
Returns the value of attribute status_code.
Instance Method Summary collapse
- #code_tests_ok? ⇒ Boolean
- #dcommit ⇒ Object
- #growl(title, message, image, stick = "yes") ⇒ Object
- #main ⇒ Object
- #rebase ⇒ Object
- #report_fail(message = "Failed dcommit") ⇒ Object
- #report_success(message = "Successful dcommit") ⇒ Object
- #test_command ⇒ Object
Instance Attribute Details
#status_code ⇒ Object
Returns the value of attribute status_code.
10 11 12 |
# File 'lib/conditional_dcommit/command.rb', line 10 def status_code @status_code end |
Instance Method Details
#code_tests_ok? ⇒ Boolean
16 17 18 19 |
# File 'lib/conditional_dcommit/command.rb', line 16 def code_tests_ok? puts "testing code" system(test_command) ? true : false end |
#dcommit ⇒ Object
21 22 23 24 |
# File 'lib/conditional_dcommit/command.rb', line 21 def dcommit puts "dcommitting" system("git svn dcommit") ? true : false end |
#growl(title, message, image, stick = "yes") ⇒ Object
69 70 71 72 73 |
# File 'lib/conditional_dcommit/command.rb', line 69 def growl(title, , image, stick="yes") growlNotify_file = Package.data_file('growlNotify.applescript') system "osascript #{growlNotify_file} '#{title}' '#{message}' '#{image}' #{stick}" end |
#main ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/conditional_dcommit/command.rb', line 75 def main self.status_code = 254 begin rebase 5.times do if code_tests_ok? unless rebase raise StandardError.new("Error dcommitting") unless dcommit report_success break end else raise StandardError.new("Code tests failed") end end && report_fail("Too many tries") rescue StandardError => err report_fail(err.to_s) end self.status_code end |
#rebase ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/conditional_dcommit/command.rb', line 26 def rebase puts "rebasing" pid, stdin, stdout, stderr = Open4.popen4('git svn rebase') firstline = nil until (firstline = stdout.gets) || (firsterror = stderr.gets) end puts "firstline: #{firstline}" puts "firsterror: #{firsterror}" if firsterror && firsterror.chomp =~ /Current branch .* is up to date./ retval = false else puts firstline || firsterror while line = stdout.gets || stderr.gets puts line end retval = true end ignored, status = Process::waitpid2 pid raise StandardError.new("Error rebasing") if status != 0 puts "rebase return: #{retval.to_s}" retval end |
#report_fail(message = "Failed dcommit") ⇒ Object
57 58 59 60 61 |
# File 'lib/conditional_dcommit/command.rb', line 57 def report_fail(="Failed dcommit") puts self.status_code = 255 growl('FAIL', , Package.data_file('stop_sign.jpg')) end |
#report_success(message = "Successful dcommit") ⇒ Object
63 64 65 66 67 |
# File 'lib/conditional_dcommit/command.rb', line 63 def report_success(="Successful dcommit") puts self.status_code = 0 growl('Success', , Package.data_file('traffic_green.jpg')) end |
#test_command ⇒ Object
12 13 14 |
# File 'lib/conditional_dcommit/command.rb', line 12 def test_command @test_command ||= ENV['TEST_COMMAND'] || 'script/cruise' end |