close_taiga_items.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import requests
  2. import urllib3
  3. import sys
  4. urllib3.disable_warnings()
  5. sys.stdout.reconfigure(encoding='utf-8')
  6. TAIGA_USER = 'FrancoisLange'
  7. TAIGA_PASS = 'your_db_password_here'
  8. base_url = 'https://192.168.130.161/taiga/api/v1'
  9. def main():
  10. print("Connecting to Taiga...")
  11. auth_resp = requests.post(f'{base_url}/auth', json={'type': 'normal', 'username': TAIGA_USER, 'password': TAIGA_PASS}, verify=False)
  12. if auth_resp.status_code != 200:
  13. print("Auth failed!")
  14. return
  15. auth = auth_resp.json()
  16. headers = {'Authorization': f'Bearer {auth["auth_token"]}', 'Content-Type': 'application/json', 'x-disable-pagination': 'true'}
  17. project_id = 21
  18. # 1. Close all user stories
  19. print("\n--- 1. Closing User Stories ---")
  20. us_resp = requests.get(f'{base_url}/userstories?project={project_id}', headers=headers, verify=False).json()
  21. for us in us_resp:
  22. # Done status is ID 125
  23. if us['status'] != 125:
  24. print(f"Closing User Story {us['ref']}: {us['subject']}...")
  25. patch = {"status": 125, "version": us['version']}
  26. requests.patch(f"{base_url}/userstories/{us['id']}", json=patch, headers=headers, verify=False)
  27. else:
  28. print(f"User Story {us['ref']}: {us['subject']} is already Done.")
  29. # 2. Close all tasks
  30. print("\n--- 2. Closing Tasks ---")
  31. tasks_resp = requests.get(f'{base_url}/tasks?project={project_id}', headers=headers, verify=False).json()
  32. for t in tasks_resp:
  33. # Closed status is ID 104
  34. if t['status'] != 104:
  35. print(f"Closing Task #{t['ref']} ({t['id']}): {t['subject']}...")
  36. patch = {"status": 104, "version": t['version']}
  37. requests.patch(f"{base_url}/tasks/{t['id']}", json=patch, headers=headers, verify=False)
  38. else:
  39. print(f"Task #{t['ref']}: {t['subject']} is already Closed.")
  40. # 3. Close all issues
  41. print("\n--- 3. Closing Issues ---")
  42. issues_resp = requests.get(f'{base_url}/issues?project={project_id}', headers=headers, verify=False).json()
  43. for issue in issues_resp:
  44. # Closed status is ID 144
  45. if issue['status'] != 144:
  46. print(f"Closing Issue #{issue['ref']}: {issue['subject']}...")
  47. patch = {"status": 144, "version": issue['version']}
  48. requests.patch(f"{base_url}/issues/{issue['id']}", json=patch, headers=headers, verify=False)
  49. else:
  50. print(f"Issue #{issue['ref']}: {issue['subject']} is already Closed.")
  51. print("\nTaiga cleanup completed successfully!")
  52. if __name__ == '__main__':
  53. main()