mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-03 03:40:49 +08:00
新增:固定数据清洗及获取
This commit is contained in:
54
lib/tasks/sync_mindspore_contributors.rake
Normal file
54
lib/tasks/sync_mindspore_contributors.rake
Normal file
@@ -0,0 +1,54 @@
|
||||
desc "mindspore项目贡献者数据"
|
||||
|
||||
# 同步mindspre贡献者数据至用户表
|
||||
|
||||
namespace :sync_mindspore do
|
||||
desc "同步用户信息"
|
||||
task contributor_to_user: :environment do
|
||||
i = 1
|
||||
fail_users = []
|
||||
file = File.open('public/mindspore_authors', 'r')
|
||||
file.each_line do |l|
|
||||
itemArray = l.gsub("\r\n", "").split("|:|")
|
||||
email = itemArray[0]
|
||||
username = itemArray[1]
|
||||
password = '12345678'
|
||||
puts "=======Generate:[#{i}] Username: #{username}, Password: #{password}, Email: #{email}======="
|
||||
puts "=======Create User Begin====== "
|
||||
|
||||
user = User.new(admin: false, login: username, mail: email, type: "User", is_test: 1)
|
||||
user.password = password
|
||||
user.platform = 'forge'
|
||||
user.activate
|
||||
|
||||
unless user.valid?
|
||||
puts "=======Create User Fail!====== "
|
||||
fail_users << [username, email]
|
||||
next
|
||||
end
|
||||
|
||||
interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password})
|
||||
if interactor.success?
|
||||
gitea_user = interactor.result
|
||||
result = Gitea::User::GenerateTokenService.call(username, password)
|
||||
user.gitea_token = result['sha1']
|
||||
user.gitea_uid = gitea_user[:body]['id']
|
||||
if user.save!
|
||||
UserExtension.create!(user_id: user.id)
|
||||
end
|
||||
end
|
||||
|
||||
i += 1
|
||||
puts "=======Create User End====== "
|
||||
end
|
||||
|
||||
puts "=======Fail Users:#{fail_users}====== "
|
||||
|
||||
file.close
|
||||
end
|
||||
|
||||
desc "初始化区块链项目"
|
||||
task init_project_blockchain: :environment do
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user