From 65c6cccf300503aad9c9c9f4a08bd2bc4d3a6d20 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Thu, 26 Sep 2024 19:11:02 -0300 Subject: [PATCH] Ignore bots when processing comments --- src/Web/Webhook.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Web/Webhook.cs b/src/Web/Webhook.cs index c9e9b50b..80825385 100644 --- a/src/Web/Webhook.cs +++ b/src/Web/Webhook.cs @@ -8,6 +8,7 @@ using Octokit.Webhooks.Events.IssueComment; using Octokit.Webhooks.Events.Issues; using Octokit.Webhooks.Events.Sponsorship; +using Octokit.Webhooks.Models; namespace Devlooped.Sponsors; @@ -38,6 +39,10 @@ protected override async Task ProcessIssueCommentWebhookAsync(WebhookHeaders hea // It was not an issue or it was not found. return; + if (IsBot(payload.Sender)) + // Ignore comments from bots. + return; + try { using var activity = tracer.StartActivity("IssueComment"); @@ -81,6 +86,10 @@ protected override async Task ProcessIssuesWebhookAsync(WebhookHeaders headers, // It was not an issue or it was not found. return; + if (IsBot(payload.Sender)) + // Ignore comments from bots. + return; + try { using var activity = tracer.StartActivity("Issue"); @@ -170,4 +179,9 @@ await notifier.PostAsync(new PushoverMessage throw; } } + + static bool IsBot(Octokit.Webhooks.Models.User? user) => user?.Type == UserType.Bot || + user?.Login.EndsWith("-bot") == true || + user?.Name?.EndsWith("bot]") == true || user?.Name?.EndsWith("-bot") == true; + }