Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions backend/controllers/webhook/handleWebhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default async function handleWebhook(req, res) {

// --- Fetch commit author email ---
// Email: analysis started
console.log("preparation started");
console.log("preparation started");//
// --- Fetch commit author email ---
let userEmail = req?.user?.email || "";
console.log(userEmail || "ni aayi");
Expand Down Expand Up @@ -163,17 +163,31 @@ export default async function handleWebhook(req, res) {
{ pr: base64Payload },
{ headers: { "Content-Type": "application/json" } }
);
console.log("Model response:", "response aagaya");
// console.log("Model response:", "response aagaya");//

// --- Extract pre-formatted comment from model response ---
const commentText =
modelResp.data?.formatted_comment ||
"PullShark analysis complete. No specific feedback provided.";

// --- Post a comment on the PR ---
try {
await axios.post(
pr.comments_url,
{ body: commentText },
{ headers: ghHeaders }
);
console.log(`Comment posted on PR #${pr.number}`);
} catch (err) {
console.error("Failed to post PR comment:", err.message);
}
Comment on lines +173 to +183
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Email claims PR comment was added even if posting the comment fails

Right now, failures in axios.post(pr.comments_url, ...) are caught and only logged, but the completion email always says “We’ve added a comment to your PR…” and includes ${commentText}. If the GitHub comment post fails, this message becomes misleading.

You can track whether the comment was actually posted and branch the email text accordingly:

-    // --- Post a comment on the PR ---
-    try {
-      await axios.post(
-        pr.comments_url,
-        { body: commentText },
-        { headers: ghHeaders }
-      );
-      console.log(`Comment posted on PR #${pr.number}`);
-    } catch (err) {
-      console.error("Failed to post PR comment:", err.message);
-    }
+    // --- Post a comment on the PR ---
+    let commentPosted = false;
+    try {
+      await axios.post(
+        pr.comments_url,
+        { body: commentText },
+        { headers: ghHeaders }
+      );
+      commentPosted = true;
+      console.log(`Comment posted on PR #${pr.number}`);
+    } catch (err) {
+      console.error("Failed to post PR comment:", err.message);
+    }

@@
-      sendEmail({
-        to: userEmail,
-        subject: `[PullShark] Analysis complete`,
-        text: `Your analysis is complete. We've added a comment to your PR with the details.\n\n${commentText}`,
-      }).catch(() => {});
+      sendEmail({
+        to: userEmail,
+        subject: `[PullShark] Analysis complete`,
+        text: commentPosted
+          ? `Your analysis is complete. We've added a comment to your PR with the details.\n\n${commentText}`
+          : `Your analysis is complete, but we could not add a comment to your PR automatically. Here's the analysis:\n\n${commentText}`,
+      }).catch(() => {});

This keeps the email accurate in both success and failure cases.

Also applies to: 190-191


// Email: analysis done
if (userEmail) {
sendEmail({
to: userEmail,
subject: `[PullShark] Analysis complete`,
text: `Your analysis is complete: ${JSON.stringify(
modelResp.data,
null,
2
)}`,
text: `Your analysis is complete. We've added a comment to your PR with the details.\n\n${commentText}`,
}).catch(() => {});
}

Expand Down