action.rb 1.24 KB
Newer Older
1 2 3 4 5
module Gitlab
  module Satellite
    class Action
      DEFAULT_OPTIONS = { git_timeout: 30.seconds }

6
      attr_accessor :options, :project, :user
7

8 9
      def initialize(user, project, options = {})
        @options = DEFAULT_OPTIONS.merge(options)
10
        @project = project
11
        @user = user
12 13 14 15 16 17 18 19 20
      end

      protected

      # * Sets a 30s timeout for Git
      # * Locks the satellite repo
      # * Yields the prepared satellite repo
      def in_locked_and_timed_satellite
        Grit::Git.with_timeout(options[:git_timeout]) do
21 22
          project.satellite.lock do
            return yield project.satellite.repo
23 24 25 26 27 28 29 30 31 32
          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
      end

33 34 35 36 37 38
      # * 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)
39
        project.satellite.clear_and_update!
40 41 42 43

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