You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Program.cs
  3. using Azure.Identity;
  4. using DevTeam.Backend.Agents;
  5. using DevTeam.Backend.Agents.Developer;
  6. using DevTeam.Backend.Agents.DeveloperLead;
  7. using DevTeam.Backend.Agents.ProductManager;
  8. using DevTeam.Backend.Services;
  9. using DevTeam.Options;
  10. using Microsoft.AutoGen.Core;
  11. using Microsoft.AutoGen.Core.Grpc;
  12. using Microsoft.Extensions.Azure;
  13. using Microsoft.Extensions.Options;
  14. using Octokit.Webhooks;
  15. using Octokit.Webhooks.AspNetCore;
  16. var builder = WebApplication.CreateBuilder(args);
  17. builder.AddServiceDefaults();
  18. builder.Services.AddHttpClient();
  19. builder.Services.AddControllers();
  20. builder.Services.AddSwaggerGen();
  21. builder.AddGrpcAgentWorker(builder.Configuration["AGENT_HOST"]!)
  22. .AddAgentWorker()
  23. .AddAgent<AzureGenie>(nameof(AzureGenie))
  24. //.AddAgent<Sandbox>(nameof(Sandbox))
  25. .AddAgent<Hubber>(nameof(Hubber))
  26. .AddAgent<Dev>(nameof(Dev))
  27. .AddAgent<ProductManager>(nameof(ProductManager))
  28. .AddAgent<DeveloperLead>(nameof(DeveloperLead));
  29. builder.Services.AddSingleton<AgentRuntime>();
  30. builder.Services.AddSingleton<WebhookEventProcessor, GithubWebHookProcessor>();
  31. builder.Services.AddSingleton<GithubAuthService>();
  32. builder.Services.AddSingleton<IManageAzure, AzureService>();
  33. builder.Services.AddSingleton<IManageGithub, GithubService>();
  34. builder.Services.AddTransient(s =>
  35. {
  36. var ghOptions = s.GetRequiredService<IOptions<GithubOptions>>();
  37. var logger = s.GetRequiredService<ILogger<GithubAuthService>>();
  38. var ghService = new GithubAuthService(ghOptions, logger);
  39. var client = ghService.GetGitHubClient();
  40. return client;
  41. });
  42. // TODO: Rework?
  43. builder.Services.AddOptions<GithubOptions>()
  44. .Configure<IConfiguration>((settings, configuration) =>
  45. {
  46. configuration.GetSection("Github").Bind(settings);
  47. })
  48. .ValidateDataAnnotations()
  49. .ValidateOnStart();
  50. builder.Services.AddAzureClients(clientBuilder =>
  51. {
  52. clientBuilder.AddArmClient(default);
  53. clientBuilder.UseCredential(new DefaultAzureCredential());
  54. });
  55. var app = builder.Build();
  56. Microsoft.Extensions.Hosting.AspireHostingExtensions.MapDefaultEndpoints(app);
  57. app.UseRouting()
  58. .UseEndpoints(endpoints =>
  59. {
  60. var ghOptions = app.Services.GetRequiredService<IOptions<GithubOptions>>().Value;
  61. endpoints.MapGitHubWebhooks(secret: ghOptions.WebhookSecret);
  62. }); ;
  63. app.UseSwagger();
  64. /* app.UseSwaggerUI(c =>
  65. {
  66. c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
  67. }); */
  68. app.Run();