Skip to content
Snippets Groups Projects
Verified Commit c8a713cb authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Add support for import repo timeout

parent 3df55367
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -36,7 +36,11 @@ Remove repo
 
Import repo
 
./bin/gitlab-projects import-project randx/six.git https://github.com/randx/six.git
# Default timeout is 2 minutes
./bin/gitlab-projects import-project randx/six.git https://github.com/randx/six.git
# Override timeout in seconds
./bin/gitlab-projects import-project randx/six.git https://github.com/randx/six.git 90
 
Fork repo
 
Loading
Loading
require 'fileutils'
require 'timeout'
 
require_relative 'gitlab_config'
require_relative 'gitlab_logger'
Loading
Loading
@@ -92,9 +93,23 @@ class GitlabProjects
# URL must be publicly cloneable
def import_project
@source = ARGV.shift
# timeout for clone
timeout = (ARGV.shift || 120).to_i
$logger.info "Importing project #{@project_name} from <#{@source}> to <#{full_path}>."
cmd = %W(git clone --bare -- #{@source} #{full_path})
system(*cmd) && self.class.create_hooks(full_path)
begin
Timeout.timeout(timeout) do
system(*cmd)
end
rescue
$logger.error "Importing project #{@project_name} from <#{@source}> failed due to timeout."
FileUtils.rm_rf(full_path)
false
else
self.class.create_hooks(full_path)
end
end
 
# Move repository from one directory to another
Loading
Loading
Loading
Loading
@@ -196,17 +196,38 @@ describe GitlabProjects do
end
 
describe :import_project do
let(:gl_projects) { build_gitlab_projects('import-project', repo_name, 'https://github.com/randx/six.git') }
context 'success import' do
let(:gl_projects) { build_gitlab_projects('import-project', repo_name, 'https://github.com/randx/six.git') }
 
it "should import a repo" do
gl_projects.exec
File.exists?(File.join(tmp_repo_path, 'HEAD')).should be_true
it { gl_projects.exec.should be_true }
it "should import a repo" do
gl_projects.exec
File.exists?(File.join(tmp_repo_path, 'HEAD')).should be_true
end
it "should log an import-project event" do
message = "Importing project #{repo_name} from <https://github.com/randx/six.git> to <#{tmp_repo_path}>."
$logger.should_receive(:info).with(message)
gl_projects.exec
end
end
 
it "should log an import-project event" do
message = "Importing project #{repo_name} from <https://github.com/randx/six.git> to <#{tmp_repo_path}>."
$logger.should_receive(:info).with(message)
gl_projects.exec
context 'timeout' do
let(:gl_projects) { build_gitlab_projects('import-project', repo_name, 'https://dev.gitlab.org/samples/private.git', '1') }
it { gl_projects.exec.should be_false }
it "should not import a repo" do
gl_projects.exec
File.exists?(File.join(tmp_repo_path, 'HEAD')).should be_false
end
it "should log an import-project event" do
message = "Importing project #{repo_name} from <https://dev.gitlab.org/samples/private.git> failed due to timeout."
$logger.should_receive(:error).with(message)
gl_projects.exec
end
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment