2018-02-19 17:20:53 +00:00
|
|
|
module Gitlab
|
|
|
|
module Plugin
|
2018-02-19 17:55:54 +00:00
|
|
|
def self.files
|
2018-02-23 13:58:57 +00:00
|
|
|
Dir.glob(Rails.root.join('plugins/enabled/*'))
|
2018-02-19 17:55:54 +00:00
|
|
|
end
|
2018-02-19 17:20:53 +00:00
|
|
|
|
2018-02-19 17:55:54 +00:00
|
|
|
def self.execute_all_async(data)
|
|
|
|
files.each do |file|
|
2018-02-23 13:58:57 +00:00
|
|
|
puts file
|
2018-02-19 17:55:54 +00:00
|
|
|
PluginWorker.perform_async(file, data)
|
2018-02-19 17:20:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-19 17:55:54 +00:00
|
|
|
def self.execute(file, data)
|
2018-02-23 13:58:57 +00:00
|
|
|
# Prepare the hook subprocess. Attach a pipe to its stdin, and merge
|
|
|
|
# both its stdout and stderr into our own stdout.
|
|
|
|
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
|
|
|
|
|
|
|
|
# Close the pipe to let the hook know there is no further input.
|
|
|
|
stdin_writer.close
|
|
|
|
|
|
|
|
Process.wait(hook_pid)
|
|
|
|
$?.success?
|
2018-02-19 17:20:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|