|
|
|
@ -7,11 +7,11 @@
|
|
|
|
|
module GitlabHelper
|
|
|
|
|
|
|
|
|
|
# gitlab版本库数据本地保存的根目录
|
|
|
|
|
ROOT_PATH="/home/git/repositories/"
|
|
|
|
|
ROOT_PATH="/home/git/repositories"
|
|
|
|
|
PROJECT_PATH_CUT = 40
|
|
|
|
|
# gitlab版本库所在服务器
|
|
|
|
|
# 注意REPO_IP_ADDRESS必须以http://开头,暂时只支持HTTP协议,未支持SSH
|
|
|
|
|
#REPO_IP_ADDRESS = "http://" + Setting.repository_domain
|
|
|
|
|
#REPO_IP_ADDRESS = "http://" + Setting.gitlab_server
|
|
|
|
|
REPO_IP_ADDRESS = "http://192.168.137.100"
|
|
|
|
|
GITLAB_API = "/api/v3"
|
|
|
|
|
# gitlab的默认登录用户(需管理员)
|
|
|
|
@ -65,6 +65,41 @@ module GitlabHelper
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 登录并初始化gitlab用户
|
|
|
|
|
# 登录成功且本地未保存数据时保存
|
|
|
|
|
# email:登录gitlab用户邮件,loginname:登录gitlab用户账号, password :登录gitlab用户密码
|
|
|
|
|
# user_id:用户在trustie中的编号
|
|
|
|
|
# add by nwb
|
|
|
|
|
def login_init_gitlab(email,password,loginname,user_id)
|
|
|
|
|
url = REPO_IP_ADDRESS + GITLAB_API + "/session"
|
|
|
|
|
uri = URI.parse(url)
|
|
|
|
|
data = {email:email, password:password}
|
|
|
|
|
begin
|
|
|
|
|
res = Net::HTTP.post_form(uri, data)
|
|
|
|
|
# 判断返回数据
|
|
|
|
|
if res.code == '201'
|
|
|
|
|
temp = ActiveSupport::JSON.decode(res.body)
|
|
|
|
|
if temp['username'] == loginname
|
|
|
|
|
# 保存数据
|
|
|
|
|
gituser = GitlabUser.new
|
|
|
|
|
gituser.user_id = user_id
|
|
|
|
|
gituser.gitlab_user_id = temp['id']
|
|
|
|
|
gituser.email = email
|
|
|
|
|
gituser.password = password
|
|
|
|
|
gituser.login =loginname
|
|
|
|
|
gituser.save
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
rescue =>err
|
|
|
|
|
logger.error "gitlab: error: #{err.message}"
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 创建项目
|
|
|
|
|
# add by nwb
|
|
|
|
|
def create_project(project_name,project_id)
|
|
|
|
@ -77,14 +112,14 @@ module GitlabHelper
|
|
|
|
|
if res.code == '201'
|
|
|
|
|
temp = ActiveSupport::JSON.decode(res.body)
|
|
|
|
|
#新创建项目的版本库地址
|
|
|
|
|
repository_url = temp['http_url_to_repo']
|
|
|
|
|
repository_url = String.new(temp['http_url_to_repo'])
|
|
|
|
|
repository_url['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
# 新创建项目的web地址
|
|
|
|
|
web_url = temp['web_url']
|
|
|
|
|
web_url = String.new(temp['web_url'])
|
|
|
|
|
web_url['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
# 新创建项目的本地文件路径
|
|
|
|
|
localfile = temp['web_url']
|
|
|
|
|
localfile['http://localhost'] = ROOT_PATH
|
|
|
|
|
localfile = String.new(temp['web_url'])
|
|
|
|
|
localfile[REPO_IP_ADDRESS] = ROOT_PATH
|
|
|
|
|
|
|
|
|
|
# 保存数据
|
|
|
|
|
gitproject =GitlabProject.new
|
|
|
|
@ -119,13 +154,13 @@ module GitlabHelper
|
|
|
|
|
if res.code == '201'
|
|
|
|
|
temp = ActiveSupport::JSON.decode(res.body)
|
|
|
|
|
#新创建项目的版本库地址
|
|
|
|
|
repository_url = temp['http_url_to_repo']
|
|
|
|
|
repository_url = String.new(temp['http_url_to_repo'])
|
|
|
|
|
repository_url['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
# 新创建项目的web地址
|
|
|
|
|
web_url = temp['web_url']
|
|
|
|
|
web_url = String.new(temp['web_url'])
|
|
|
|
|
web_url['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
# 新创建项目的本地文件路径
|
|
|
|
|
localfile = temp['web_url']
|
|
|
|
|
localfile = String.new(temp['web_url'])
|
|
|
|
|
localfile['http://localhost'] = ROOT_PATH
|
|
|
|
|
|
|
|
|
|
# 保存数据
|
|
|
|
|