socialforge/lib/tasks/gitlab_sync.rake

51 lines
1.8 KiB
Ruby

# namespace :gitlab do
# desc "make sure trustie'data consistent with gitlab's data"
# task :sync_data => :environment do
# s = Trustie::Gitlab::Sync.new
# g = Gitlab.client
# projects = Project.where("gpid is not null and status=?", 1)
# projects.each do |project|
# # sync members and roles
# begin
# if project.members.count != g.team_members(project.gpid).count
# project.members.each do |m|
# begin
# gid = m.user.gid
# if gid.nil?
# gid = s.sync_user(m.user).id
# end
# access_level = m.roles[0].position == 3 ? 40 : (m.roles[0].position == 4 ? 30 : 20)
# # sync project's members
# g.add_team_member(project.gpid, gid, access_level)
# # sync members' roles
# g.edit_team_member(project.gpid, gid, access_level)
# rescue Exception => e
# DataException.create(:message => e.message, :container_id => project.id, :container_type => "Project")
# puts e
# end
# end
# end
# rescue Exception => e
# puts e
# end
# end
#
# users = User.where("gid is not null and status =?", 1)
# users.each do |user|
# begin
# # sync username
# g.edit_user(user.gid, :username => user.login) if user.login != g.user(user.gid).try(:username)
#
# # sync email
# g.edit_user(user.gid, :email => user.mail) if user.mail != g.user(user.gid).try(:email)
#
# # sync password
# options = {:encrypted_password=> user.hashed_password, :password_salt=> user.salt}
# g.put("/users/ext/#{user.gid}", :body => options)
# rescue Exception => e
# puts e
# end
# end
# end
# end