From 817211051f240be5601c5a939b56ae045e60bd0f Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 14 Jun 2018 11:32:44 +0800 Subject: [PATCH] =?UTF-8?q?gitlab=E4=B8=80=E4=BA=9B=E9=9D=9E=E6=B3=95?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/gitlab.rake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/tasks/gitlab.rake b/lib/tasks/gitlab.rake index d6e01ab6a..fe2cc4dce 100644 --- a/lib/tasks/gitlab.rake +++ b/lib/tasks/gitlab.rake @@ -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")