Skip to content

Commit

Permalink
Convert custom 'Type' field in Pivotal importer to be a dropdown. Add…
Browse files Browse the repository at this point in the history
… support for Priority custom field. Fix saving multiple custom fields
  • Loading branch information
mig5 committed Nov 18, 2024
1 parent c33922f commit 744d1b4
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions taiga/importers/pivotal/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,28 @@ def _import_project_data(self, project_id, options):
UserStoryCustomAttribute.objects.create(
name="Type",
description="Story type",
type="text",
type="dropdown",
order=2,
project=project
project=project,
extra=[
"feature",
"bug",
"chore",
"release"
]
)
UserStoryCustomAttribute.objects.create(
name="Priority",
description="Priority",
type="dropdown",
order=3,
project=project,
extra=[
"Critical",
"High",
"Medium",
"Low"
]
)
for user in options.get('users_bindings', {}).values():
if user != self._user:
Expand Down Expand Up @@ -298,6 +317,7 @@ def _import_user_stories_data(self, project_data, project, options):
epics = {e['label']['id']: e for e in project_data['epics']}
due_date_field = project.userstorycustomattributes.get(name="Due date")
story_type_field = project.userstorycustomattributes.get(name="Type")
story_priority_field = project.userstorycustomattributes.get(name="Priority")
story_milestone_binding = {}
for iteration in project_data['iterations']:
for story in iteration['stories']:
Expand All @@ -318,6 +338,7 @@ def _import_user_stories_data(self, project_data, project, options):
"description",
"estimate",
"story_type",
"story_priority",
"current_state",
"deadline",
"requested_by_id",
Expand Down Expand Up @@ -374,12 +395,23 @@ def _import_user_stories_data(self, project_data, project, options):
if watcher_user:
us.add_watcher(watcher_user)

custom_attributes_values = {}
if story.get('deadline', None):
us.custom_attributes_values.attributes_values = {due_date_field.id: story['deadline']}
us.custom_attributes_values.save()
custom_attributes_values[due_date_field.id] = story['deadline']
if story.get('story_type', None):
us.custom_attributes_values.attributes_values = {story_type_field.id: story['story_type']}
us.custom_attributes_values.save()
custom_attributes_values[story_type_field.id] = story['story_type']
if story.get('story_priority', None):
if story['story_priority'] == "p0":
priority = "Critical"
if story['story_priority'] == "p1":
priority = "High"
if story['story_priority'] == "p2":
priority = "Medium"
if story['story_priority'] == "p3":
priority = "Low"
custom_attributes_values[story_priority_field.id] = priority
us.custom_attributes_values.attributes_values = custom_attributes_values
us.custom_attributes_values.save()

UserStory.objects.filter(id=us.id).update(
ref=story['id'],
Expand Down Expand Up @@ -571,6 +603,7 @@ def _transform_activity_data(self, obj, activity, options):
users_bindings = options.get('users_bindings', {})
due_date_field = obj.project.userstorycustomattributes.get(name="Due date")
story_type_field = obj.project.userstorycustomattributes.get(name="Type")
story_priority_field = obj.project.userstorycustomattributes.get(name="Priority")

user = {"pk": None, "name": activity.get('performed_by', {}).get('name', None)}
taiga_user = users_bindings.get(activity.get('performed_by', {}).get('id', None), None)
Expand Down Expand Up @@ -666,6 +699,23 @@ def _transform_activity_data(self, obj, activity, options):
"id": story_type_field.id
})

if 'story_priority' in change['new_values']:
if "custom_attributes" not in result['change_old']:
result['change_old']["custom_attributes"] = []
if "custom_attributes" not in result['change_new']:
result['change_new']["custom_attributes"] = []

result['change_old']["custom_attributes"].append({
"name": "Priority",
"value": change['original_values']['story_priority'],
"id": story_priority_field.id
})
result['change_new']["custom_attributes"].append({
"name": "Priority",
"value": change['new_values']['story_priority'],
"id": story_priority_field.id
})

if 'deadline' in change['new_values']:
if "custom_attributes" not in result['change_old']:
result['change_old']["custom_attributes"] = []
Expand Down

0 comments on commit 744d1b4

Please sign in to comment.