upload_plan.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import requests
  2. import urllib3
  3. import os
  4. urllib3.disable_warnings()
  5. TAIGA_USER = os.environ.get('TAIGA_USER', 'FrancoisLange')
  6. TAIGA_PASS = os.environ.get('TAIGA_PASS', 'your_db_password_here')
  7. base_url = 'https://192.168.130.161/taiga/api/v1'
  8. project_id = 21
  9. us_id = 281 # ID of the new User Story
  10. def main():
  11. print("Connecting to Taiga...")
  12. auth_resp = requests.post(f'{base_url}/auth', json={'type': 'normal', 'username': TAIGA_USER, 'password': TAIGA_PASS}, verify=False)
  13. if auth_resp.status_code != 200:
  14. print("Auth failed!")
  15. return
  16. auth = auth_resp.json()
  17. headers = {
  18. 'Authorization': f'Bearer {auth["auth_token"]}'
  19. }
  20. plan_path = r"C:\Users\lanfr144\.gemini\antigravity-ide\brain\74c205dc-e2c0-4179-9849-9d8dda480c08\implementation_plan.md"
  21. if not os.path.exists(plan_path):
  22. print(f"Error: Implementation plan not found at {plan_path}")
  23. return
  24. # 1. Attach to User Story
  25. print(f"Uploading implementation_plan.md to User Story {us_id}...")
  26. with open(plan_path, 'rb') as f:
  27. files = {'attached_file': ('implementation_plan.md', f, 'text/markdown')}
  28. data = {'project': project_id, 'object_id': us_id}
  29. resp = requests.post(f'{base_url}/userstories/attachments', data=data, files=files, headers=headers, verify=False)
  30. if resp.status_code == 201:
  31. print("Successfully attached implementation plan to User Story!")
  32. else:
  33. print(f"Failed to attach to User Story: {resp.status_code} {resp.text}")
  34. # 2. Fetch Tasks under this US and attach to each
  35. tasks = requests.get(f'{base_url}/tasks?user_story={us_id}', headers={'Authorization': f'Bearer {auth["auth_token"]}', 'x-disable-pagination': 'true'}, verify=False).json()
  36. for task in tasks:
  37. t_id = task['id']
  38. t_subject = task['subject']
  39. print(f"Uploading implementation_plan.md to Task '{t_subject}' (ID: {t_id})...")
  40. with open(plan_path, 'rb') as f:
  41. files = {'attached_file': ('implementation_plan.md', f, 'text/markdown')}
  42. data = {'project': project_id, 'object_id': t_id}
  43. resp = requests.post(f'{base_url}/tasks/attachments', data=data, files=files, headers=headers, verify=False)
  44. if resp.status_code == 201:
  45. print(f"Successfully attached implementation plan to Task '{t_subject}'!")
  46. else:
  47. print(f"Failed to attach to Task '{t_subject}': {resp.status_code} {resp.text}")
  48. print("Attachment operations completed.")
  49. if __name__ == '__main__':
  50. main()