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

action.rb « satellite « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 63303ca3de14c9d31a04f08b7630237e82d8c502 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
module Gitlab
  module Satellite
    class Action
      DEFAULT_OPTIONS = { git_timeout: 30.seconds }

      attr_accessor :options, :project, :user

      def initialize(user, project, options = {})
        @options = DEFAULT_OPTIONS.merge(options)
        @project = project
        @user = user
      end

      protected

      # * Sets a 30s timeout for Git
      # * Locks the satellite repo
      # * Yields the prepared satellite repo
      def in_locked_and_timed_satellite
        Gitlab::ShellEnv.set_env(user)

        Grit::Git.with_timeout(options[:git_timeout]) do
          project.satellite.lock do
            return yield project.satellite.repo
          end
        end
      rescue Errno::ENOMEM => ex
        Gitlab::GitLogger.error(ex.message)
        return false
      rescue Grit::Git::GitTimeout => ex
        Gitlab::GitLogger.error(ex.message)
        return false
      ensure
        Gitlab::ShellEnv.reset_env
      end

      # * Clears the satellite
      # * Updates the satellite from Gitolite
      # * Sets up Git variables for the user
      #
      # Note: use this within #in_locked_and_timed_satellite
      def prepare_satellite!(repo)
        project.satellite.clear_and_update!

        repo.git.config({}, "user.name", user.name)
        repo.git.config({}, "user.email", user.email)
      end
    end
  end
end