diff --git a/api/comment_fix.py b/api/comment_fix.py new file mode 100644 index 0000000..457c1b0 --- /dev/null +++ b/api/comment_fix.py @@ -0,0 +1,37 @@ +# Nova função post_analysis_comment com formatação melhor +async def post_analysis_comment(ticket: dict, result: dict): + """Post analysis result back to TicketHub as a comment""" + ticket_id = ticket.get("id") + if not ticket_id: + return + + confidence_pct = int(result.get("confidence", 0) * 100) + files = ", ".join(result.get("affected_files", ["Unknown"])) + + # Formatação texto plano com quebras de linha claras + comment = f"""🤖 AI ANALYSIS COMPLETE +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +📋 ROOT CAUSE: +{result.get('analysis', 'Unable to determine')} + +📁 AFFECTED FILES: {files} + +🔧 SUGGESTED FIX: +──────────────────────────────────────── +{result.get('suggested_fix', 'No fix suggested')} +──────────────────────────────────────── + +📊 CONFIDENCE: {confidence_pct}% + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Analyzed by JIRA AI Fixer""" + + async with httpx.AsyncClient(timeout=10.0) as client: + try: + await client.post( + f"https://tickethub.startdata.com.br/api/tickets/{ticket_id}/comments", + json={"author": "AI Fixer", "content": comment} + ) + except: + pass diff --git a/api/main_v2.py b/api/main_v2.py index 188d2c7..7af0efc 100644 --- a/api/main_v2.py +++ b/api/main_v2.py @@ -290,21 +290,24 @@ async def post_analysis_comment(ticket: dict, result: dict): confidence_pct = int(result.get("confidence", 0) * 100) files = ", ".join(result.get("affected_files", ["Unknown"])) - comment = f"""🤖 **AI Analysis Complete** + # Formatação texto plano com quebras de linha claras + comment = f"""🤖 AI ANALYSIS COMPLETE +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ -**Root Cause:** {result.get('analysis', 'Unable to determine')} +📋 ROOT CAUSE: +{result.get('analysis', 'Unable to determine')} -**Affected Files:** {files} +📁 AFFECTED FILES: {files} -**Suggested Fix:** -```cobol +🔧 SUGGESTED FIX: +──────────────────────────────────────── {result.get('suggested_fix', 'No fix suggested')} -``` +──────────────────────────────────────── -**Confidence:** {confidence_pct}% +📊 CONFIDENCE: {confidence_pct}% ---- -_Analyzed by JIRA AI Fixer_""" +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Analyzed by JIRA AI Fixer""" async with httpx.AsyncClient(timeout=10.0) as client: try: