Spaces:
Sleeping
Sleeping
pranav8tripathi@gmail.com commited on
Commit Β·
edf1d63
1
Parent(s): 9455009
enhanced comments
Browse files- app/github_service.py +11 -8
- app/github_webhook.py +12 -12
app/github_service.py
CHANGED
|
@@ -32,14 +32,17 @@ async def post_file_review(owner: str, repo: str, pr_number: int, filename: str,
|
|
| 32 |
|
| 33 |
review_body = f"### π€ AI Review: `{filename}`\n\n"
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
review_body += "_Posted by PRism AI Reviewer_ π€"
|
| 45 |
|
|
|
|
| 32 |
|
| 33 |
review_body = f"### π€ AI Review: `{filename}`\n\n"
|
| 34 |
|
| 35 |
+
if not ai_feedback:
|
| 36 |
+
review_body += "β
No critical issues found in this file.\n\n"
|
| 37 |
+
else:
|
| 38 |
+
for c in ai_feedback:
|
| 39 |
+
line = c.get("line", 0)
|
| 40 |
+
severity = c.get("severity", "info").capitalize()
|
| 41 |
+
comment = c.get("comment", "").strip()
|
| 42 |
+
emoji_map = {"low": "π’", "medium": "π ", "high": "π΄", "info": "π‘"}
|
| 43 |
+
emoji = emoji_map.get(c.get("severity", "").lower(), "π‘")
|
| 44 |
+
|
| 45 |
+
review_body += f"{emoji} **{severity}** (Line {line}): {comment}\n\n"
|
| 46 |
|
| 47 |
review_body += "_Posted by PRism AI Reviewer_ π€"
|
| 48 |
|
app/github_webhook.py
CHANGED
|
@@ -31,7 +31,7 @@ async def github_webhook(request: Request):
|
|
| 31 |
event_type = request.headers.get("X-GitHub-Event", "")
|
| 32 |
logger.info(f"π Event Type: {event_type}")
|
| 33 |
|
| 34 |
-
# Only process pull_request events
|
| 35 |
if event_type != "pull_request":
|
| 36 |
logger.info(f"βοΈ Ignoring {event_type} event (only processing pull_request events)")
|
| 37 |
return {"message": f"Ignored {event_type} event"}
|
|
@@ -90,7 +90,8 @@ async def github_webhook(request: Request):
|
|
| 90 |
files_with_patches = [f for f in files if f.get("patch") and should_review_file(f["filename"])]
|
| 91 |
|
| 92 |
if files_with_patches:
|
| 93 |
-
|
|
|
|
| 94 |
await post_pr_comment(owner, repo, pr_number, initial_msg)
|
| 95 |
logger.info("π’ Posted initial status comment")
|
| 96 |
else:
|
|
@@ -119,13 +120,10 @@ async def github_webhook(request: Request):
|
|
| 119 |
ai_feedback = await analyze_code(f["filename"], f["patch"])
|
| 120 |
logger.info(f" β
AI returned {len(ai_feedback)} comments")
|
| 121 |
|
| 122 |
-
# Post review for this file immediately
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
logger.info(f" π€ Posted {len(ai_feedback)} comments for {f['filename']}")
|
| 127 |
-
else:
|
| 128 |
-
logger.info(f" β
No issues found in {f['filename']}")
|
| 129 |
except Exception as file_error:
|
| 130 |
logger.error(f" β Error analyzing {f['filename']}: {str(file_error)}")
|
| 131 |
# Post error comment for this file
|
|
@@ -137,11 +135,13 @@ async def github_webhook(request: Request):
|
|
| 137 |
|
| 138 |
if files_analyzed > 0:
|
| 139 |
summary_msg = f"β
**PRism AI Review Complete!**\n\n"
|
| 140 |
-
summary_msg += f"π Analyzed {files_analyzed} file(s)\n"
|
| 141 |
if total_comments == 0:
|
| 142 |
-
summary_msg += "
|
| 143 |
else:
|
| 144 |
-
summary_msg += f"π¬ Found {total_comments} issue(s) - please review above
|
|
|
|
|
|
|
| 145 |
|
| 146 |
await post_pr_comment(owner, repo, pr_number, summary_msg)
|
| 147 |
logger.info("β
Posted final summary")
|
|
|
|
| 31 |
event_type = request.headers.get("X-GitHub-Event", "")
|
| 32 |
logger.info(f"π Event Type: {event_type}")
|
| 33 |
|
| 34 |
+
# Only process pull_request events- Ignore rest
|
| 35 |
if event_type != "pull_request":
|
| 36 |
logger.info(f"βοΈ Ignoring {event_type} event (only processing pull_request events)")
|
| 37 |
return {"message": f"Ignored {event_type} event"}
|
|
|
|
| 90 |
files_with_patches = [f for f in files if f.get("patch") and should_review_file(f["filename"])]
|
| 91 |
|
| 92 |
if files_with_patches:
|
| 93 |
+
#hello
|
| 94 |
+
initial_msg = f"π€ **PRism AI is reviewing your PR right now...**\n\nAnalyzing {len(files_with_patches)} file(s). Only critical issues will be reported."
|
| 95 |
await post_pr_comment(owner, repo, pr_number, initial_msg)
|
| 96 |
logger.info("π’ Posted initial status comment")
|
| 97 |
else:
|
|
|
|
| 120 |
ai_feedback = await analyze_code(f["filename"], f["patch"])
|
| 121 |
logger.info(f" β
AI returned {len(ai_feedback)} comments")
|
| 122 |
|
| 123 |
+
# Post review for this file immediately (even if no issues)
|
| 124 |
+
await post_file_review(owner, repo, pr_number, f["filename"], ai_feedback)
|
| 125 |
+
total_comments += len(ai_feedback)
|
| 126 |
+
logger.info(f" π€ Posted review for {f['filename']} ({len(ai_feedback)} issues)")
|
|
|
|
|
|
|
|
|
|
| 127 |
except Exception as file_error:
|
| 128 |
logger.error(f" β Error analyzing {f['filename']}: {str(file_error)}")
|
| 129 |
# Post error comment for this file
|
|
|
|
| 135 |
|
| 136 |
if files_analyzed > 0:
|
| 137 |
summary_msg = f"β
**PRism AI Review Complete!**\n\n"
|
| 138 |
+
summary_msg += f"π Analyzed **{files_analyzed}** file(s)\n"
|
| 139 |
if total_comments == 0:
|
| 140 |
+
summary_msg += f"π¬ Found **{total_comments}** issue(s) - please review above.\n\n"
|
| 141 |
else:
|
| 142 |
+
summary_msg += f"π¬ Found **{total_comments}** issue(s) - please review above.\n\n"
|
| 143 |
+
|
| 144 |
+
summary_msg += "---\n_Posted by PRism AI Reviewer_ π€"
|
| 145 |
|
| 146 |
await post_pr_comment(owner, repo, pr_number, summary_msg)
|
| 147 |
logger.info("β
Posted final summary")
|