refactor: web hook
This commit is contained in:
32
Handlers/ProjectPlanEventHandler.cs
Normal file
32
Handlers/ProjectPlanEventHandler.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Alchegos.Core.Services.RabbitMQ;
|
||||
|
||||
namespace Alchegos.Gitea.Webhook.Handlers;
|
||||
|
||||
public class ProjectPlanEventHandler : IGiteaEventHandler
|
||||
{
|
||||
public async Task HandleAsync(JsonNode payload, IRabbitPublisher publisher)
|
||||
{
|
||||
string projectName = payload["title"]?.ToString();
|
||||
string action = payload["action"]?.ToString();
|
||||
string plan = payload["content"]?.ToString();
|
||||
|
||||
Dictionary<string, string> routingKeys = new Dictionary<string, string>
|
||||
{
|
||||
{"create", "new_project_plan_created"},
|
||||
{"update", "project_plan_updated"},
|
||||
};
|
||||
|
||||
Dictionary<string, string> message = new()
|
||||
{
|
||||
{ "project_name", projectName },
|
||||
{ "project_plan", plan }
|
||||
};
|
||||
await publisher.PublishAsync(
|
||||
exchange: "alchegos",
|
||||
routingKey: routingKeys.GetValueOrDefault(action, ""),
|
||||
message: JsonSerializer.Serialize(message)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user