Commit 5f9d78fd authored by James E. Flemer's avatar James E. Flemer

Include groups in import with import repos rake task

Expand the import glob to include `**/*.git` to find projects in groups
as well as top level projects.  Check for existing group, and create
group if needed.  Set namespace_id for imported projects.
parent d58aca06
...@@ -116,6 +116,8 @@ bundle exec rake gitlab:satellites:create RAILS_ENV=production ...@@ -116,6 +116,8 @@ bundle exec rake gitlab:satellites:create RAILS_ENV=production
Notes: Notes:
* project owner will be a first admin * project owner will be a first admin
* groups will be created as needed
* group owner will be the first admin
* existing projects will be skipped * existing projects will be skipped
How to use: How to use:
...@@ -132,5 +134,8 @@ Example output: ...@@ -132,5 +134,8 @@ Example output:
``` ```
Processing abcd.git Processing abcd.git
* Created abcd (abcd.git) * Created abcd (abcd.git)
Processing group/xyz.git
* Created Group group (2)
* Created xyz (group/xyz.git)
[...] [...]
``` ```
...@@ -13,42 +13,61 @@ namespace :gitlab do ...@@ -13,42 +13,61 @@ namespace :gitlab do
task repos: :environment do task repos: :environment do
git_base_path = Gitlab.config.gitlab_shell.repos_path git_base_path = Gitlab.config.gitlab_shell.repos_path
repos_to_import = Dir.glob(git_base_path + '/*') repos_to_import = Dir.glob(git_base_path + '/**/*.git')
namespaces = Namespace.pluck(:path) namespaces = Namespace.pluck(:path)
repos_to_import.each do |repo_path| repos_to_import.each do |repo_path|
repo_name = File.basename repo_path # strip repo base path
repo_path[0..git_base_path.length] = ''
# Skip if group or user path = repo_path.sub(/\.git$/, '')
next if namespaces.include?(repo_name) name = File.basename path
group_name = File.dirname path
group_name = nil if group_name == '.'
# skip if not git repo # Skip if group or user
next unless repo_name =~ /.git$/ next if namespaces.include?(name)
next if repo_name == 'gitolite-admin.git' next if name == 'gitolite-admin'
path = repo_name.sub(/\.git$/, '') puts "Processing #{repo_path}".yellow
project = Project.find_with_namespace(path) project = Project.find_with_namespace(path)
puts "Processing #{repo_name}".yellow
if project if project
puts " * #{project.name} (#{repo_name}) exists" puts " * #{project.name} (#{repo_path}) exists"
else else
user = User.admins.first user = User.admins.first
project_params = { project_params = {
name: path, name: name,
} }
# find group namespace
if group_name
group = Group.find_by_path(group_name)
# create group namespace
if !group
group = Group.new(:name => group_name)
group.path = group_name
group.owner = user
if group.save
puts " * Created Group #{group.name} (#{group.id})".green
else
puts " * Failed trying to create group #{group.name}".red
end
end
# set project group
project_params[:namespace_id] = group.id
end
project = Projects::CreateContext.new(user, project_params).execute project = Projects::CreateContext.new(user, project_params).execute
if project.valid? if project.valid?
puts " * Created #{project.name} (#{repo_name})".green puts " * Created #{project.name} (#{repo_path})".green
else else
puts " * Failed trying to create #{project.name} (#{repo_name})".red puts " * Failed trying to create #{project.name} (#{repo_path})".red
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment