Merge branch 'gitlab_guange' of http://repository.trustie.net/xianbo/trustie2 into gitlab_guange
commit
64fa435a3a
@ -0,0 +1,4 @@
|
||||
<%= form_for(@repository, url: to_gitlab_project_repository_path(@project, @repository)) do |f| %>
|
||||
<input type="text" name="repo_name"/>
|
||||
<button type="submit">转换到新版本</button>
|
||||
<% end %>
|
@ -0,0 +1,86 @@
|
||||
module Trustie
|
||||
module Gitlab
|
||||
module UserLevel
|
||||
GUEST = 10
|
||||
REPORTER = 20
|
||||
DEVELOPER = 30
|
||||
MASTER = 40
|
||||
OWNER = 50
|
||||
end
|
||||
|
||||
class Sync
|
||||
attr :g
|
||||
|
||||
def initialize
|
||||
@g = ::Gitlab.client
|
||||
end
|
||||
|
||||
def change_password(uid, en_pwd, salt)
|
||||
options = {:encrypted_password=>en_pwd, :password_salt=>salt}
|
||||
self.g.put("/users/ext/#{uid}", :body => options)
|
||||
# g.edit_user(uid, :encrypted_password=>en_pwd, :password_salt=>salt)
|
||||
end
|
||||
|
||||
def sync_user(user)
|
||||
begin
|
||||
u = self.g.get("/users?search=#{user.mail}").first
|
||||
unless u
|
||||
u = self.g.create_user(user.mail, user.hashed_password, name: user.show_name, username: user.login, confirm: "true")
|
||||
user.gid = u.id
|
||||
user.save!
|
||||
puts "create user #{user.login}"
|
||||
end
|
||||
change_password(u.id, user.hashed_password, user.salt)
|
||||
rescue => e
|
||||
puts e
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def sync_project(project, opt={})
|
||||
gid = project.owner.gid
|
||||
raise "unknow gid" unless gid
|
||||
path = opt[:path]
|
||||
raise "unknow path" unless path
|
||||
import_url = opt[:import_url]
|
||||
raise "unknow import_url" unless import_url
|
||||
|
||||
if opt[:password]
|
||||
import_url.sub('@', ":#{opt[:password]}@")
|
||||
end
|
||||
|
||||
|
||||
# import url http://xianbo_trustie2:1234@repository.trustie.net/xianbo/trustie2.git
|
||||
# can use password
|
||||
gproject = self.g.create_project(path,
|
||||
path: path,
|
||||
description: project.description,
|
||||
wiki_enabled: false,
|
||||
wall_enabled: false,
|
||||
issues_enabled: false,
|
||||
snippets_enabled: false,
|
||||
public: false,
|
||||
user_id: gid,
|
||||
import_url: import_url
|
||||
)
|
||||
project.gpid = gproject.id
|
||||
project.save!
|
||||
puts "Successfully created #{project.name}"
|
||||
# add team members
|
||||
#
|
||||
|
||||
project.members.each do |m|
|
||||
begin
|
||||
self.g.add_team_member(gproject.id, m.user.gid, UserLevel::DEVELOPER)
|
||||
rescue => e
|
||||
puts e
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def remove_project
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue