-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (37 loc) · 1.99 KB
/
Program.cs
File metadata and controls
47 lines (37 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using abaci_bot.Services;
using Octokit.Webhooks;
using Octokit.Webhooks.AspNetCore;
// Load appsettings.json and environment variables
var builder = WebApplication.CreateBuilder(args);
// Validate required configuration — make sure appsettings.json exists and is filled in
var config = builder.Configuration;
var missingFields = new List<string>();
if (config.GetValue<int>("GitHubApp:AppId") == 0) missingFields.Add("GitHubApp:AppId");
if (string.IsNullOrWhiteSpace(config["GitHubApp:PrivateKey"])) missingFields.Add("GitHubApp:PrivateKey");
if (config.GetValue<long>("GitHubApp:InstallationId") == 0) missingFields.Add("GitHubApp:InstallationId");
if (string.IsNullOrWhiteSpace(config["GitHubApp:WebhookSecret"])) missingFields.Add("GitHubApp:WebhookSecret");
if (string.IsNullOrWhiteSpace(config["GitHubApp:TeamName"])) missingFields.Add("GitHubApp:TeamName");
if (missingFields.Count > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine("ERROR: The following required configuration fields are missing or empty:");
foreach (var field in missingFields)
Console.Error.WriteLine($" - {field}");
Console.Error.WriteLine();
Console.Error.WriteLine("Did you forget to create appsettings.json?");
Console.Error.WriteLine(" cp appsettings.demo.json appsettings.json");
Console.Error.WriteLine("Then fill in your GitHub App credentials.");
Console.ResetColor();
return;
}
builder.Services.AddSingleton(new GitHubService(
builder.Configuration.GetValue<int>("GitHubApp:AppId"),
builder.Configuration["GitHubApp:PrivateKey"]!,
builder.Configuration.GetValue<long>("GitHubApp:InstallationId")
));
builder.Services.AddSingleton<WebhookEventProcessor, GitHubWebhookProcessor>();
var app = builder.Build();
app.MapGitHubWebhooks("/api/webhook", config["GitHubApp:WebhookSecret"]!);
// Health check endpoint for Docker/Kubernetes
app.MapGet("/health", () => Results.Ok(new { status = "healthy", timestamp = DateTime.UtcNow }));
app.Run();