1
0

update_taiga_status.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import requests
  2. import urllib3
  3. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  4. base_url = 'https://192.168.130.161/taiga/api/v1'
  5. def close_sprint_tasks():
  6. try:
  7. # Authenticate
  8. auth = requests.post(f'{base_url}/auth', json={'type': 'normal', 'username': 'FrancoisLange', 'password': 'BTSai123'}, verify=False).json()
  9. headers = {'Authorization': f'Bearer {auth["auth_token"]}', 'Content-Type': 'application/json'}
  10. proj_id = 21
  11. # 1. Get Milestone (Sprint 9)
  12. milestones = requests.get(f'{base_url}/milestones?project={proj_id}', headers=headers, verify=False).json()
  13. sprint9 = next((m for m in milestones if m['name'] == 'Sprint 9'), None)
  14. if not sprint9:
  15. print("Sprint 9 not found!")
  16. return
  17. sprint_id = sprint9['id']
  18. # 2. Get 'Closed' Task Status ID
  19. statuses = requests.get(f'{base_url}/task-statuses?project={proj_id}', headers=headers, verify=False).json()
  20. closed_status = next((s for s in statuses if s['is_closed']), None)
  21. if not closed_status:
  22. print("Could not find a 'Closed' task status for the project.")
  23. return
  24. closed_status_id = closed_status['id']
  25. print(f"Found Closed Status ID: {closed_status_id}")
  26. # 3. Get all tasks for Sprint 9
  27. tasks = requests.get(f'{base_url}/tasks?project={proj_id}&milestone={sprint_id}', headers=headers, verify=False).json()
  28. # 4. Close Tasks
  29. for task in tasks:
  30. if task['status'] != closed_status_id:
  31. payload = {
  32. "status": closed_status_id,
  33. "version": task['version']
  34. }
  35. res = requests.patch(f'{base_url}/tasks/{task["id"]}', json=payload, headers=headers, verify=False).json()
  36. print(f"Closed Task TG-{task['ref']}: {task['subject']}")
  37. else:
  38. print(f"Task TG-{task['ref']} already closed.")
  39. print("Successfully updated all Taiga tasks to Closed!")
  40. except Exception as e:
  41. print(f"Error updating Taiga: {e}")
  42. if __name__ == "__main__":
  43. close_sprint_tasks()