file_hook.rb 735 Bytes
Newer Older
1 2
# frozen_string_literal: true

3
module Gitlab
4
  module FileHook
5 6 7 8
    def self.any?
      plugin_glob.any? { |entry| File.file?(entry) }
    end

9
    def self.files
10 11 12 13 14
      plugin_glob.select { |entry| File.file?(entry) }
    end

    def self.plugin_glob
      Dir.glob(Rails.root.join('plugins/*'))
15
    end
16

17
    def self.execute_all_async(data)
18 19
      args = files.map { |file| [file, data] }

20
      FileHookWorker.bulk_perform_async(args)
21 22
    end

23
    def self.execute(file, data)
24
      result = Gitlab::Popen.popen_with_detail([file]) do |stdin|
25
        stdin.write(data.to_json)
26 27
      end

28
      exit_status = result.status&.exitstatus
29
      [exit_status.zero?, result.stderr]
30
    rescue => e
31
      [false, e.message]
32 33 34
    end
  end
end