refactor: web hook
This commit is contained in:
25
GiteaEventDispatcher.cs
Normal file
25
GiteaEventDispatcher.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Alchegos.Core.Services.RabbitMQ;
|
||||
using Alchegos.Gitea.Webhook.Handlers;
|
||||
|
||||
namespace Alchegos.Gitea.Webhook;
|
||||
|
||||
public class GiteaEventDispatcher
|
||||
{
|
||||
private Dictionary<string, IGiteaEventHandler> Handlers { get; set; } = new (StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{"push", new PushEventHandler()},
|
||||
{"issues", new IssuesEventHandler()},
|
||||
{"issue_comment", new IssueCommentEventHandler()},
|
||||
{"pull_request", new PullRequestEventHandler()}
|
||||
};
|
||||
|
||||
|
||||
public async Task DispatchAsync(string eventType, JsonNode payload, IRabbitPublisher publisher)
|
||||
{
|
||||
if (Handlers.TryGetValue(eventType, out var handler))
|
||||
{
|
||||
await handler.HandleAsync(payload, publisher);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user