Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
37e39e41
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
37e39e41
编写于
10月 30, 2012
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added bare import script. Removed old unworking script
上级
36dbac2f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
83 deletion
+54
-83
lib/tasks/bulk_import.rake
lib/tasks/bulk_import.rake
+0
-83
lib/tasks/gitlab/import.rake
lib/tasks/gitlab/import.rake
+54
-0
未找到文件。
lib/tasks/bulk_import.rake
已删除
100644 → 0
浏览文件 @
36dbac2f
desc
"Imports existing Git repos from a directory into new projects in git_base_path"
task
:import_projects
,
[
:directory
,
:email
]
=>
:environment
do
|
t
,
args
|
user_email
,
import_directory
=
args
.
email
,
args
.
directory
repos_to_import
=
Dir
.
glob
(
"
#{
import_directory
}
/*"
)
git_base_path
=
Gitlab
.
config
.
git_base_path
imported_count
,
skipped_count
,
failed_count
=
0
puts
"Found
#{
repos_to_import
.
size
}
repos to import"
repos_to_import
.
each
do
|
repo_path
|
repo_name
=
File
.
basename
repo_path
clone_path
=
"
#{
git_base_path
}#{
repo_name
}
.git"
puts
" Processing
#{
repo_name
}
"
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
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_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
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
)
git_user
=
Gitlab
.
config
.
ssh_user
begin
sh
"sudo -u
#{
git_user
}
-i git clone --bare '
#{
existing_path
}
'
#{
new_path
}
"
rescue
Exception
=>
msg
puts
" ERROR: Failed to clone
#{
existing_path
}
to
#{
new_path
}
"
puts
" Make sure
#{
git_user
}
can reach
#{
existing_path
}
"
puts
" Exception-MSG:
#{
msg
}
"
end
end
# Creates a project in GitLab 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
)
if
user
=
User
.
find_by_email
(
user_email
)
# 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."
else
project
=
Project
.
create
(
name:
project_name
,
code:
project_name
,
path:
project_name
,
owner:
user
,
description:
"Automatically created from 'import_projects' rake task on
#{
Time
.
now
}
"
)
if
project
.
valid?
# Add user as admin for project
project
.
users_projects
.
create!
(
:project_access
=>
UsersProject
::
MASTER
,
:user
=>
user
)
project
.
update_repository
else
puts
" ERROR: Failed to create project
#{
project
}
because
#{
project
.
errors
.
first
}
"
end
end
else
puts
" ERROR: user with
#{
user_email
}
not found, skipping"
end
end
lib/tasks/gitlab/import.rake
0 → 100644
浏览文件 @
37e39e41
namespace
:gitlab
do
namespace
:import
do
# How to use:
#
# 1. copy your bare repos under git base_path
# 2. run bundle exec rake gitlab:import:repos RAILS_ENV=production
#
# Notes:
# * project owner will be a first admin
# * existing projects will be skipped
#
desc
"GITLAB | Import bare repositories from git_host -> base_path into GitLab project instance"
task
:repos
=>
:environment
do
git_base_path
=
Gitlab
.
config
.
git_base_path
repos_to_import
=
Dir
.
glob
(
git_base_path
+
'/*'
)
repos_to_import
.
each
do
|
repo_path
|
repo_name
=
File
.
basename
repo_path
# skip gitolite admin
next
if
repo_name
==
'gitolite-admin.git'
path
=
repo_name
.
sub
(
/\.git$/
,
''
)
project
=
Project
.
find_by_path
(
path
)
puts
"Processing
#{
repo_name
}
"
.
yellow
if
project
puts
" *
#{
project
.
name
}
(
#{
repo_name
}
) exists"
else
user
=
User
.
admins
.
first
project_params
=
{
:name
=>
path
,
:code
=>
path
,
:path
=>
path
,
}
project
=
Project
.
create_by_user
(
project_params
,
user
)
if
project
.
valid?
puts
" * Created
#{
project
.
name
}
(
#{
repo_name
}
)"
.
green
else
puts
" * Failed trying to create
#{
project
.
name
}
(
#{
repo_name
}
)"
.
red
end
end
end
puts
"Done!"
.
green
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录