add: terminal tool
This commit is contained in:
34
Handlers/GiteaEventHandlers/PushEventHandler.cs
Normal file
34
Handlers/GiteaEventHandlers/PushEventHandler.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user