refactor(mapping): add task_tatus

This commit is contained in:
Angelina Tingaeva 2023-11-29 14:08:36 +05:00
parent 8546782a22
commit 3c6221ad90

View File

@ -43,17 +43,32 @@ def get_assignee_data():
assignee = get_assignee_data() assignee = get_assignee_data()
def get_task_status(task):
""" Получение данных о статусе задачи """
if task.get('completed') is True:
status = 'resolved'
completed_at = task.get('completed_at', '')
else:
status = 'open'
completed_at = ''
return status, completed_at
def transform_data(data): def transform_data(data):
""" Преобразование данных из Asana в ЯндексТрекер в совместимом формате """ """ Преобразование данных из Asana в ЯндексТрекер в совместимом формате """
transformed_data = [] transformed_data = []
for task in data["data"]: for task in data["data"]:
status, completed_at = get_task_status(task)
transformed_task = { transformed_task = {
'summary': task['name'], 'summary': task['name'],
'description': task['notes'], 'description': task['notes'],
'createdAt': task['created_at'], 'createdAt': task['created_at'],
'deadline': task['due_on'], 'deadline': task['due_on'],
'assignee': task['assignee'], 'assignee': task['assignee'],
'status': status,
'completedAt': completed_at,
} }
transformed_data.append(transformed_task) transformed_data.append(transformed_task)
return transformed_data return transformed_data
@ -86,7 +101,7 @@ def create_tasks_in_tracker(data):
# 'milestone': task['milestone'], # 'milestone': task['milestone'],
# 'memberships': task['memberships'], # 'memberships': task['memberships'],
# 'parent': task['parent'], # 'parent': task['parent'],
# 'status': task['status'], 'status': task['status'],
} }
response = requests.post( response = requests.post(
base_url, base_url,