gitlab一些非法历史数据处理

This commit is contained in:
huang 2018-06-14 11:32:44 +08:00
parent 76ac760114
commit 817211051f
1 changed files with 19 additions and 0 deletions

View File

@ -26,6 +26,7 @@ namespace :gitlab do
end
end
# 检查一个gitlab用户对应多个trustie用户的问题
task :useless_user => :environment do
# projects = Project.where(:id => [6286, 6292, 6293, 6294])
ids = User.find_by_sql("select gid from users where gid is not null group by gid having count(gid) > 1").map(&:gid)
@ -41,6 +42,24 @@ namespace :gitlab do
end
end
# 需要查出这样的用户并且删除Gitlab中这样的用户
task :sigle_useless_user => :environment do
users = User.where("gid is not null")
g = Gitlab.client
# users = User.where(:gid => 8823)
users.each do |user|
puts "start"+ "#{user.id}"
# 没有创建或者加入过项目
if Member.where("project_id >0 and user_id =?", user.id).blank? && g.user(user.gid).try(:username) != user.login
puts user.id
user.update_column(:gid, nil)
g.delete_user(user.gid)
end
end
end
# 检查gitlab中username和trustie不一致的问题
# 不一致的问题有一些是特殊符号导致的,比如:@、.等
task :username => :environment do
# projects = Project.where(:id => [6286, 6292, 6293, 6294])
users = User.where("gid is not null")