2012-10-25 22:10:40 +00:00
|
|
|
module Gitlab
|
|
|
|
module Satellite
|
|
|
|
class Action
|
2013-07-16 21:14:03 +00:00
|
|
|
DEFAULT_OPTIONS = { git_timeout: 30.seconds }
|
2012-10-25 22:10:40 +00:00
|
|
|
|
2012-10-25 22:24:02 +00:00
|
|
|
attr_accessor :options, :project, :user
|
2012-10-25 22:10:40 +00:00
|
|
|
|
2012-10-25 22:26:47 +00:00
|
|
|
def initialize(user, project, options = {})
|
|
|
|
@options = DEFAULT_OPTIONS.merge(options)
|
2012-10-25 22:10:40 +00:00
|
|
|
@project = project
|
2012-10-25 22:24:02 +00:00
|
|
|
@user = user
|
2012-10-25 22:10:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
# * Sets a 30s timeout for Git
|
|
|
|
# * Locks the satellite repo
|
|
|
|
# * Yields the prepared satellite repo
|
|
|
|
def in_locked_and_timed_satellite
|
2013-02-14 13:17:43 +00:00
|
|
|
Gitlab::ShellEnv.set_env(user)
|
|
|
|
|
2012-10-25 22:10:40 +00:00
|
|
|
Grit::Git.with_timeout(options[:git_timeout]) do
|
2012-10-25 23:44:20 +00:00
|
|
|
project.satellite.lock do
|
|
|
|
return yield project.satellite.repo
|
2012-10-25 22:10:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue Errno::ENOMEM => ex
|
2013-06-06 21:22:36 +00:00
|
|
|
return handle_exception(ex)
|
2012-10-25 22:10:40 +00:00
|
|
|
rescue Grit::Git::GitTimeout => ex
|
2013-06-06 21:22:36 +00:00
|
|
|
return handle_exception(ex)
|
2013-02-14 13:17:43 +00:00
|
|
|
ensure
|
|
|
|
Gitlab::ShellEnv.reset_env
|
2012-10-25 22:10:40 +00:00
|
|
|
end
|
|
|
|
|
2013-04-25 14:15:33 +00:00
|
|
|
# * Recreates the satellite
|
2012-10-25 22:24:02 +00:00
|
|
|
# * Sets up Git variables for the user
|
|
|
|
#
|
|
|
|
# Note: use this within #in_locked_and_timed_satellite
|
|
|
|
def prepare_satellite!(repo)
|
2012-10-25 23:32:33 +00:00
|
|
|
project.satellite.clear_and_update!
|
2012-10-25 22:24:02 +00:00
|
|
|
|
2013-07-16 21:14:03 +00:00
|
|
|
repo.config['user.name'] = user.name
|
|
|
|
repo.config['user.email'] = user.email
|
2013-04-25 14:15:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def default_options(options = {})
|
|
|
|
{raise: true, timeout: true}.merge(options)
|
2012-10-25 22:24:02 +00:00
|
|
|
end
|
2013-06-06 21:22:36 +00:00
|
|
|
|
|
|
|
def handle_exception(exception)
|
|
|
|
Gitlab::GitLogger.error(exception.message)
|
|
|
|
false
|
|
|
|
end
|
2012-10-25 22:10:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|