Use Gitlab::Popen instead of spawn [ci skip]
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
84097def3c
commit
3337130e01
1 changed files with 3 additions and 16 deletions
|
@ -13,24 +13,11 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.execute(file, data)
|
def self.execute(file, data)
|
||||||
# Prepare the hook subprocess. Attach a pipe to its stdin, and merge
|
_output, exit_status = Gitlab::Popen.popen([file]) do |stdin|
|
||||||
# both its stdout and stderr into our own stdout.
|
stdin.write(data.to_json)
|
||||||
stdin_reader, stdin_writer = IO.pipe
|
|
||||||
hook_pid = spawn({}, file, in: stdin_reader, err: :out)
|
|
||||||
stdin_reader.close
|
|
||||||
|
|
||||||
# Submit changes to the hook via its stdin.
|
|
||||||
begin
|
|
||||||
IO.copy_stream(StringIO.new(data.to_json), stdin_writer)
|
|
||||||
rescue Errno::EPIPE
|
|
||||||
# It is not an error if the hook does not consume all of its input.
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Close the pipe to let the hook know there is no further input.
|
exit_status.zero?
|
||||||
stdin_writer.close
|
|
||||||
|
|
||||||
Process.wait(hook_pid)
|
|
||||||
$?.success?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue