新增:导入禅道需求数据脚本

This commit is contained in:
yystopf 2024-01-15 14:53:29 +08:00
parent d55ff07296
commit ccdacb641f
1 changed files with 27 additions and 2 deletions

View File

@ -2,8 +2,8 @@
desc "导入禅道数据"
namespace :import_from_chandao do
desc "bug数据"
# 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统-yystopf.csv, 1]"
# RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统-yystopf.csv, 1]"
# 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]"
# RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]"
task :bugs, [:name, :pm_project_id] => :environment do |t, args|
name = args.name
CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row |
@ -26,4 +26,29 @@ namespace :import_from_chandao do
issue.save!
end
end
# 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]"
# RAILS_ENV=production bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]"
task :requirements, [:name, :pm_project_id] => :environment do |t, args|
name = args.name
CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row |
randd_field_hash = row.to_hash
issue = Issue.new
author = User.like(randd_field_hash['由谁创建']).take
issue.author_id = author&.id
assigner = User.like(randd_field_hash['指派给']).take
issue.assigners << assigner
issue.status_id = IssueStatus.first.id
issue.tracker_id = Tracker.first.id
issue.priority_id = randd_field_hash['优先级'].to_i
issue.subject = randd_field_hash['需求名称']
issue.description = randd_field_hash['需求描述']
issue.created_on = randd_field_hash['创建日期'].to_time
issue.time_scale = randd_field_hash['预计工时'].to_i
issue.project_id = 0
issue.pm_project_id = args.pm_project_id
issue.pm_issue_type = 1
issue.save!
end
end
end