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

hooks_service.rb « git « gitlab « lib « ruby - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 67ac4c3fb39d7ca272631f1a175aa37f66b1d057 (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
36
37
module Gitlab
  module Git
    class HooksService
      attr_accessor :oldrev, :newrev, :ref

      def execute(pusher, repository, oldrev, newrev, ref, push_options:, transaction: nil)
        @repository  = repository
        @gl_id       = pusher.gl_id
        @gl_username = pusher.username
        @oldrev      = oldrev
        @newrev      = newrev
        @ref         = ref
        @push_options = push_options
        @transaction = transaction

        %w[pre-receive update reference-transaction].each do |hook_name|
          status, message = run_hook(hook_name)

          raise PreReceiveError, message unless status
        end

        yield(self).tap do
          status, message = run_hook('post-receive')

          Gitlab::GitLogger.error("post-receive hook: #{message}") unless status
        end
      end

      private

      def run_hook(name)
        hook = Gitlab::Git::Hook.new(name, @repository)
        hook.trigger(@gl_id, @gl_username, oldrev, newrev, ref, push_options: @push_options, transaction: @transaction)
      end
    end
  end
end