Skip to content

Commit d7d7a05

Browse files
committed
Merge pull request stateio#7 from mozamimy/fix/when-there-is-blank-fields
Fix the behavior when there are blank fields.
2 parents 2ad49f0 + 6ad4b1a commit d7d7a05

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

app/controllers/importer_controller.rb

+32-25
Original file line numberDiff line numberDiff line change
@@ -394,21 +394,23 @@ def assign_issue_attrs(issue, category, fixed_version_id, assigned_to, status, r
394394
issue.tracker_id = tracker.present? ? tracker.id : issue.tracker_id
395395

396396
# optional attributes
397-
issue.description = fetch("description", row) || issue.description
398-
issue.category_id = category != nil ? category.id : issue.category_id
397+
issue.description = fetch("description", row)
398+
issue.category_id = category.try(:id)
399399

400-
if fetch("start_date", row).present?
401-
issue.start_date = Date.parse(fetch("start_date", row))
400+
["start_date", "due_date"].each do |date_field_name|
401+
date_field_value = fetch(date_field_name, row)
402+
403+
if date_field_value.present?
404+
issue.send("#{date_field_name}=", Date.parse(date_field_value))
405+
else
406+
issue.send("#{date_field_name}=", nil)
407+
end
402408
end
403-
issue.due_date = if row[@attrs_map["due_date"]].blank?
404-
nil
405-
else
406-
Date.parse(row[@attrs_map["due_date"]])
407-
end
408-
issue.assigned_to_id = assigned_to.id if assigned_to
409-
issue.fixed_version_id = fixed_version_id if fixed_version_id
410-
issue.done_ratio = row[@attrs_map["done_ratio"]] || issue.done_ratio
411-
issue.estimated_hours = row[@attrs_map["estimated_hours"]] || issue.estimated_hours
409+
410+
issue.assigned_to_id = assigned_to.try(:id)
411+
issue.fixed_version_id = fixed_version_id
412+
issue.done_ratio = fetch("done_ratio", row)
413+
issue.estimated_hours = fetch("estimated_hours", row)
412414
issue.is_private = (convert_to_boolean(fetch("is_private", row)) || false)
413415
end
414416

@@ -489,18 +491,23 @@ def handle_custom_fields(add_versions, issue, project, row)
489491
h[cf.id] = process_multivalue_custom_field(project, add_versions, issue, cf, value)
490492
else
491493
begin
492-
value = case cf.field_format
493-
when 'user'
494-
user_id_for_login!(value).to_s
495-
when 'version'
496-
version_id_for_name!(project, value, add_versions).to_s
497-
when 'date'
498-
value.to_date.to_s(:db)
499-
when 'bool'
500-
convert_to_0_or_1(value)
501-
else
502-
value
503-
end
494+
if value.present?
495+
value = case cf.field_format
496+
when 'user'
497+
user_id_for_login!(value).to_s
498+
when 'version'
499+
version_id_for_name!(project, value, add_versions).to_s
500+
when 'date'
501+
value.to_date.to_s(:db)
502+
when 'bool'
503+
convert_to_0_or_1(value)
504+
else
505+
value
506+
end
507+
else
508+
value = nil
509+
end
510+
504511
h[cf.id] = value
505512
rescue
506513
if custom_failed_count == 0

0 commit comments

Comments
 (0)