From ebdfbbf4201a9e742a310f5755cb566c1b22acb5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 13 Jan 2024 14:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E7=A6=85=E9=81=93=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 lib/tasks/import_issues_from_chandao.rake diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake new file mode 100644 index 000000000..1923f977a --- /dev/null +++ b/lib/tasks/import_issues_from_chandao.rake @@ -0,0 +1,29 @@ + +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]" + task :bugs, [: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['Bug标题'] + issue.description = randd_field_hash['重现步骤'] + issue.created_on = randd_field_hash['创建日期'].to_time + issue.due_date = randd_field_hash['截止日期'] + issue.project_id = 0 + issue.pm_project_id = args.pm_project_id + issue.pm_issue_type = 3 + issue.save! + end + end +end \ No newline at end of file