版本库历史数据处理

This commit is contained in:
huang 2016-07-21 16:08:13 +08:00
parent d58167f4bc
commit 3fb5322b03
2 changed files with 16 additions and 4 deletions

View File

@ -2,8 +2,7 @@ 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")
projects = Project.find_by_sql("select * from projects where gpid is not null and id > 265")
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)
@ -14,13 +13,19 @@ namespace :gitlab do
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|
Changeset.create(:project_id => project.id, :repository_id => project.gpid, :revision => commit.id, :committer => commit.author_email, :comments => Redmine::CodesetUtil.to_utf8(commit.title, 'UTF-8'), :committed_on => commit.created_at, :type => true)
result = 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)
puts "result is #{result}"
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

View File

@ -3,7 +3,14 @@ namespace :gitlab do
task :unused => :environment do
begin
Project.where("id in (161,236,266)").update_all(:gpid => nil)
Repository.where("project_id in (161,236,266)").destroy_all
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