Welcome to mirror list, hosted at ThFree Co, Russian Federation.

file_hook.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e398a3f9585595bf9126eeb3a00a3858f810e725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

module Gitlab
  module FileHook
    def self.any?
      dir_glob.any? { |entry| File.file?(entry) }
    end

    def self.files
      dir_glob.select { |entry| File.file?(entry) }
    end

    def self.dir_glob
      Dir.glob([Rails.root.join('file_hooks/*'), Rails.root.join('plugins/*')])
    end
    private_class_method :dir_glob

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

      FileHookWorker.bulk_perform_async(args) # rubocop:disable Scalability/BulkPerformWithContext
    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
      [exit_status == 0, result.stderr]
    rescue StandardError => e
      [false, e.message]
    end
  end
end