版本库数据同步任务

This commit is contained in:
siteen 2016-12-14 10:08:41 +08:00
parent 413efa8d02
commit f82ea16102
1 changed files with 18 additions and 6 deletions

View File

@ -1,20 +1,32 @@
namespace :gitlab do
desc "make sure trustie'data consistent with gitlab's data"
task :sync_date => :environment do
projects = Project.where("gpid is not null")
task :sync_data => :environment do
s = Trustie::Gitlab::Sync.new
g = Gitlab.client
begin
projects = Project.where(:status => 1)
projects = Project.where("gpid is not null and status=?", 1)
projects.each do |project|
# sync members and roles
if project.members.count != g.team_members(project.gpid).count
DataException.create(:message => "project's members is not true", :container_id => project.id, :container_type => "Project")
s.only_members(project)
project.members.each do |m|
begin
gid = m.user.gid
if gid.nil?
gid = sync_user(m.user).id
end
# sync project's members
g.add_team_member(project.gpid, gid, get_gitlab_role(m))
# sync members' roles
g.edit_team_member(project.gpid, gid, get_gitlab_role(m))
rescue => e
puts e
end
end
end
end
users = User.where("gpid is not null and status =?", 1)
users = User.where("gid is not null and status =?", 1)
users.each do |user|
# sync username
g.edit_user(user.gid, :username => user.login) if user.login != g.user(user.gid).try(:username)
@ -24,7 +36,7 @@ namespace :gitlab do
# sync password
options = {:encrypted_password=> user.hashed_password, :password_salt=> user.salt}
g.put("/users/ext/#{uid}", :body => options)
g.put("/users/ext/#{user.gid}", :body => options)
end
rescue Exception => e
DataException.create(:message => e.message)