summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-03-12 14:39:26 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-03-12 14:39:26 +0000
commit0f4ad24ff2f3ff375153b2e6535f1fd2ca467401 (patch)
tree1a4378fb5f372b4fc1e7e7a7fc0a16b687ab89b9
parentd207d69ba2d74856b81f8c88159cdcdde36d37ca (diff)
parent323545fc87a5527867b9f276d8efc29a27a1468d (diff)
downloadgitlab-shell-0f4ad24ff2f3ff375153b2e6535f1fd2ca467401.tar.gz
Merge branch 'import-timeout' into 'master'v1.8.3
Import Timeout
-rw-r--r--CHANGELOG3
-rw-r--r--README.md6
-rw-r--r--VERSION2
-rw-r--r--lib/gitlab_projects.rb20
-rw-r--r--spec/gitlab_projects_spec.rb37
5 files changed, 57 insertions, 11 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 355eb03..2f50ec6 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+v1.8.3
+ - Add timeout option for repository import
+
v1.8.2
- Fix broken 1.8.1
diff --git a/README.md b/README.md
index fee7b53..b194039 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/VERSION b/VERSION
index 53adb84..a7ee35a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.8.2
+1.8.3
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index a0063aa..38a3a7d 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -1,4 +1,5 @@
require 'fileutils'
+require 'timeout'
require_relative 'gitlab_config'
require_relative 'gitlab_logger'
@@ -92,9 +93,26 @@ 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)
+
+ pid = Process.spawn(*cmd)
+
+ begin
+ Timeout.timeout(timeout) do
+ Process.wait(pid)
+ end
+ rescue Timeout::Error
+ Process.kill('KILL', pid)
+ $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
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb
index dbdbfd9..c60febb 100644
--- a/spec/gitlab_projects_spec.rb
+++ b/spec/gitlab_projects_spec.rb
@@ -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://github.com/gitlabhq/gitlabhq.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://github.com/gitlabhq/gitlabhq.git> failed due to timeout."
+ $logger.should_receive(:error).with(message)
+ gl_projects.exec
+ end
end
end