diff --git a/src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs b/src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs index 027026f51..2ffef3a6f 100644 --- a/src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs +++ b/src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs @@ -11,6 +11,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Octokit; +using Credentials = Octokit.Credentials; +using Repository = LibGit2Sharp.Repository; namespace FilterLists.Agent.Extensions { @@ -25,6 +28,7 @@ public static void RegisterAgentServices(this IServiceCollection services) services.AddMediatR(AppDomain.CurrentDomain.GetAssemblies()); services.AddAgentHttpClient(); services.AddSingleton(); + services.AddGitHubClient(); services.AddSingleton(); services.AddArchiveRepository(); services.AddTransient(); @@ -77,6 +81,18 @@ private static void AddAgentHttpClient(this IServiceCollection services) }); } + private static void AddGitHubClient(this IServiceCollection services) + { + services.AddSingleton(s => + { + var gitHubSettings = s.GetService>().Value; + return new GitHubClient(new ProductHeaderValue(gitHubSettings.ProductHeaderValue)) + { + Credentials = new Credentials(gitHubSettings.PersonalAccessToken) + }; + }); + } + private static void AddArchiveRepository(this IServiceCollection services) { services.AddTransient(s => diff --git a/src/FilterLists.Agent/Infrastructure/Clients/AgentGitHubClient.cs b/src/FilterLists.Agent/Infrastructure/Clients/AgentGitHubClient.cs index 2b6aba723..b1f39a48f 100644 --- a/src/FilterLists.Agent/Infrastructure/Clients/AgentGitHubClient.cs +++ b/src/FilterLists.Agent/Infrastructure/Clients/AgentGitHubClient.cs @@ -19,21 +19,18 @@ public interface IAgentGitHubClient public class AgentGitHubClient : IAgentGitHubClient { - private readonly GitHubClient _gitHubClient; + private readonly IGitHubClient _gitHubClient; private readonly GitHubSettings _gitHubSettings; private readonly IStringLocalizer _localizer; private readonly ILogger _logger; - public AgentGitHubClient(IOptions gitHubOptions, ILogger logger, - IStringLocalizer stringLocalizer) + public AgentGitHubClient(IGitHubClient gitHubClient, IOptions gitHubOptions, + IStringLocalizer stringLocalizer, ILogger logger) { + _gitHubClient = gitHubClient; _gitHubSettings = gitHubOptions.Value; - _logger = logger; _localizer = stringLocalizer; - _gitHubClient = new GitHubClient(new ProductHeaderValue(_gitHubSettings.ProductHeaderValue)) - { - Credentials = new Credentials(_gitHubSettings.PersonalAccessToken) - }; + _logger = logger; } public async Task> GetAllIssues(RepositoryIssueRequest repositoryIssueRequest)