rake导入项目

This commit is contained in:
xiaoxiaoqiong 2022-05-27 14:19:57 +08:00
parent 2a387ad997
commit 48cf92a2cf
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
namespace :create_mulan_repository do
desc "sync outer repository to gitlink"
task sync_from_gitee: :environment do
file = ENV['file'] || "rcore-os_repo.xlsx"
user_type = ENV['type'] || "User"
doc = SimpleXlsxReader.open("#{Rails.root}/public/#{file}")
data = doc.sheets.first.rows
data.each_with_index do |row, index|
next if index == 0
begin
user = (user_type == "User" ? User.find_by(login: row[1]) : Owner.find_by(login: row[1]))
project = user.projects.find_by(identifier: row[4])
unless project.present?
p_category = ProjectCategory.find_or_create_by(name: row[6])
p_language = ProjectLanguage.find_or_create_by(name: row[7].split("/")[0])
p_license = License.find_by(name: row[8])
mirror_params = {
user_id: user.id,
name: row[5],
description: row[9],
repository_name: row[4],
project_category_id: p_category.id,
project_language_id: p_language.id,
clone_addr: row[10]
}
Projects::MigrateService.call(user, mirror_params)
end
puts "sync outer repository to gitlink Success repo: #{row[5]} username: #{row[0]}"
rescue Exception => e
puts "sync outer repository to gitlink Error repo: #{row[5]} username: #{row[0]}"
end
end
end
end

BIN
public/rcore-os_repo.xlsx Normal file

Binary file not shown.