修复:导入禅道脚本无法导入迭代数据

This commit is contained in:
yystopf 2024-09-03 10:13:38 +08:00
parent 12ae3b94d9
commit cd71532dd7
1 changed files with 154 additions and 111 deletions

View File

@ -1,10 +1,34 @@
desc "导入禅道数据" desc "导入禅道数据"
namespace :import_from_chandao do namespace :import_from_chandao do
def get_sprint_data(name, pm_project_id, org)
assigner = org.team_users.joins(:team).where(teams: {authorize: "owner"}).take&.user
url = URI("#{EduSetting.get("pms_server_url")}/api/pms/#{org.login}/pmsProjectSprint/findOrCreate")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Cookie"] = "autologin_trustie=#{Token.get_or_create_permanent_login_token(assigner, 'autologin')}"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"pmsProjectId": pm_project_id,
"sprintAssigneeId": assigner.id,
"sprintName": name
})
response = http.request(request)
puts response.read_body
return JSON.parse(response.read_body)['data']
rescue
return nil
end
desc "bug数据" desc "bug数据"
# 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" # 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]"
# RAILS_ENV=production 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| task :bugs, [:name, :pm_project_id, :org_login] => :environment do |t, args|
org = Organization.find_by(login: args.org_login)
if org.present?
def trans_status(str) def trans_status(str)
h={ h={
"激活" => 1, "激活" => 1,
@ -35,6 +59,9 @@ namespace :import_from_chandao do
issue.project_id = 0 issue.project_id = 0
issue.pm_project_id = args.pm_project_id issue.pm_project_id = args.pm_project_id
issue.pm_issue_type = 3 issue.pm_issue_type = 3
sprint_name = randd_field_hash['所属迭代'].split('(#')[0]
sprint = get_sprint_data(sprint_name, args.pm_project_id, org)
issue.pm_sprint_id = sprint['id'] if sprint.present?
issue.save! issue.save!
requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: args.pm_project_id, pm_issue_type: 1) rescue nil requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: args.pm_project_id, pm_issue_type: 1) rescue nil
if requirement_issue.present? if requirement_issue.present?
@ -45,11 +72,16 @@ namespace :import_from_chandao do
task_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) task_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id)
end end
end end
else
puts "组织不存在"
end
end end
# 执行示例 bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365]" # 执行示例 bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365]"
# RAILS_ENV=production bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365]" # RAILS_ENV=production bundle exec rake "import_from_chandao:tasks[复杂智能软件项目-所有任务.csv, 365]"
task :tasks, [:name, :pm_project_id] => :environment do |t, args| task :tasks, [:name, :pm_project_id, :org_login] => :environment do |t, args|
org = Organization.find_by(login: args.org_login)
if org.present?
def trans_status(str) def trans_status(str)
h={ h={
"未开始" => 1, "未开始" => 1,
@ -85,17 +117,25 @@ namespace :import_from_chandao do
issue.project_id = 0 issue.project_id = 0
issue.pm_project_id = pm_project_id issue.pm_project_id = pm_project_id
issue.pm_issue_type = 2 issue.pm_issue_type = 2
sprint_name = randd_field_hash['所属迭代'].split('(#')[0]
sprint = get_sprint_data(sprint_name, args.pm_project_id, org)
issue.pm_sprint_id = sprint['id'] if sprint.present?
issue.save! issue.save!
requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 1) rescue nil requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 1) rescue nil
if requirement_issue.present? if requirement_issue.present?
requirement_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) requirement_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id)
end end
end end
else
puts '组织不存在'
end
end end
# 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" # 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]"
# RAILS_ENV=production 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| task :requirements, [:name, :pm_project_id, :org_login] => :environment do |t, args|
org = Organization.find_by(login: args.org_login)
if org.present?
def trans_status(str) def trans_status(str)
h={ h={
"草稿" => 1, "草稿" => 1,
@ -129,5 +169,8 @@ namespace :import_from_chandao do
issue.pm_issue_type = 1 issue.pm_issue_type = 1
issue.save! issue.save!
end end
else
puts '组织不存在'
end
end end
end end