35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Nodes;
|
|
using Alchegos.Core.Services.RabbitMQ;
|
|
|
|
namespace Alchegos.Webhook.Handlers.GiteaEventHandlers;
|
|
|
|
public class PushEventHandler : IGiteaEventHandler
|
|
{
|
|
public async Task HandleAsync(JsonNode payload, IRabbitPublisher publisher)
|
|
{
|
|
string branch = payload["ref"]?.ToString()?.Replace("refs/heads/", "") ?? "";
|
|
if (branch == "main")
|
|
return;
|
|
|
|
JsonArray commits = payload["commits"]?.AsArray() ?? new JsonArray();
|
|
foreach (var commit in commits)
|
|
{
|
|
if (commit["message"]?.ToString()?.Trim() == "init")
|
|
{
|
|
Dictionary<string, string> message = new Dictionary<string, string>
|
|
{
|
|
{"repo_url", payload["repository"]?["url"]?.ToString()},
|
|
{"repo_owner", payload["repository"]?["owner"]?["login"]?.ToString()},
|
|
{"repo_name", payload["repository"]?["name"]?.ToString()}
|
|
};
|
|
await publisher.PublishAsync(
|
|
exchange: "alchegos",
|
|
routingKey:"project_initialized",
|
|
message: JsonSerializer.Serialize(message));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|