2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
module Gitlab
|
2020-03-13 15:44:24 +05:30
|
|
|
module FileHook
|
2020-01-12 00:16:45 +05:30
|
|
|
def self.any?
|
2020-04-22 19:07:51 +05:30
|
|
|
dir_glob.any? { |entry| File.file?(entry) }
|
2020-01-12 00:16:45 +05:30
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
def self.files
|
2020-04-22 19:07:51 +05:30
|
|
|
dir_glob.select { |entry| File.file?(entry) }
|
2020-01-12 00:16:45 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
def self.dir_glob
|
|
|
|
Dir.glob([Rails.root.join('file_hooks/*'), Rails.root.join('plugins/*')])
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
private_class_method :dir_glob
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
def self.execute_all_async(data)
|
|
|
|
args = files.map { |file| [file, data] }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
FileHookWorker.bulk_perform_async(args) # rubocop:disable Scalability/BulkPerformWithContext
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def self.execute(file, data)
|
|
|
|
result = Gitlab::Popen.popen_with_detail([file]) do |stdin|
|
|
|
|
stdin.write(data.to_json)
|
|
|
|
end
|
|
|
|
|
|
|
|
exit_status = result.status&.exitstatus
|
2020-10-24 23:57:45 +05:30
|
|
|
[exit_status == 0, result.stderr]
|
2018-03-27 19:54:05 +05:30
|
|
|
rescue => e
|
|
|
|
[false, e.message]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|