79 lines
2.4 KiB
Python
79 lines
2.4 KiB
Python
import json
|
|
import os
|
|
import sys
|
|
|
|
import requests
|
|
|
|
|
|
from dotenv import load_dotenv
|
|
from logging_config import setup_logging
|
|
|
|
load_dotenv()
|
|
|
|
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'
|
|
TOKEN = os.getenv('TOKEN')
|
|
|
|
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'
|
|
headers = {
|
|
'Host': 'api.tracker.yandex.net',
|
|
'Authorization': TOKEN,
|
|
'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}')
|
|
|
|
|
|
# Вызов функции для закрытия задач в очереди 'TESTIMPORT'
|
|
close_tasks_in_queue('TESTIMPORT')
|