Skip to content

Commit

Permalink
Add handling for ping & non-create repo events
Browse files Browse the repository at this point in the history
  • Loading branch information
Bardin08 committed May 11, 2024
1 parent f0167d1 commit fbd2594
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions EduAutomation/Rest/GitHub/GitHubEndpoints.cs
Original file line number Diff line number Diff line change
@@ -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<IResult> 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();
}
Expand Down

0 comments on commit fbd2594

Please sign in to comment.