diff --git a/src/FilterLists.Agent/Core/IGitHubIssuesRepository.cs b/src/FilterLists.Agent/Core/GitHub/IIssuesRepository.cs similarity index 81% rename from src/FilterLists.Agent/Core/IGitHubIssuesRepository.cs rename to src/FilterLists.Agent/Core/GitHub/IIssuesRepository.cs index 48a89b13f..f734b3683 100644 --- a/src/FilterLists.Agent/Core/IGitHubIssuesRepository.cs +++ b/src/FilterLists.Agent/Core/GitHub/IIssuesRepository.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using Octokit; -namespace FilterLists.Agent.Core +namespace FilterLists.Agent.Core.GitHub { - public interface IGitHubIssuesRepository + public interface IIssuesRepository { Task> GetAllIssuesAsync(RepositoryIssueRequest repositoryIssueRequest); diff --git a/src/FilterLists.Agent/Features/Urls/CloseUrlValidationIssue.cs b/src/FilterLists.Agent/Features/Urls/CloseUrlValidationIssue.cs index c5b7f2835..30b302720 100644 --- a/src/FilterLists.Agent/Features/Urls/CloseUrlValidationIssue.cs +++ b/src/FilterLists.Agent/Features/Urls/CloseUrlValidationIssue.cs @@ -1,6 +1,6 @@ using System.Threading; using System.Threading.Tasks; -using FilterLists.Agent.Core; +using FilterLists.Agent.Core.GitHub; using FilterLists.Agent.Extensions; using MediatR; using Octokit; @@ -16,11 +16,11 @@ public class Command : IRequest public class Handler : AsyncRequestHandler { private const string AgentBotLabel = "agent bot"; - private readonly IGitHubIssuesRepository _repo; + private readonly IIssuesRepository _repo; - public Handler(IGitHubIssuesRepository gitHubIssuesRepository) + public Handler(IIssuesRepository issuesRepository) { - _repo = gitHubIssuesRepository; + _repo = issuesRepository; } protected override async Task Handle(Command request, CancellationToken cancellationToken) diff --git a/src/FilterLists.Agent/Features/Urls/CreateOrUpdateUrlValidationIssue.cs b/src/FilterLists.Agent/Features/Urls/CreateOrUpdateUrlValidationIssue.cs index 185be8958..1586515c2 100644 --- a/src/FilterLists.Agent/Features/Urls/CreateOrUpdateUrlValidationIssue.cs +++ b/src/FilterLists.Agent/Features/Urls/CreateOrUpdateUrlValidationIssue.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using FilterLists.Agent.Core; +using FilterLists.Agent.Core.GitHub; using FilterLists.Agent.Extensions; using FilterLists.Agent.Features.Urls.Models.ValidationResults; using MediatR; @@ -27,12 +27,12 @@ public class Handler : AsyncRequestHandler private const string HelpWantedLabel = "help wanted"; private const string DataLabel = "data"; private const string IssueTitle = "BOT: url validation errors"; - private readonly IGitHubIssuesRepository _repo; private readonly IMediator _mediator; + private readonly IIssuesRepository _repo; - public Handler(IGitHubIssuesRepository gitHubIssuesRepository, IMediator mediator) + public Handler(IIssuesRepository issuesRepository, IMediator mediator) { - _repo = gitHubIssuesRepository; + _repo = issuesRepository; _mediator = mediator; } diff --git a/src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs b/src/FilterLists.Agent/Infrastructure/DependencyInjection/ServiceCollectionExtensions.cs similarity index 73% rename from src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs rename to src/FilterLists.Agent/Infrastructure/DependencyInjection/ServiceCollectionExtensions.cs index a19f0267d..170ac9f63 100644 --- a/src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs +++ b/src/FilterLists.Agent/Infrastructure/DependencyInjection/ServiceCollectionExtensions.cs @@ -4,21 +4,17 @@ using CommandLine; using FilterLists.Agent.AppSettings; using FilterLists.Agent.Core; -using FilterLists.Agent.Core.ListInfo; -using FilterLists.Agent.Infrastructure.Repositories; +using FilterLists.Agent.Infrastructure.FilterListsApi; +using FilterLists.Agent.Infrastructure.GitHub; using LibGit2Sharp; using MediatR; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Octokit; using Polly; -using RestSharp; -using Credentials = Octokit.Credentials; -using Repository = LibGit2Sharp.Repository; -namespace FilterLists.Agent.Extensions +namespace FilterLists.Agent.Infrastructure.DependencyInjection { public static class ServiceCollectionExtensions { @@ -29,13 +25,11 @@ public static void RegisterAgentServices(this IServiceCollection services) services.AddLocalization(); services.AddTransient(); services.AddMediatR(AppDomain.CurrentDomain.GetAssemblies()); - services.AddApiClient(); - services.AddGitHubClient(); + services.AddFilterListsApiResources(); + services.AddGitHubResources(); services.AddUrlRepository(); services.AddListRepository(); services.AddArchiveRepository(); - services.AddTransient(); - services.AddTransient(); } private static void AddConfiguration(this IServiceCollection services) @@ -72,27 +66,6 @@ private static void AddLoggingCustom(this IServiceCollection services) }); } - private static void AddApiClient(this IServiceCollection services) - { - services.AddSingleton(b => - { - var filterListsApiSettings = b.GetService>().Value; - return new RestClient(filterListsApiSettings.BaseUrl) {UserAgent = "FilterLists.Agent"}; - }); - } - - 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 AddUrlRepository(this IServiceCollection services) { services.AddHttpClient() diff --git a/src/FilterLists.Agent/Infrastructure/Repositories/ListInfoRepository.cs b/src/FilterLists.Agent/Infrastructure/FilterListsApi/ListInfoRepository.cs similarity index 95% rename from src/FilterLists.Agent/Infrastructure/Repositories/ListInfoRepository.cs rename to src/FilterLists.Agent/Infrastructure/FilterListsApi/ListInfoRepository.cs index 10a5f4bec..ce51c3bf1 100644 --- a/src/FilterLists.Agent/Infrastructure/Repositories/ListInfoRepository.cs +++ b/src/FilterLists.Agent/Infrastructure/FilterListsApi/ListInfoRepository.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Logging; using RestSharp; -namespace FilterLists.Agent.Infrastructure.Repositories +namespace FilterLists.Agent.Infrastructure.FilterListsApi { public class ListInfoRepository : IListInfoRepository { diff --git a/src/FilterLists.Agent/Infrastructure/FilterListsApi/ServiceCollectionExtensions.cs b/src/FilterLists.Agent/Infrastructure/FilterListsApi/ServiceCollectionExtensions.cs new file mode 100644 index 000000000..916b16bc5 --- /dev/null +++ b/src/FilterLists.Agent/Infrastructure/FilterListsApi/ServiceCollectionExtensions.cs @@ -0,0 +1,21 @@ +using FilterLists.Agent.AppSettings; +using FilterLists.Agent.Core.ListInfo; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using RestSharp; + +namespace FilterLists.Agent.Infrastructure.FilterListsApi +{ + public static class ServiceCollectionExtensions + { + public static void AddFilterListsApiResources(this IServiceCollection services) + { + services.AddSingleton(b => + { + var filterListsApiSettings = b.GetService>().Value; + return new RestClient(filterListsApiSettings.BaseUrl) {UserAgent = "FilterLists.Agent"}; + }); + services.AddTransient(); + } + } +} \ No newline at end of file diff --git a/src/FilterLists.Agent/Infrastructure/Repositories/GitHubIssuesRepository.cs b/src/FilterLists.Agent/Infrastructure/GitHub/IssuesRepository.cs similarity index 80% rename from src/FilterLists.Agent/Infrastructure/Repositories/GitHubIssuesRepository.cs rename to src/FilterLists.Agent/Infrastructure/GitHub/IssuesRepository.cs index 24e655f7b..7adb160c5 100644 --- a/src/FilterLists.Agent/Infrastructure/Repositories/GitHubIssuesRepository.cs +++ b/src/FilterLists.Agent/Infrastructure/GitHub/IssuesRepository.cs @@ -1,23 +1,23 @@ using System.Collections.Generic; using System.Threading.Tasks; using FilterLists.Agent.AppSettings; -using FilterLists.Agent.Core; +using FilterLists.Agent.Core.GitHub; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Octokit; -namespace FilterLists.Agent.Infrastructure.Repositories +namespace FilterLists.Agent.Infrastructure.GitHub { - public class GitHubIssuesRepository : IGitHubIssuesRepository + public class IssuesRepository : IIssuesRepository { private readonly IGitHubClient _gitHubClient; private readonly GitHubSettings _gitHubSettings; - private readonly IStringLocalizer _localizer; - private readonly ILogger _logger; + private readonly IStringLocalizer _localizer; + private readonly ILogger _logger; - public GitHubIssuesRepository(IGitHubClient gitHubClient, IOptions gitHubOptions, - IStringLocalizer stringLocalizer, ILogger logger) + public IssuesRepository(IGitHubClient gitHubClient, IOptions gitHubOptions, + IStringLocalizer stringLocalizer, ILogger logger) { _gitHubClient = gitHubClient; _gitHubSettings = gitHubOptions.Value; diff --git a/src/FilterLists.Agent/Infrastructure/GitHub/ServiceCollectionExtensions.cs b/src/FilterLists.Agent/Infrastructure/GitHub/ServiceCollectionExtensions.cs new file mode 100644 index 000000000..b9e8389d6 --- /dev/null +++ b/src/FilterLists.Agent/Infrastructure/GitHub/ServiceCollectionExtensions.cs @@ -0,0 +1,24 @@ +using FilterLists.Agent.AppSettings; +using FilterLists.Agent.Core.GitHub; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using Octokit; + +namespace FilterLists.Agent.Infrastructure.GitHub +{ + public static class ServiceCollectionExtensions + { + public static void AddGitHubResources(this IServiceCollection services) + { + services.AddSingleton(s => + { + var gitHubSettings = s.GetService>().Value; + return new GitHubClient(new ProductHeaderValue(gitHubSettings.ProductHeaderValue)) + { + Credentials = new Credentials(gitHubSettings.PersonalAccessToken) + }; + }); + services.AddTransient(); + } + } +} \ No newline at end of file diff --git a/src/FilterLists.Agent/Infrastructure/Repositories/ListRepository.cs b/src/FilterLists.Agent/Infrastructure/ListRepository.cs similarity index 91% rename from src/FilterLists.Agent/Infrastructure/Repositories/ListRepository.cs rename to src/FilterLists.Agent/Infrastructure/ListRepository.cs index fd8c9dc6c..3aed139c7 100644 --- a/src/FilterLists.Agent/Infrastructure/Repositories/ListRepository.cs +++ b/src/FilterLists.Agent/Infrastructure/ListRepository.cs @@ -4,7 +4,7 @@ using FilterLists.Agent.Core; using JetBrains.Annotations; -namespace FilterLists.Agent.Infrastructure.Repositories +namespace FilterLists.Agent.Infrastructure { [UsedImplicitly] public class ListRepository : IListRepository diff --git a/src/FilterLists.Agent/Infrastructure/Repositories/UrlRepository.cs b/src/FilterLists.Agent/Infrastructure/UrlRepository.cs similarity index 99% rename from src/FilterLists.Agent/Infrastructure/Repositories/UrlRepository.cs rename to src/FilterLists.Agent/Infrastructure/UrlRepository.cs index 6c8bd890a..f6afeff49 100644 --- a/src/FilterLists.Agent/Infrastructure/Repositories/UrlRepository.cs +++ b/src/FilterLists.Agent/Infrastructure/UrlRepository.cs @@ -15,7 +15,7 @@ using Microsoft.Extensions.Logging; using RestSharp; -namespace FilterLists.Agent.Infrastructure.Repositories +namespace FilterLists.Agent.Infrastructure { [UsedImplicitly] public class UrlRepository : IUrlRepository diff --git a/src/FilterLists.Agent/Program.cs b/src/FilterLists.Agent/Program.cs index 3899c3b8a..ca1d562b6 100644 --- a/src/FilterLists.Agent/Program.cs +++ b/src/FilterLists.Agent/Program.cs @@ -1,9 +1,9 @@ using System; using System.Threading.Tasks; using CommandLine; -using FilterLists.Agent.Extensions; using FilterLists.Agent.Features.Lists; using FilterLists.Agent.Features.Urls; +using FilterLists.Agent.Infrastructure.DependencyInjection; using MediatR; using Microsoft.Extensions.DependencyInjection;