Added detection and handling of exsiting repos
This commit is contained in:
parent
60fee48eaa
commit
3fd3e1fcdf
1 changed files with 38 additions and 19 deletions
|
@ -20,20 +20,27 @@ task :import_projects, [:email] => :environment do |t, args|
|
|||
clone_path = "#{REPOSITORY_DIRECTORY}/#{repo_name}.git"
|
||||
|
||||
if Dir.exists? clone_path
|
||||
if Project.find_by_code(repo_name)
|
||||
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)
|
||||
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
|
||||
else
|
||||
failed_count += 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -60,6 +67,12 @@ def create_repo_project(project_name, user_email)
|
|||
if Project.find_by_code(project_name)
|
||||
puts " INFO: Project #{project_name} already exists in Gitlab, skipping."
|
||||
false
|
||||
else
|
||||
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,
|
||||
|
@ -68,6 +81,12 @@ def create_repo_project(project_name, user_email)
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue