add: terminal tool
This commit is contained in:
49
Handlers/GiteaEventHandlers/PullRequestEventHandler.cs
Normal file
49
Handlers/GiteaEventHandlers/PullRequestEventHandler.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Alchegos.Core.Services.RabbitMQ;
|
||||
|
||||
namespace Alchegos.Webhook.Handlers.GiteaEventHandlers;
|
||||
|
||||
public class PullRequestEventHandler : IGiteaEventHandler
|
||||
{
|
||||
public async Task HandleAsync(JsonNode payload, IRabbitPublisher publisher)
|
||||
{
|
||||
string action = payload["action"]?.ToString() ?? "";
|
||||
string repo_url = payload["repository"]?["url"]?.ToString();
|
||||
string repo_owner = payload["repository"]?["owner"]?["login"]?.ToString();
|
||||
string repo_name = payload["repository"]?["name"]?.ToString();
|
||||
string branch = payload["pull_request"]?["head"]?["ref"]?.ToString();
|
||||
|
||||
JsonArray labels = payload["pull_request"]?["labels"]?.AsArray() ?? new JsonArray();
|
||||
|
||||
Dictionary<string, string> routingKeys = new Dictionary<string, string>
|
||||
{
|
||||
{"status/pending_review", "pull_request_pending_review"},
|
||||
{"status/pending_test", "pull_request_pending_test"}
|
||||
};
|
||||
|
||||
if (action is "opened" or "label_updated")
|
||||
{
|
||||
foreach (JsonNode label in labels)
|
||||
{
|
||||
string labelName = label["name"]?.ToString().Trim() ?? label.ToString().Trim();
|
||||
if (routingKeys.TryGetValue(labelName, out string routingKey))
|
||||
{
|
||||
Dictionary<string, string> message = new Dictionary<string, string>
|
||||
{
|
||||
{"repo_url", repo_url},
|
||||
{"repo_owner", repo_owner},
|
||||
{"repo_name", repo_name},
|
||||
{"branch", branch}
|
||||
};
|
||||
await publisher.PublishAsync(
|
||||
exchange: "alchegos",
|
||||
routingKey: routingKey,
|
||||
message: JsonSerializer.Serialize(message)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user