@@ -248,7 +248,6 @@ def process_issue(
248248 )
249249 analysis = cached_data .get ("analysis" , {})
250250 report = cached_data .get ("email_report" , {})
251- # Use cached issue_data merged with basic data
252251 issue_data = {** basic_issue_data , ** cached_data .get ("issue_data" , {})}
253252 else :
254253 if skip_cache :
@@ -270,20 +269,18 @@ def process_issue(
270269 try :
271270 analysis = analyzer .analyze_issue (issue_data , gitlab_url = gitlab_url )
272271 except AnalysisError as e :
273- # Store error in cache for UI display
274272 error_message = str (e )
275273 if issue_id and analysis_cache :
276274 analysis_cache .set (
277275 issue_id ,
278- {}, # Empty analysis
276+ {},
279277 issue_iid ,
280278 issue_data ,
281279 email_report = None ,
282280 error = error_message ,
283281 )
284282 raise
285283
286- # Generate email report
287284 subject_prefix = config ["smtp" ].get ("subject_prefix" , "[GitLab Issue Analysis]" )
288285 report = generate_email_report (issue_data , analysis , subject_prefix )
289286
@@ -293,25 +290,23 @@ def process_issue(
293290 issue_id , analysis , issue_iid , issue_data , email_report = report , error = None
294291 )
295292
296- # Send email (non-blocking - mark as processed even if email fails)
297- # Use custom to_email if provided, otherwise use default from config
298- email_recipients = to_email if to_email is not None else config ["smtp" ]["to_email" ]
299- if isinstance (email_recipients , str ):
300- email_recipients = [email_recipients ]
293+ email_recipients = to_email if to_email is not None else config ["smtp" ]["to_email" ]
294+ if isinstance (email_recipients , str ):
295+ email_recipients = [email_recipients ]
301296
302- try :
303- logger .info (f"👉 Sending email for issue #{ issue_iid } to { email_recipients } " )
304- email_sender .send_email (
305- to = email_recipients ,
306- subject = report ["subject" ],
307- body = report ["text" ],
308- html_body = report ["html" ],
309- )
310- logger .info (f"✅ Email sent successfully for issue #{ issue_iid } " )
311- except EmailError as e :
312- logger .warning (
313- f"Email failed for issue #{ issue_iid } : { e } . Issue will still be marked as processed."
314- )
297+ try :
298+ logger .info (f"👉 Sending email for issue #{ issue_iid } to { email_recipients } " )
299+ email_sender .send_email (
300+ to = email_recipients ,
301+ subject = report ["subject" ],
302+ body = report ["text" ],
303+ html_body = report ["html" ],
304+ )
305+ logger .info (f"✅ Email sent successfully for issue #{ issue_iid } " )
306+ except EmailError as e :
307+ logger .warning (
308+ f"Email failed for issue #{ issue_iid } : { e } . Issue will still be marked as processed."
309+ )
315310
316311 # Mark as processed (even if email failed)
317312 if issue_id :
@@ -368,69 +363,54 @@ def process_issue_from_data(
368363 return False
369364
370365 try :
366+ issue_id = issue .get ("id" )
367+
368+ if not skip_cache and issue_id and analysis_cache :
369+ cached_data = analysis_cache .get_issue_with_report (issue_id , issue_iid )
370+ if cached_data :
371+ return True
372+
371373 logger .info (f"👉 Processing issue #{ issue_iid } from project { project_id } " )
372374
373375 if dry_run :
374376 return True
375377
376- # Check cache first (unless skip_cache is True) - we already have issue data with id
377- issue_id = issue .get ("id" )
378- cached_data = None
379- if not skip_cache and issue_id and analysis_cache :
380- cached_data = analysis_cache .get_issue_with_report (issue_id , issue_iid )
381-
382- if cached_data :
378+ if skip_cache :
383379 logger .info (
384- f"👉 Using cached analysis for issue #{ issue_iid } (ID: { issue_id } )"
380+ f"👉 Skipping cache and re-analyzing issue #{ issue_iid } (ID: { issue_id } )"
385381 )
386- analysis = cached_data .get ("analysis" , {})
387- report = cached_data .get ("email_report" , {})
388- # Use cached issue_data merged with original issue data
389- issue_data = {** issue , ** cached_data .get ("issue_data" , {})}
390- else :
391- if skip_cache :
392- logger .info (
393- f"👉 Skipping cache and re-analyzing issue #{ issue_iid } (ID: { issue_id } )"
394- )
395- # Fetch comprehensive issue data (comments, attachments, etc.) for analysis
396- logger .info (f"👉 Fetching comprehensive data for issue #{ issue_iid } " )
397- comprehensive_data = gitlab_client .fetch_comprehensive_issue_data (
398- issue_iid , project_id = project_id
399- )
400- # Merge with the original issue data to ensure we have all fields
401- issue_data = {** issue , ** comprehensive_data }
402- logger .info (f"✅ Fetched comprehensive data for issue #{ issue_iid } successfully" )
403-
404- # Analyze issue
405- logger .info (f"👉 Analyzing issue #{ issue_iid } ..." )
406- gitlab_url = config .get ("gitlab" , {}).get ("url" ) if config else None
407- try :
408- analysis = analyzer .analyze_issue (issue_data , gitlab_url = gitlab_url )
409- except AnalysisError as e :
410- # Store error in cache for UI display
411- error_message = str (e )
412- if issue_id and analysis_cache :
413- analysis_cache .set (
414- issue_id ,
415- {}, # Empty analysis
416- issue_iid ,
417- issue_data ,
418- email_report = None ,
419- error = error_message ,
420- )
421- raise
422-
423- # Generate email report
424- subject_prefix = config ["smtp" ].get ("subject_prefix" , "[GitLab Issue Analysis]" )
425- report = generate_email_report (issue_data , analysis , subject_prefix )
426-
427- # Cache analysis and email report together (only once, after both are ready)
382+ logger .info (f"👉 Fetching comprehensive data for issue #{ issue_iid } " )
383+ comprehensive_data = gitlab_client .fetch_comprehensive_issue_data (
384+ issue_iid , project_id = project_id
385+ )
386+ issue_data = {** issue , ** comprehensive_data }
387+ logger .info (f"✅ Fetched comprehensive data for issue #{ issue_iid } successfully" )
388+
389+ logger .info (f"👉 Analyzing issue #{ issue_iid } ..." )
390+ gitlab_url = config .get ("gitlab" , {}).get ("url" ) if config else None
391+ try :
392+ analysis = analyzer .analyze_issue (issue_data , gitlab_url = gitlab_url )
393+ except AnalysisError as e :
394+ error_message = str (e )
428395 if issue_id and analysis_cache :
429396 analysis_cache .set (
430- issue_id , analysis , issue_iid , issue_data , email_report = report , error = None
397+ issue_id ,
398+ {},
399+ issue_iid ,
400+ issue_data ,
401+ email_report = None ,
402+ error = error_message ,
431403 )
404+ raise
405+
406+ subject_prefix = config ["smtp" ].get ("subject_prefix" , "[GitLab Issue Analysis]" )
407+ report = generate_email_report (issue_data , analysis , subject_prefix )
408+
409+ if issue_id and analysis_cache :
410+ analysis_cache .set (
411+ issue_id , analysis , issue_iid , issue_data , email_report = report , error = None
412+ )
432413
433- # Send email (non-blocking - mark as processed even if email fails)
434414 to_email = config ["smtp" ]["to_email" ]
435415 if isinstance (to_email , str ):
436416 to_email = [to_email ]
@@ -449,7 +429,6 @@ def process_issue_from_data(
449429 f"Email failed for issue #{ issue_iid } : { e } . Issue will still be marked as processed."
450430 )
451431
452- # Mark as processed (even if email failed)
453432 if issue_id :
454433 monitor .mark_as_processed (issue_id )
455434
0 commit comments