Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Commit 7cccff9

Browse files
authored
Merge pull request #98 from djcruz93/fix-store-latest-15-webhook-events
[FIX] Store unlimited webhook events for each webhook
2 parents 8427d31 + 7283878 commit 7cccff9

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

server/controllers/webhooks.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,23 @@ module.exports.handleGithubWebhook = async (req, res) => {
2121
(req.body["issue"] && req.body["issue"]["updated_at"]) ||
2222
req.body.pull_request.updated_at,
2323
};
24-
await githubWebhook.updateOne(
24+
const webhook = await githubWebhook.findOneAndUpdate(
2525
{ hook_id: req.get("X-GitHub-Hook-ID") },
2626
{ $push: { events: event } }
2727
);
28+
if(webhook.events.length >= 20){
29+
await githubWebhook.updateOne(
30+
{ hook_id: req.get("X-GitHub-Hook-ID") },
31+
{ $pop: { events: -1 } }
32+
);
33+
}
2834
if (clients[req.get("X-GitHub-Hook-ID")])
2935
clients[req.get("X-GitHub-Hook-ID")].map((client) => {
3036
client.res.write(`data: ${JSON.stringify(event)}\n\n`);
3137
});
3238
return res.status(200).json({ success: true });
3339
} catch (err) {
34-
console.log(req.body);
40+
console.log(err);
3541
return res.status(500).json({ success: false, error: err });
3642
}
3743
};

0 commit comments

Comments
 (0)