diff options
author | Jeremy Mack <jmacktdkc@gmail.com> | 2011-12-16 01:55:53 +0400 |
---|---|---|
committer | Jeremy Mack <jmacktdkc@gmail.com> | 2011-12-16 01:55:53 +0400 |
commit | 3fd3e1fcdf69e8544b25193a6e2a53716c65096c (patch) | |
tree | d68861be87f7b79a86aa4d38b546d387e924a0f1 /lib | |
parent | 60fee48eaa98bf859613160dcad87b8f0908aac6 (diff) |
Added detection and handling of exsiting repos
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tasks/bulk_import.rake | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/lib/tasks/bulk_import.rake b/lib/tasks/bulk_import.rake index f463f3b061c..de00a68ad4d 100644 --- a/lib/tasks/bulk_import.rake +++ b/lib/tasks/bulk_import.rake @@ -20,21 +20,28 @@ task :import_projects, [:email] => :environment do |t, args| clone_path = "#{REPOSITORY_DIRECTORY}/#{repo_name}.git" if Dir.exists? clone_path - puts " INFO: #{clone_path} already exists in repositories directory, skipping." - skipped_count += 1 - next - else - if clone_bare_repo_as_git(repo_full_path, clone_path) - if create_repo_project(repo_name, user_email) - imported_count += 1 - else - failed_count += 1 - end + if Project.find_by_code(repo_name) + puts " INFO: #{clone_path} already exists in repositories directory, skipping." + skipped_count += 1 + next else + puts " INFO: Project doesn't exist for #{repo_name} (but the repo does)." + end + else + # Clone the repo + unless clone_bare_repo_as_git(repo_full_path, clone_path) failed_count += 1 + next end end + # Create the project and repo + if create_repo_project(repo_name, user_email) + imported_count += 1 + else + failed_count += 1 + end + end puts "Finished importing #{imported_count} projects (skipped #{skipped_count}, failed #{failed_count})." @@ -61,13 +68,25 @@ def create_repo_project(project_name, user_email) puts " INFO: Project #{project_name} already exists in Gitlab, skipping." false else - project = Project.create( - name: project_name, - code: project_name, - path: project_name, - owner: user, - description: "Automatically created from Rake on #{Time.now.to_s}" - ) + project = nil + if Project.find_by_code(project_name) + puts " ERROR: Project already exists #{project_name}" + return false + project = Project.find_by_code(project_name) + else + project = Project.create( + name: project_name, + code: project_name, + path: project_name, + owner: user, + description: "Automatically created from Rake on #{Time.now.to_s}" + ) + end + + unless project.valid? + puts " ERROR: Failed to create project #{project} because #{project.errors.first}" + return false + end # Add user as admin for project project.users_projects.create!( @@ -82,7 +101,7 @@ def create_repo_project(project_name, user_email) if project.valid? true else - puts " ERROR: Failed to create project #{project} because #{project.errors}" + puts " ERROR: Failed to create project #{project} because #{project.errors.first}" false end end |