Rudraaaa76 commited on
Commit
9206cfd
·
1 Parent(s): ed71ee4

updated email logic

Browse files
Files changed (1) hide show
  1. api/webhook_routes.py +22 -1
api/webhook_routes.py CHANGED
@@ -1,6 +1,7 @@
1
  from fastapi import APIRouter, Header, Request, HTTPException
2
  import logging
3
  from services.supabase_service import supabase_service
 
4
  from typing import Dict, Any
5
 
6
  logger = logging.getLogger(__name__)
@@ -41,7 +42,27 @@ async def receive_jira_webhook(
41
  user_email = payload["user"].get("emailAddress")
42
 
43
  if not user_email:
44
- logger.warning("Could not identify user email from webhook payload")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  logger.warning(f"Payload snippet: {str(payload)[:500]}...") # Log first 500 chars to debug
46
  # We still return 200 to Jira so it doesn't retry infinitely
47
  return {"status": "ignored", "reason": "no_email_found"}
 
1
  from fastapi import APIRouter, Header, Request, HTTPException
2
  import logging
3
  from services.supabase_service import supabase_service
4
+ from integrations.jira_service import JiraIntegrationService
5
  from typing import Dict, Any
6
 
7
  logger = logging.getLogger(__name__)
 
42
  user_email = payload["user"].get("emailAddress")
43
 
44
  if not user_email:
45
+ logger.warning("Email not found in payload. Attempting to fetch user details from Jira API.")
46
+
47
+ # Try to get accountId from payload
48
+ account_id = None
49
+ if "user" in payload and "accountId" in payload["user"]:
50
+ account_id = payload["user"]["accountId"]
51
+ elif "issue" in payload and payload["issue"].get("fields", {}).get("assignee"):
52
+ account_id = payload["issue"]["fields"]["assignee"].get("accountId")
53
+
54
+ if account_id:
55
+ try:
56
+ jira_service = JiraIntegrationService()
57
+ user_profile = jira_service._get_user_details(account_id)
58
+ user_email = user_profile.get("emailAddress")
59
+ if user_email:
60
+ logger.info(f"Successfully fetched email {user_email} for accountId {account_id}")
61
+ except Exception as e:
62
+ logger.error(f"Failed to fetch user details from Jira: {str(e)}")
63
+
64
+ if not user_email:
65
+ logger.warning("Could not identify user email from webhook payload or Jira API")
66
  logger.warning(f"Payload snippet: {str(payload)[:500]}...") # Log first 500 chars to debug
67
  # We still return 200 to Jira so it doesn't retry infinitely
68
  return {"status": "ignored", "reason": "no_email_found"}