|
|
|
@ -41,6 +41,7 @@ module GitlabHelper
|
|
|
|
|
data = {email:email, password:password}
|
|
|
|
|
begin
|
|
|
|
|
res = Net::HTTP.post_form(uri, data)
|
|
|
|
|
# 判断返回数据
|
|
|
|
|
if res.code == '201'
|
|
|
|
|
temp = ActiveSupport::JSON.decode(res.body)
|
|
|
|
|
GitlabHelper.gitlab_token= temp['private_token']
|
|
|
|
@ -55,7 +56,7 @@ module GitlabHelper
|
|
|
|
|
|
|
|
|
|
# 创建项目
|
|
|
|
|
# add by nwb
|
|
|
|
|
def create_project(project_name)
|
|
|
|
|
def create_project(project_name,project_id)
|
|
|
|
|
url = REPO_IP_ADDRESS + GITLAB_API + "/projects"
|
|
|
|
|
uri = URI.parse(url)
|
|
|
|
|
data = {name:project_name, private_token:GitlabHelper.gitlab_token}
|
|
|
|
@ -64,11 +65,19 @@ module GitlabHelper
|
|
|
|
|
if res.code == '201'
|
|
|
|
|
temp = ActiveSupport::JSON.decode(res.body)
|
|
|
|
|
#新创建项目的版本库地址
|
|
|
|
|
respo = temp['http_url_to_repo']
|
|
|
|
|
respo['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
repository_url = temp['http_url_to_repo']
|
|
|
|
|
repository_url['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
# 新创建项目的web地址
|
|
|
|
|
webaddress = temp['web_url']
|
|
|
|
|
webaddress['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
web_url = temp['web_url']
|
|
|
|
|
web_url['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
|
|
|
|
|
# 保存数据
|
|
|
|
|
gitproject =GitlabProject.new
|
|
|
|
|
gitproject.project_id = project_id
|
|
|
|
|
gitproject.gitlab_project_id = temp['id']
|
|
|
|
|
gitproject.repository_url = repository_url
|
|
|
|
|
gitproject.web_url = web_url
|
|
|
|
|
gitproject.save
|
|
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
@ -90,11 +99,19 @@ module GitlabHelper
|
|
|
|
|
if res.code == '201'
|
|
|
|
|
temp = ActiveSupport::JSON.decode(res.body)
|
|
|
|
|
#新创建项目的版本库地址
|
|
|
|
|
respo = temp['http_url_to_repo']
|
|
|
|
|
respo['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
repository_url = temp['http_url_to_repo']
|
|
|
|
|
repository_url['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
# 新创建项目的web地址
|
|
|
|
|
webaddress = temp['web_url']
|
|
|
|
|
webaddress['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
web_url = temp['web_url']
|
|
|
|
|
web_url['http://localhost'] = REPO_IP_ADDRESS
|
|
|
|
|
|
|
|
|
|
# 保存数据
|
|
|
|
|
gitproject =GitlabProject.new
|
|
|
|
|
gitproject.project_id = project_id
|
|
|
|
|
gitproject.gitlab_project_id = temp['id']
|
|
|
|
|
gitproject.repository_url = repository_url
|
|
|
|
|
gitproject.web_url = web_url
|
|
|
|
|
gitproject.save
|
|
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
@ -107,7 +124,7 @@ module GitlabHelper
|
|
|
|
|
# 创建用户
|
|
|
|
|
# loginname:登录名称(版本库路径包含) name:用户姓名
|
|
|
|
|
# add by nwb
|
|
|
|
|
def create_user (loginname,name,password,email)
|
|
|
|
|
def create_user (loginname,name,password,email,userid)
|
|
|
|
|
url = REPO_IP_ADDRESS + GITLAB_API + "/users"
|
|
|
|
|
uri = URI.parse(url)
|
|
|
|
|
data = {email:email,password:password,username:loginname, name:name, private_token:GitlabHelper.gitlab_token}
|
|
|
|
@ -116,7 +133,15 @@ module GitlabHelper
|
|
|
|
|
if res.code == '201'
|
|
|
|
|
temp = ActiveSupport::JSON.decode(res.body)
|
|
|
|
|
#新创建的gitlab用户编号(需保存)
|
|
|
|
|
user_id = temp['id']
|
|
|
|
|
git_user_id = temp['id']
|
|
|
|
|
|
|
|
|
|
# 保存数据
|
|
|
|
|
gituser = GitlabUser.new
|
|
|
|
|
gituser.user_id = userid
|
|
|
|
|
gituser.gitlab_user_id = git_user_id
|
|
|
|
|
gituser.email = email
|
|
|
|
|
gituser.password = password
|
|
|
|
|
gituser.save
|
|
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
@ -140,7 +165,9 @@ module GitlabHelper
|
|
|
|
|
res= http.start { |http| http.request req }
|
|
|
|
|
if res.code == '200'
|
|
|
|
|
temp = ActiveSupport::JSON.decode(res.body)
|
|
|
|
|
# 删除成功,对应更新trustie用户的gitlab用户编号
|
|
|
|
|
# 删除成功,更新数据
|
|
|
|
|
gituser = GitlabUser.find_by_gitlab_user_id(user_id_)
|
|
|
|
|
gituser.destroy
|
|
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
@ -228,6 +255,7 @@ module GitlabHelper
|
|
|
|
|
uri = URI.parse(url)
|
|
|
|
|
uri.query = URI.encode_www_form(params)
|
|
|
|
|
http = Net::HTTP.new uri.host, uri.port
|
|
|
|
|
#https协议额外解析
|
|
|
|
|
if uri.scheme == 'https'
|
|
|
|
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
|
|
|
http.use_ssl = true
|
|
|
|
|