2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-02-19 12:20:53 -05:00
|
|
|
module Gitlab
|
2020-01-16 10:08:41 -05:00
|
|
|
module FileHook
|
2020-01-06 04:07:42 -05:00
|
|
|
def self.any?
|
|
|
|
plugin_glob.any? { |entry| File.file?(entry) }
|
|
|
|
end
|
|
|
|
|
2018-02-19 12:55:54 -05:00
|
|
|
def self.files
|
2020-01-06 04:07:42 -05:00
|
|
|
plugin_glob.select { |entry| File.file?(entry) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.plugin_glob
|
|
|
|
Dir.glob(Rails.root.join('plugins/*'))
|
2018-02-19 12:55:54 -05:00
|
|
|
end
|
2018-02-19 12:20:53 -05:00
|
|
|
|
2018-02-19 12:55:54 -05:00
|
|
|
def self.execute_all_async(data)
|
2018-02-26 07:15:51 -05:00
|
|
|
args = files.map { |file| [file, data] }
|
|
|
|
|
2020-01-16 10:08:41 -05:00
|
|
|
FileHookWorker.bulk_perform_async(args)
|
2018-02-19 12:20:53 -05:00
|
|
|
end
|
|
|
|
|
2018-02-19 12:55:54 -05:00
|
|
|
def self.execute(file, data)
|
2018-02-27 11:08:38 -05:00
|
|
|
result = Gitlab::Popen.popen_with_detail([file]) do |stdin|
|
2018-02-26 06:42:25 -05:00
|
|
|
stdin.write(data.to_json)
|
2018-02-23 08:58:57 -05:00
|
|
|
end
|
|
|
|
|
2018-02-27 11:08:38 -05:00
|
|
|
exit_status = result.status&.exitstatus
|
2018-02-28 05:16:23 -05:00
|
|
|
[exit_status.zero?, result.stderr]
|
2018-02-27 11:08:38 -05:00
|
|
|
rescue => e
|
2018-02-28 05:16:23 -05:00
|
|
|
[false, e.message]
|
2018-02-19 12:20:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|