sync_taiga.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import os
  2. import requests
  3. import urllib3
  4. from datetime import datetime, timedelta
  5. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  6. # Authenticate
  7. base_url = 'https://192.168.130.161/taiga/api/v1'
  8. auth_url = f'{base_url}/auth'
  9. auth = requests.post(auth_url, json={'type': 'normal', 'username': 'lanfr1904@outlook.com', 'password': 'BTSai123'}, verify=False).json()
  10. headers = {'Authorization': f'Bearer {auth["auth_token"]}', 'Content-Type': 'application/json'}
  11. proj_id = 21
  12. # 1. Sync Milestones (Sprints 1-8)
  13. print("Syncing Sprints/Milestones...")
  14. existing_m_res = requests.get(f'{base_url}/milestones?project={proj_id}', headers=headers, verify=False).json()
  15. existing_sprints = {m['name']: m for m in existing_m_res}
  16. start_date = datetime(2026, 4, 16)
  17. for i in range(1, 9):
  18. sprint_name = f"Sprint {i}"
  19. sprint_start = start_date + timedelta(weeks=i-1)
  20. sprint_end = sprint_start + timedelta(days=6)
  21. if sprint_name not in existing_sprints:
  22. payload = {
  23. "project": proj_id,
  24. "name": sprint_name,
  25. "estimated_start": sprint_start.strftime('%Y-%m-%d'),
  26. "estimated_finish": sprint_end.strftime('%Y-%m-%d')
  27. }
  28. res = requests.post(f'{base_url}/milestones', json=payload, headers=headers, verify=False)
  29. if res.status_code == 201:
  30. print(f"Created {sprint_name}")
  31. else:
  32. print(f"Failed to create {sprint_name}: {res.text}")
  33. # 2. Sync Wiki
  34. print("\nSyncing Wiki pages...")
  35. for filename in os.listdir('taiga_wiki'):
  36. if not filename.endswith('.md'):
  37. continue
  38. filepath = os.path.join('taiga_wiki', filename)
  39. with open(filepath, 'r') as f:
  40. content = f.read()
  41. slug = filename.replace('.md', '').lower().replace('_', '-')
  42. # Check if exists
  43. res = requests.get(f'{base_url}/wiki/by_slug?slug={slug}&project={proj_id}', headers=headers, verify=False)
  44. if res.status_code == 200:
  45. # Update
  46. page_id = res.json()['id']
  47. version = res.json()['version']
  48. payload = {
  49. "project": proj_id,
  50. "slug": slug,
  51. "content": content,
  52. "version": version
  53. }
  54. update_res = requests.put(f'{base_url}/wiki/{page_id}', json=payload, headers=headers, verify=False)
  55. print(f"Updated wiki '{slug}' (status {update_res.status_code})")
  56. if update_res.status_code != 200:
  57. print(update_res.text)
  58. else:
  59. # Create
  60. payload = {
  61. "project": proj_id,
  62. "slug": slug,
  63. "content": content
  64. }
  65. create_res = requests.post(f'{base_url}/wiki', json=payload, headers=headers, verify=False)
  66. print(f"Created wiki '{slug}' (status {create_res.status_code})")
  67. if create_res.status_code != 201:
  68. print(create_res.text)
  69. print("\nDone syncing to Taiga Local Food AI project!")