Gitlab数据清理及迁移,主要是历史数据

dev_shcool
huang 9 years ago
parent 1935176500
commit f979e80f24

@ -57,9 +57,7 @@ class Changeset < ActiveRecord::Base
validates :committed_on, presence: true
validates :commit_date, presence: true
validates :scmid, uniqueness: {scope: :repository_id, allow_nil: true}
attr_accessible :product, :project_id, :repository_id, :revision, :committer, :comments, :committed_on
attr_accessible :type
attr_accessible :type, :project_id, :repository_id, :revision, :committer, :comments, :committed_on
scope :visible, lambda {|*args|
includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args))
}

@ -1,11 +1,11 @@
namespace :gitlab do
desc "sync gitlab's commit acts to trustie"
task :forge_acts => :environment do
begin
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 != 2")
projects = Project.find_by_sql("select * from projects where gpid is not null and id > 265")
projects.each do |project|
begin
g_project = g.project(project.gpid)
# 获取默认分支
g_default_branch = g_project.default_branch.nil? ? "master" : g_project.default_branch
@ -13,15 +13,16 @@ namespace :gitlab do
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}"
(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)
end
end
end
rescue Exception => e
puts e
end
end
end
end

@ -0,0 +1,11 @@
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)
Repository.where("project_id in (161,236,266)").destroy_all
rescue Exception => e
puts e
end
end
end
Loading…
Cancel
Save