Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
3fd3e1fc
Commit
3fd3e1fc
authored
Dec 15, 2011
by
Jeremy Mack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added detection and handling of exsiting repos
parent
60fee48e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
18 deletions
+37
-18
lib/tasks/bulk_import.rake
lib/tasks/bulk_import.rake
+37
-18
No files found.
lib/tasks/bulk_import.rake
View file @
3fd3e1fc
...
@@ -20,20 +20,27 @@ task :import_projects, [:email] => :environment do |t, args|
...
@@ -20,20 +20,27 @@ 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
if
Project
.
find_by_code
(
repo_name
)
puts
" INFO:
#{
clone_path
}
already exists in repositories directory, skipping."
puts
" INFO:
#{
clone_path
}
already exists in repositories directory, skipping."
skipped_count
+=
1
skipped_count
+=
1
next
next
else
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)."
if
create_repo_project
(
repo_name
,
user_email
)
end
imported_count
+=
1
else
else
# Clone the repo
unless
clone_bare_repo_as_git
(
repo_full_path
,
clone_path
)
failed_count
+=
1
failed_count
+=
1
next
end
end
end
# Create the project and repo
if
create_repo_project
(
repo_name
,
user_email
)
imported_count
+=
1
else
else
failed_count
+=
1
failed_count
+=
1
end
end
end
end
end
...
@@ -60,6 +67,12 @@ def create_repo_project(project_name, user_email)
...
@@ -60,6 +67,12 @@ def create_repo_project(project_name, user_email)
if
Project
.
find_by_code
(
project_name
)
if
Project
.
find_by_code
(
project_name
)
puts
" INFO: Project
#{
project_name
}
already exists in Gitlab, skipping."
puts
" INFO: Project
#{
project_name
}
already exists in Gitlab, skipping."
false
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
else
project
=
Project
.
create
(
project
=
Project
.
create
(
name:
project_name
,
name:
project_name
,
...
@@ -68,6 +81,12 @@ def create_repo_project(project_name, user_email)
...
@@ -68,6 +81,12 @@ def create_repo_project(project_name, user_email)
owner:
user
,
owner:
user
,
description:
"Automatically created from Rake on
#{
Time
.
now
.
to_s
}
"
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)
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment