git同名的一些处理
This commit is contained in:
parent
0f081eeb70
commit
91d7632ef1
|
@ -26,6 +26,19 @@ namespace :gitlab do
|
|||
end
|
||||
end
|
||||
|
||||
task :useless_user => :environment do
|
||||
# projects = Project.where(:id => [6286, 6292, 6293, 6294])
|
||||
users = User.where("SELECT * FROM `users` where gid is not null group by gid having count(*)=2")
|
||||
# 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?
|
||||
puts user.id
|
||||
user.update_column(:gid, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "update user password"
|
||||
task :password => :environment do
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
namespace :gitlab do
|
||||
desc "sync gitlab's commit acts to trustie"
|
||||
task :forge_acts => :environment do
|
||||
g = Gitlab.client
|
||||
projects = Project.find_by_sql("select * from projects where gpid is not null and id not in (2,847,931,942)")
|
||||
projects.each do |project|
|
||||
begin
|
||||
g_project = g.project(project.gpid)
|
||||
# 获取默认分支
|
||||
g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
|
||||
# 总的提交次数
|
||||
commit_count = g.user_static(project.gpid, :rev => g_default_branch).count
|
||||
pages = commit_count / 20 + 1
|
||||
puts "#{pages}"
|
||||
puts "project id is #{project.id}"
|
||||
# api获取每次只能获取20次提交,所以需要通过取得page值来获取每页的提交动态
|
||||
(0..pages).each do |page|
|
||||
commits = g.commits(project.gpid, :ref_name => g_default_branch, :page => page)
|
||||
commits.each do |commit|
|
||||
Commit.create(:project_id => project.id, :repository_id => project.gpid, :version => commit.id, :committer => commit.author_email, :comments => Redmine::CodesetUtil.to_utf8(commit.title, 'UTF-8'), :committed_on => commit.created_at)
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
# puts "Some wrong with project #{project.id}"
|
||||
# Project.where(:id => project.id).first.update_column(:gpid, nil)
|
||||
# Repository.where(:project_id => project.id).first.destroy
|
||||
# try
|
||||
puts e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# namespace :gitlab do
|
||||
# desc "sync gitlab's commit acts to trustie"
|
||||
# task :forge_acts => :environment do
|
||||
# g = Gitlab.client
|
||||
# projects = Project.find_by_sql("select * from projects where gpid is not null and id not in (2,847,931,942)")
|
||||
# projects.each do |project|
|
||||
# begin
|
||||
# g_project = g.project(project.gpid)
|
||||
# # 获取默认分支
|
||||
# g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
|
||||
# # 总的提交次数
|
||||
# commit_count = g.user_static(project.gpid, :rev => g_default_branch).count
|
||||
# pages = commit_count / 20 + 1
|
||||
# puts "#{pages}"
|
||||
# puts "project id is #{project.id}"
|
||||
# # api获取每次只能获取20次提交,所以需要通过取得page值来获取每页的提交动态
|
||||
# (0..pages).each do |page|
|
||||
# commits = g.commits(project.gpid, :ref_name => g_default_branch, :page => page)
|
||||
# commits.each do |commit|
|
||||
# Commit.create(:project_id => project.id, :repository_id => project.gpid, :version => commit.id, :committer => commit.author_email, :comments => Redmine::CodesetUtil.to_utf8(commit.title, 'UTF-8'), :committed_on => commit.created_at)
|
||||
# end
|
||||
# end
|
||||
# rescue Exception => e
|
||||
# # puts "Some wrong with project #{project.id}"
|
||||
# # Project.where(:id => project.id).first.update_column(:gpid, nil)
|
||||
# # Repository.where(:project_id => project.id).first.destroy
|
||||
# # try
|
||||
# puts e
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
namespace :gitlab do
|
||||
desc "sync gitlab's commit acts to trustie"
|
||||
task :forge_acts_update => :environment do
|
||||
g = Gitlab.client
|
||||
ids = [2,847,931,942]
|
||||
projects = Project.find(ids)
|
||||
projects.each do |project|
|
||||
# c = Commit.where(:project_id => project.id)
|
||||
# if c.blank?
|
||||
begin
|
||||
g_project = g.project(project.gpid)
|
||||
# 获取默认分支
|
||||
g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
|
||||
# 总的提交次数
|
||||
commit_count = g.user_static(project.gpid, :rev => g_default_branch).count
|
||||
pages = commit_count / 20 + 1
|
||||
puts "#{pages}"
|
||||
puts "project id is #{project.id}"
|
||||
# api获取每次只能获取20次提交,所以需要通过取得page值来获取每页的提交动态
|
||||
(0..pages).each do |page|
|
||||
commits = g.commits(project.gpid, :ref_name => g_default_branch, :page => page)
|
||||
commits.each do |commit|
|
||||
Commit.create(:project_id => project.id, :repository_id => project.gpid, :version => commit.id, :committer => commit.author_email, :comments => Redmine::CodesetUtil.to_utf8(commit.title, 'UTF-8'), :committed_on => commit.created_at)
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
puts e
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
# namespace :gitlab do
|
||||
# desc "sync gitlab's commit acts to trustie"
|
||||
# task :forge_acts_update => :environment do
|
||||
# g = Gitlab.client
|
||||
# ids = [2,847,931,942]
|
||||
# projects = Project.find(ids)
|
||||
# projects.each do |project|
|
||||
# # c = Commit.where(:project_id => project.id)
|
||||
# # if c.blank?
|
||||
# begin
|
||||
# g_project = g.project(project.gpid)
|
||||
# # 获取默认分支
|
||||
# g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
|
||||
# # 总的提交次数
|
||||
# commit_count = g.user_static(project.gpid, :rev => g_default_branch).count
|
||||
# pages = commit_count / 20 + 1
|
||||
# puts "#{pages}"
|
||||
# puts "project id is #{project.id}"
|
||||
# # api获取每次只能获取20次提交,所以需要通过取得page值来获取每页的提交动态
|
||||
# (0..pages).each do |page|
|
||||
# commits = g.commits(project.gpid, :ref_name => g_default_branch, :page => page)
|
||||
# commits.each do |commit|
|
||||
# Commit.create(:project_id => project.id, :repository_id => project.gpid, :version => commit.id, :committer => commit.author_email, :comments => Redmine::CodesetUtil.to_utf8(commit.title, 'UTF-8'), :committed_on => commit.created_at)
|
||||
# end
|
||||
# end
|
||||
# rescue Exception => e
|
||||
# puts e
|
||||
# end
|
||||
# # end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
|
|
@ -1,50 +1,50 @@
|
|||
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
|
||||
# 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
|
||||
|
|
|
@ -1,41 +1,41 @@
|
|||
namespace :gitlab do
|
||||
desc "sync gitlab's commit acts to trustie"
|
||||
task :acts_to_trustie => :environment do
|
||||
begin
|
||||
projects = Project.where(:status => 1)
|
||||
projects.each do |project|
|
||||
c = Commit.find_by_sql("SELECT * FROM `commits` where project_id = #{project.id} order by committed_on limit 1;")
|
||||
g_project = g.project(project.gpid)
|
||||
end
|
||||
rescue Exception => e
|
||||
puts e
|
||||
end
|
||||
g = Gitlab.client
|
||||
ids = [2,847,931,942]
|
||||
projects = Project.find(ids)
|
||||
projects.each do |project|
|
||||
c = Commit.where(:project_id => project.id)
|
||||
if c.blank?
|
||||
begin
|
||||
g_project = g.project(project.gpid)
|
||||
# 获取默认分支
|
||||
g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
|
||||
# 总的提交次数
|
||||
commit_count = g.user_static(project.gpid, :rev => g_default_branch).count
|
||||
pages = commit_count / 20 + 1
|
||||
puts "#{pages}"
|
||||
puts "project id is #{project.id}"
|
||||
# api获取每次只能获取20次提交,所以需要通过取得page值来获取每页的提交动态
|
||||
(0..pages).each do |page|
|
||||
commits = g.commits(project.gpid, :ref_name => g_default_branch, :page => page)
|
||||
commits.each do |commit|
|
||||
Commit.create(:project_id => project.id, :repository_id => project.gpid, :version => commit.id, :committer => commit.author_email, :comments => Redmine::CodesetUtil.to_utf8(commit.title, 'UTF-8'), :committed_on => commit.created_at)
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
puts e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# namespace :gitlab do
|
||||
# desc "sync gitlab's commit acts to trustie"
|
||||
# task :acts_to_trustie => :environment do
|
||||
# begin
|
||||
# projects = Project.where(:status => 1)
|
||||
# projects.each do |project|
|
||||
# c = Commit.find_by_sql("SELECT * FROM `commits` where project_id = #{project.id} order by committed_on limit 1;")
|
||||
# g_project = g.project(project.gpid)
|
||||
# end
|
||||
# rescue Exception => e
|
||||
# puts e
|
||||
# end
|
||||
# g = Gitlab.client
|
||||
# ids = [2,847,931,942]
|
||||
# projects = Project.find(ids)
|
||||
# projects.each do |project|
|
||||
# c = Commit.where(:project_id => project.id)
|
||||
# if c.blank?
|
||||
# begin
|
||||
# g_project = g.project(project.gpid)
|
||||
# # 获取默认分支
|
||||
# g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
|
||||
# # 总的提交次数
|
||||
# commit_count = g.user_static(project.gpid, :rev => g_default_branch).count
|
||||
# pages = commit_count / 20 + 1
|
||||
# puts "#{pages}"
|
||||
# puts "project id is #{project.id}"
|
||||
# # api获取每次只能获取20次提交,所以需要通过取得page值来获取每页的提交动态
|
||||
# (0..pages).each do |page|
|
||||
# commits = g.commits(project.gpid, :ref_name => g_default_branch, :page => page)
|
||||
# commits.each do |commit|
|
||||
# Commit.create(:project_id => project.id, :repository_id => project.gpid, :version => commit.id, :committer => commit.author_email, :comments => Redmine::CodesetUtil.to_utf8(commit.title, 'UTF-8'), :committed_on => commit.created_at)
|
||||
# end
|
||||
# end
|
||||
# rescue Exception => e
|
||||
# puts e
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
namespace :gitlab do
|
||||
desc "sync gitlab's commit acts to trustie"
|
||||
task :unused => :environment do
|
||||
begin
|
||||
Project.where("id in (161,236,266)").update_all(:gpid => nil)
|
||||
repositories = Repository.find_by_sql("select * from repositories where project_id in (select project_id from repositories group by project_id having count(project_id) > 1);")
|
||||
repositories.each do |rep|
|
||||
puts "#{rep.id}"
|
||||
if rep.type == "Repository::Git"
|
||||
rep.destroy
|
||||
end
|
||||
end
|
||||
# Repository.where("project_id in (161,236,266)").destroy_all
|
||||
rescue Exception => e
|
||||
puts e
|
||||
end
|
||||
end
|
||||
end
|
||||
# namespace :gitlab do
|
||||
# desc "sync gitlab's commit acts to trustie"
|
||||
# task :unused => :environment do
|
||||
# begin
|
||||
# Project.where("id in (161,236,266)").update_all(:gpid => nil)
|
||||
# repositories = Repository.find_by_sql("select * from repositories where project_id in (select project_id from repositories group by project_id having count(project_id) > 1);")
|
||||
# repositories.each do |rep|
|
||||
# puts "#{rep.id}"
|
||||
# if rep.type == "Repository::Git"
|
||||
# rep.destroy
|
||||
# end
|
||||
# end
|
||||
# # Repository.where("project_id in (161,236,266)").destroy_all
|
||||
# rescue Exception => e
|
||||
# puts e
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
|
Loading…
Reference in New Issue