添加gitlab创建项目(版本库)接口
This commit is contained in:
parent
36ab954cf9
commit
6dcc50e60b
|
@ -365,6 +365,8 @@ class UsersController < ApplicationController
|
|||
def show
|
||||
# 测试代码
|
||||
#login_gitlab("admin@local.host","19840410")
|
||||
#create_project("testproject1")
|
||||
#create_project_for_user("testproject1","2")
|
||||
# 测试结束
|
||||
|
||||
pre_count = 10 #limit
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# Gitlab5.3 API操作接口
|
||||
# Add by nwb
|
||||
# 暂时没支持SSH
|
||||
|
||||
module GitlabHelper
|
||||
|
||||
|
@ -7,7 +8,7 @@ module GitlabHelper
|
|||
ROOT_PATH="/home/git/repositories/"
|
||||
PROJECT_PATH_CUT = 40
|
||||
# gitlab版本库所在服务器
|
||||
#REPO_IP_ADDRESS = Setting.repository_domain
|
||||
#REPO_IP_ADDRESS = "http://" + Setting.repository_domain
|
||||
REPO_IP_ADDRESS = "http://192.168.137.100"
|
||||
GITLAB_API = "/api/v3"
|
||||
|
||||
|
@ -31,7 +32,7 @@ module GitlabHelper
|
|||
res = Net::HTTP.post_form(uri, data)
|
||||
if res.code == '201'
|
||||
temp = ActiveSupport::JSON.decode(res.body)
|
||||
gitlab_token= temp['private_token']
|
||||
GitlabHelper.gitlab_token= temp['private_token']
|
||||
return true
|
||||
else
|
||||
return false
|
||||
|
@ -43,14 +44,53 @@ module GitlabHelper
|
|||
|
||||
# 创建项目
|
||||
# add by nwb
|
||||
def create_project(name)
|
||||
|
||||
def create_project(project_name)
|
||||
url = REPO_IP_ADDRESS + GITLAB_API + "/projects"
|
||||
uri = URI.parse(url)
|
||||
data = {name:project_name, private_token:GitlabHelper.gitlab_token}
|
||||
begin
|
||||
res = Net::HTTP.post_form(uri, data)
|
||||
if res.code == '201'
|
||||
temp = ActiveSupport::JSON.decode(res.body)
|
||||
#新创建项目的版本库地址
|
||||
respo = temp['http_url_to_repo']
|
||||
respo['http://localhost'] = REPO_IP_ADDRESS
|
||||
# 新创建项目的web地址
|
||||
webaddress = temp['web_url']
|
||||
webaddress['http://localhost'] = REPO_IP_ADDRESS
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
rescue =>err
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# 为指定用户创建版本库
|
||||
# name:版本库名称 user:版本库创建后所属的用户
|
||||
def create_project_for_user(name,user)
|
||||
|
||||
# project_name:版本库名称 user_id:Gitlab版本库中的用户编号
|
||||
# add by nwb
|
||||
def create_project_for_user(project_name,user_id)
|
||||
url = REPO_IP_ADDRESS + GITLAB_API + "/projects/user/" + user_id
|
||||
uri = URI.parse(url)
|
||||
data = {user_id:user_id, name:project_name,private_token:GitlabHelper.gitlab_token}
|
||||
begin
|
||||
res = Net::HTTP.post_form(uri, data)
|
||||
if res.code == '201'
|
||||
temp = ActiveSupport::JSON.decode(res.body)
|
||||
#新创建项目的版本库地址
|
||||
respo = temp['http_url_to_repo']
|
||||
respo['http://localhost'] = REPO_IP_ADDRESS
|
||||
# 新创建项目的web地址
|
||||
webaddress = temp['web_url']
|
||||
webaddress['http://localhost'] = REPO_IP_ADDRESS
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
rescue =>err
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
# 创建用户
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20140715015540) do
|
||||
ActiveRecord::Schema.define(:version => 20140716021558) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -415,6 +415,7 @@ ActiveRecord::Schema.define(:version => 20140715015540) do
|
|||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "page_type"
|
||||
t.integer "sort_type"
|
||||
end
|
||||
|
||||
create_table "forums", :force => true do |t|
|
||||
|
|
Loading…
Reference in New Issue