Class: ConditionalDcommit::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/conditional_dcommit/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#status_codeObject

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

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/conditional_dcommit/command.rb', line 22

def code_tests_ok?
  puts "testing code"
  system(test_command) ? true : false
end

#dcommitObject



27
28
29
30
# File 'lib/conditional_dcommit/command.rb', line 27

def dcommit
  puts "dcommitting"
  system("git svn dcommit") ? true : false
end

#growl(title, message, image, stick = "yes") ⇒ Object



78
79
80
81
82
# File 'lib/conditional_dcommit/command.rb', line 78

def growl(title, message, image, stick="yes")
  growlNotify_file = Package.data_file('growlNotify.applescript')

  system "osascript #{growlNotify_file} '#{title}' '#{message}' '#{image}' #{stick}"
end

#mainObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/conditional_dcommit/command.rb', line 84

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

#rebaseObject

Raises:

  • (StandardError)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/conditional_dcommit/command.rb', line 32

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}"

  matcher = /Current branch .* is up to date./

  if (firsterror && firsterror.chomp =~ matcher) ||
     (firstline && firstline.chomp =~ matcher)
    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



66
67
68
69
70
# File 'lib/conditional_dcommit/command.rb', line 66

def report_fail(message="Failed dcommit")
  puts message
  self.status_code = 255
  growl('FAIL', message, Package.data_file('stop_sign.jpg'))
end

#report_success(message = "Successful dcommit") ⇒ Object



72
73
74
75
76
# File 'lib/conditional_dcommit/command.rb', line 72

def report_success(message="Successful dcommit")
  puts message
  self.status_code = 0
  growl('Success', message, Package.data_file('traffic_green.jpg'))
end

#test_commandObject



12
13
14
15
16
17
18
19
20
# File 'lib/conditional_dcommit/command.rb', line 12

def test_command
  @test_command ||= if env_command = ENV['TEST_COMMAND']
                      env_command
                    elsif(File.exists?(cruise_file=File.join(%w{script cruise})))
                      cruise_file
                    else
                      'rake'
                    end
end