diff --git a/lib/tasks/gitlab_act_project.rake b/lib/tasks/gitlab_act_project.rake index 142d5bf89..7ef336689 100644 --- a/lib/tasks/gitlab_act_project.rake +++ b/lib/tasks/gitlab_act_project.rake @@ -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 diff --git a/lib/tasks/gitlab_unused.rake b/lib/tasks/gitlab_unused.rake index 0b90d9352..4b81acbff 100644 --- a/lib/tasks/gitlab_unused.rake +++ b/lib/tasks/gitlab_unused.rake @@ -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