Skip to content

Commit

Permalink
Ignore bots when processing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Sep 26, 2024
1 parent b3c8339 commit 65c6ccc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Web/Webhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;

}

0 comments on commit 65c6ccc

Please sign in to comment.