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
e38fa328
Commit
e38fa328
authored
Dec 13, 2011
by
Jeremy Mack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Calling update_repository
- Better comment too
parent
5bc97fbd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
0 deletions
+94
-0
lib/tasks/bulk_import.rake
lib/tasks/bulk_import.rake
+94
-0
No files found.
lib/tasks/bulk_import.rake
0 → 100644
View file @
e38fa328
IMPORT_DIRECTORY
=
'import_projects'
REPOSITORY_DIRECTORY
=
'/home/git/repositories'
desc
"Imports existing Git repos into new projects from the import_projects folder"
task
:import_projects
,
[
:email
]
=>
:environment
do
|
t
,
args
|
user_email
=
args
.
email
repos_to_import
=
Dir
.
glob
(
"
#{
IMPORT_DIRECTORY
}
/*"
)
puts
"Found
#{
repos_to_import
.
length
}
repos to import"
imported_count
=
0
skipped_count
=
0
failed_count
=
0
repos_to_import
.
each
do
|
repo_path
|
repo_name
=
File
.
basename
repo_path
repo_full_path
=
File
.
join
(
Rails
.
root
,
repo_path
)
puts
" Processing
#{
repo_name
}
"
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
else
failed_count
+=
1
end
end
end
puts
"Finished importing
#{
imported_count
}
projects (skipped
#{
skipped_count
}
, failed
#{
failed_count
}
)."
end
# Clones a repo as bare git repo using the git user
def
clone_bare_repo_as_git
(
existing_path
,
new_path
)
begin
sh
"sudo -u git -i git clone --bare '
#{
existing_path
}
'
#{
new_path
}
"
true
rescue
puts
" ERROR: Faild to clone
#{
existing_path
}
to
#{
new_path
}
"
false
end
end
# Creats a project in Gitlag given a @project_name@ to use (for name, web url, and code
# url) and a @user_email@ that will be assigned as the owner of the project.
def
create_repo_project
(
project_name
,
user_email
)
user
=
User
.
find_by_email
(
user_email
)
if
user
# Using find_by_code since that's the most important identifer to be unique
if
Project
.
find_by_code
(
project_name
)
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 CVS on
#{
Time
.
now
.
to_s
}
"
)
# Add user as admin for project
project
.
users_projects
.
create!
(
:repo_access
=>
Repository
::
REPO_RW
,
:project_access
=>
Project
::
PROJECT_RWA
,
:user
=>
user
)
# Per projects_controller.rb#37
project
.
update_repository
if
project
.
valid?
true
else
puts
" ERROR: Failed to create project
#{
project
}
because
#{
project
.
errors
}
"
false
end
end
else
puts
" ERROR:
#{
user_email
}
not found, skipping"
false
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