From fbd2594641068992ef21ed300e334f982bcd2cfa Mon Sep 17 00:00:00 2001 From: Bardin08 Date: Sat, 11 May 2024 03:15:20 +0300 Subject: [PATCH] Add handling for `ping` & non-create repo events --- EduAutomation/Rest/GitHub/GitHubEndpoints.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/EduAutomation/Rest/GitHub/GitHubEndpoints.cs b/EduAutomation/Rest/GitHub/GitHubEndpoints.cs index 8cd4f96..85881fc 100644 --- a/EduAutomation/Rest/GitHub/GitHubEndpoints.cs +++ b/EduAutomation/Rest/GitHub/GitHubEndpoints.cs @@ -1,20 +1,30 @@ -using EduAutomation.Application.GitHub; -using EduAutomation.Application.GitHub.Services; -using EduAutomation.Application.Telegram; -using EduAutomation.Application.Trello; +using EduAutomation.Application.GitHub.Services; using EduAutomation.Rest.GitHub.Mappers; using EduAutomation.Rest.GitHub.Models; using Microsoft.AspNetCore.Mvc; namespace EduAutomation.Rest.GitHub; -public class GitHubEndpoints +public static class GitHubEndpoints { public static async ValueTask RepositoryCreatedWebhook( RepositoryEventPayload payload, + HttpRequest request, CancellationToken cancellationToken, [FromServices] IGitHubWebHookService webHookService) { + if (request.Headers.TryGetValue("X-GitHub-Event", out var header) && header == "ping") + { + return Results.Ok("pong"); + } + + var action = payload.Action; + if (action is not "created") + { + // don't process any repo related action except repo creation event. + return Results.NoContent(); + } + await webHookService.HandleRepoCreated(payload.ToDomainModel(), true, true); return Results.Ok(); }