Browse Source

更改: 导入项目数据脚本

pull/347/head
yystopf 1 year ago
parent
commit
f5f73bfa68
1 changed files with 31 additions and 23 deletions
  1. +31
    -23
      lib/tasks/import_issues_from_another_forge.rake

+ 31
- 23
lib/tasks/import_issues_from_another_forge.rake View File

@@ -1,6 +1,28 @@

desc "导入导出issue、version、journal数据"
namespace :import_from_another_forge do

def find_or_create_by(login)
return nil unless login.present?
user = User.find_by(login: login)
return user if user.present?

user = User.new(admin: false, login: login, mail: "#{login}@forge.com", nickname: login, platform: 'forge' , type: "User")
user.password = "12345678"
user.activate
interactor = Gitea::RegisterInteractor.call({username: login, email: "#{login}@forge.com", password: "12345678"})
gitea_user = interactor.result
result = Gitea::User::GenerateTokenService.call(login, "12345678")
user.gitea_token = result['sha1']
user.gitea_uid = gitea_user[:body]['id']
user.save!
UserExtension.create!(user_id: user.id)

return user
rescue
return nil
end

desc "导出数据"
# 执行示例 bundle exec rake "import_from_another_forge:export[110]"
# RAILS_ENV=production bundle exec rake "import_from_another_forge:export[110]"
@@ -31,25 +53,6 @@ namespace :import_from_another_forge do
end
end

def find_or_create_by(login)
return nil unless login.present?
user = User.find_by(login: login)
return user if user.present?

user = User.new(admin: false, login: login, mail: "#{login}@forge.com", nickname: login, platform: 'forge' , type: "User")
user.password = "12345678"
user.activate
interactor = Gitea::RegisterInteractor.call({username: login, email: "#{login}@forge.com", password: "12345678"})
gitea_user = interactor.result
result = Gitea::User::GenerateTokenService.call(username, password)
user.gitea_token = result['sha1']
user.gitea_uid = gitea_user[:body]['id']
UserExtension.create!(user_id: user.id) if user.save!

return user
rescue
return nil
end

# 执行示例 bundle exec rake "import_from_another_forge:import[filepath, 365, ceshi_org]"
# RAILS_ENV=production bundle exec rake "import_from_another_forge:import[public/version_issue_journal_data.xlsx, 110]"
@@ -114,25 +117,30 @@ namespace :import_from_another_forge do
end
end
end
issue.fixed_version_id = row[12]
issue.fixed_version_id = version_hash["#{row[12]}"]
issue.save!
issue_hash["#{row[0]}"] = issue.id
end
when 'journal'
sheet.rows.each.with_index do |row, index|
next if index == 0
next if row[6].present? || row[8].present?
journal = Journal.new
journal.journalized_type = row[1]
journal.journalized_id = row[2]
journal.journalized_id = issue_hash["#{row[2]}"]
journal.user = find_or_create_by(row[3])
journal.notes = row[4]
journal.created_on = row[5]
journal.updated_on = row[9]
journal.parent_id = journal_hash["#{row[6]}"]
journal.reply_id = journal_hash["#{row[8]}"]
journal.save!
journal_hash["#{row[0]}"] = journal.id
end
end
end
end
end

end
end

Loading…
Cancel
Save