Spaces:
Sleeping
Sleeping
Commit ·
fea3cfe
1
Parent(s): 427e0f5
logic changes
Browse files- api/webhook_routes.py +26 -8
api/webhook_routes.py
CHANGED
|
@@ -67,23 +67,41 @@ async def receive_jira_webhook(
|
|
| 67 |
"webhook_event": payload,
|
| 68 |
"synced_at": datetime.utcnow().isoformat(),
|
| 69 |
"assigned_issues": [],
|
| 70 |
-
"
|
| 71 |
"boards": []
|
| 72 |
}
|
| 73 |
|
| 74 |
-
# Fetch Assigned Issues
|
| 75 |
-
|
| 76 |
-
full_data["assigned_issues"] = [issue.model_dump(mode='json') for issue in
|
| 77 |
|
| 78 |
-
# Fetch All Projects
|
| 79 |
projects = jira_service.get_projects()
|
| 80 |
-
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
boards = jira_service.get_boards()
|
| 84 |
full_data["boards"] = boards
|
| 85 |
|
| 86 |
-
logger.info(f"Synced for user {account_id}: {len(
|
| 87 |
|
| 88 |
# 5. Store data
|
| 89 |
success = supabase_service.upsert_jira_data(firebase_id, full_data)
|
|
|
|
| 67 |
"webhook_event": payload,
|
| 68 |
"synced_at": datetime.utcnow().isoformat(),
|
| 69 |
"assigned_issues": [],
|
| 70 |
+
"projects_data": [], # Renamed to store rich data
|
| 71 |
"boards": []
|
| 72 |
}
|
| 73 |
|
| 74 |
+
# A. Fetch Assigned Issues (Just for quick reference)
|
| 75 |
+
assigned_issues = jira_service.get_issues_assigned_to_user(account_id)
|
| 76 |
+
full_data["assigned_issues"] = [issue.model_dump(mode='json') for issue in assigned_issues]
|
| 77 |
|
| 78 |
+
# B. Fetch All Projects & Their Contents (Spaces)
|
| 79 |
projects = jira_service.get_projects()
|
| 80 |
+
logger.info(f"Found {len(projects)} projects for user. Fetching details...")
|
| 81 |
|
| 82 |
+
for project in projects:
|
| 83 |
+
# 1. Fetch All Issues in Project (Limit 50 to avoid timeout for now, can increase)
|
| 84 |
+
# We need a method to get issues by project key
|
| 85 |
+
try:
|
| 86 |
+
project_issues = jira_service.get_issues_by_project(project.key, max_results=50)
|
| 87 |
+
|
| 88 |
+
full_data["projects_data"].append({
|
| 89 |
+
"project_info": project.model_dump(mode='json'),
|
| 90 |
+
"issues": [issue.model_dump(mode='json') for issue in project_issues]
|
| 91 |
+
})
|
| 92 |
+
except Exception as e:
|
| 93 |
+
logger.error(f"Failed to fetch issues for project {project.key}: {str(e)}")
|
| 94 |
+
# Add project without issues in worst case
|
| 95 |
+
full_data["projects_data"].append({
|
| 96 |
+
"project_info": project.model_dump(mode='json'),
|
| 97 |
+
"issues": []
|
| 98 |
+
})
|
| 99 |
+
|
| 100 |
+
# C. Fetch All Boards
|
| 101 |
boards = jira_service.get_boards()
|
| 102 |
full_data["boards"] = boards
|
| 103 |
|
| 104 |
+
logger.info(f"Synced for user {account_id}: Assigned={len(assigned_issues)}, Projects={len(full_data['projects_data'])}, Boards={len(boards)}")
|
| 105 |
|
| 106 |
# 5. Store data
|
| 107 |
success = supabase_service.upsert_jira_data(firebase_id, full_data)
|