1.创建gitlab项目、用户model

2.gitlab接口更新
GitlabVersion
nwb 11 years ago
parent 0a06e2033f
commit 48ded776de

@ -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

@ -0,0 +1,3 @@
class GitlabProject < ActiveRecord::Base
attr_accessible :project_id
end

@ -0,0 +1,3 @@
class GitlabUser < ActiveRecord::Base
attr_accessible :user_id
end

@ -0,0 +1,14 @@
class CreateGitlabProjects < ActiveRecord::Migration
def change
create_table :gitlab_projects do |t|
t.integer :gitlab_project_id
t.integer :project_id
#版本库地址
t.string :repository_url
#版本库web地址
t.string :web_url
t.timestamps
end
end
end

@ -0,0 +1,16 @@
class CreateGitlabUsers < ActiveRecord::Migration
def change
create_table :gitlab_users do |t|
# 用户在gitlab中的编号
t.integer :gitlab_user_id
# 用户在trustie中的编号
t.integer :user_id
# 登录gitlab所用的邮箱
t.string :email
# 登录gitlab所用的密码
t.string :password
t.timestamps
end
end
end

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140722024513) do
ActiveRecord::Schema.define(:version => 20140723012553) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -429,6 +429,24 @@ ActiveRecord::Schema.define(:version => 20140722024513) do
t.datetime "updated_at", :null => false
end
create_table "gitlab_projects", :force => true do |t|
t.integer "gitlab_project_id"
t.integer "project_id"
t.string "repository_url"
t.string "web_url"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "gitlab_users", :force => true do |t|
t.integer "gitlab_user_id"
t.integer "user_id"
t.string "email"
t.string "password"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "groups_users", :id => false, :force => true do |t|
t.integer "group_id", :null => false
t.integer "user_id", :null => false
@ -844,19 +862,6 @@ ActiveRecord::Schema.define(:version => 20140722024513) do
add_index "repositories", ["project_id"], :name => "index_repositories_on_project_id"
create_table "rich_rich_files", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "rich_file_file_name"
t.string "rich_file_content_type"
t.integer "rich_file_file_size"
t.datetime "rich_file_updated_at"
t.string "owner_type"
t.integer "owner_id"
t.text "uri_cache"
t.string "simplified_type", :default => "file"
end
create_table "roles", :force => true do |t|
t.string "name", :limit => 30, :default => "", :null => false
t.integer "position", :default => 1

@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
project_id:
two:
project_id:

@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
user_id:
two:
user_id:

@ -0,0 +1,7 @@
require 'test_helper'
class GitlabProjectTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

@ -0,0 +1,7 @@
require 'test_helper'
class GitlabUserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Loading…
Cancel
Save