Mapping_ya_tracker/resolved_task.py

76 lines
2.4 KiB
Python
Raw Normal View History

2023-12-10 21:15:45 +05:00
import json
import os
import sys
import requests
from logging_config import setup_logging
logger = setup_logging(__name__)
base_dir = os.path.dirname(os.path.realpath(__file__))
asana_data_json = os.path.join(base_dir, './data/data_asana.json')
users_data = os.path.join(base_dir, './data/users.mapping.asana2ya.csv')
sys.stdin.reconfigure(encoding='utf-8')
sys.stdout.reconfigure(encoding='utf-8')
QUEUE_NAME = 'TESTIMPORT'
def close_tasks_in_queue(queue_name):
base_url = 'https://api.tracker.yandex.net/v2/issues/_search'
# base_url = 'https://api.tracker.yandex.net/v2/issues/_search?expand=transitions'
2023-12-10 21:15:45 +05:00
headers = {
'Host': 'api.tracker.yandex.net',
'Authorization': 'OAuth y0_AgAEA7qkB3KjAArkXwAAAADzMlP9oR1lwMzBS2e94jHzdnII8Laxi7k',
'X-Org-ID': '7095769',
'Content-Type': 'application/json',
}
payload = {
"filter": {
"queue": queue_name,
"status": "open" # Фильтр для открытых задач в указанной очереди
}
}
while True:
response = requests.post(
base_url,
headers=headers,
data=json.dumps(payload)
)
if response.status_code == 200:
logger.debug('Response: %s', response.content)
tasks = response.json()
for task in tasks:
task_id = task['id']
close_payload = {
'resolution': 'fixed'
}
close_url = f'https://api.tracker.yandex.net/v2/issues/{task_id}/transitions/close/_execute'
print(close_url)
print(headers)
close_response = requests.post(
close_url,
headers=headers,
data=json.dumps(close_payload)
)
if close_response.status_code == 200:
print(f'Задача {task_id} закрыта успешно')
else:
print(f'Ошибка при закрытии задачи {task_id}: {close_response.content}')
else:
print(f'Ошибка при получении задач для очереди {queue_name}: {response.content}')
2023-12-10 21:15:45 +05:00
2023-12-10 21:15:45 +05:00
# Вызов функции для закрытия задач в очереди 'TESTIMPORT'
close_tasks_in_queue('TESTIMPORT')