Added detection and handling of exsiting repos

This commit is contained in:
Jeremy Mack 2011-12-15 16:55:53 -05:00
parent 60fee48eaa
commit 3fd3e1fcdf

View file

@ -20,19 +20,26 @@ task :import_projects, [:email] => :environment do |t, args|
clone_path = "#{REPOSITORY_DIRECTORY}/#{repo_name}.git" clone_path = "#{REPOSITORY_DIRECTORY}/#{repo_name}.git"
if Dir.exists? clone_path if Dir.exists? clone_path
puts " INFO: #{clone_path} already exists in repositories directory, skipping." if Project.find_by_code(repo_name)
skipped_count += 1 puts " INFO: #{clone_path} already exists in repositories directory, skipping."
next skipped_count += 1
else next
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
else else
failed_count += 1 puts " INFO: Project doesn't exist for #{repo_name} (but the repo does)."
end 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
end end
@ -61,13 +68,25 @@ def create_repo_project(project_name, user_email)
puts " INFO: Project #{project_name} already exists in Gitlab, skipping." puts " INFO: Project #{project_name} already exists in Gitlab, skipping."
false false
else else
project = Project.create( project = nil
name: project_name, if Project.find_by_code(project_name)
code: project_name, puts " ERROR: Project already exists #{project_name}"
path: project_name, return false
owner: user, project = Project.find_by_code(project_name)
description: "Automatically created from Rake on #{Time.now.to_s}" 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 # Add user as admin for project
project.users_projects.create!( project.users_projects.create!(
@ -82,7 +101,7 @@ def create_repo_project(project_name, user_email)
if project.valid? if project.valid?
true true
else else
puts " ERROR: Failed to create project #{project} because #{project.errors}" puts " ERROR: Failed to create project #{project} because #{project.errors.first}"
false false
end end
end end