Skip to content

Commit

Permalink
extract CommandRunner::Result
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Jul 26, 2010
1 parent 4ddded8 commit 52e9d22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
10 changes: 4 additions & 6 deletions lib/integrity/builder.rb
Expand Up @@ -8,8 +8,6 @@ def initialize(build, directory, logger)
@build = build
@directory = directory
@logger = logger
@status = false
@output = ""
end

def build
Expand All @@ -26,16 +24,16 @@ def start
end

def run
@status, @output = checkout.run_in_dir(command)
@result = checkout.run_in_dir(command)
end

def complete
@logger.info "Build #{commit} exited with #{@status} got:\n #{@output}"
@logger.info "Build #{commit} exited with #{@result.success} got:\n #{@result.output}"

@build.update(
:completed_at => Time.now,
:successful => @status,
:output => @output
:successful => @result.success,
:output => @result.output
)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/integrity/checkout.rb
Expand Up @@ -21,12 +21,12 @@ def metadata
format = "---%nidentifier: %H%nauthor: %an " \
"<%ae>%nmessage: >-%n %s%ncommitted_at: %ci%n"

output = run_in_dir!(
result = run_in_dir!(
"cd #{@directory} && git show -s " \
"--pretty=format:\"#{format}\" #{sha1}"
)

dump = YAML.load(output)
dump = YAML.load(result.output)

dump.update("committed_at" => Time.parse(dump["committed_at"]))
end
Expand All @@ -35,7 +35,7 @@ def head
runner.run!(
"git ls-remote --heads #{@repo.uri} #{@repo.branch} " \
"| cut -f1"
)
).output
end

def run_in_dir(command)
Expand Down
10 changes: 6 additions & 4 deletions lib/integrity/command_runner.rb
Expand Up @@ -2,6 +2,8 @@ module Integrity
class CommandRunner
class Error < StandardError; end

Result = Struct.new(:success, :output)

def initialize(logger)
@logger = logger
end
Expand All @@ -21,18 +23,18 @@ def run(command)
output = ""
IO.popen(cmd, "r") { |io| output = io.read }

[$?.success?, output.chomp]
Result.new($?.success?, output.chomp)
end

def run!(command)
success, output = run(command)
result = run(command)

unless success
unless result.success
@logger.error(output.inspect)
raise Error, "Failed to run '#{command}'"
end

output
result
end

def normalize(cmd)
Expand Down

0 comments on commit 52e9d22

Please sign in to comment.