From 737149d98eaef3acadd1ce839abb85b0b5c04b0a Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Sat, 6 Jul 2019 15:40:56 -0500 Subject: [PATCH] convert AgentGitHubClient to transient GitHubIssuesRepository --- .../IGitHubIssuesRepository.cs} | 4 ++-- .../Extensions/ServiceCollectionExtensions.cs | 2 +- .../Features/Urls/CloseUrlValidationIssue.cs | 12 ++++++------ .../Urls/CreateOrUpdateUrlValidationIssue.cs | 14 +++++++------- .../GitHubIssuesRepository.cs} | 14 +++++++------- 5 files changed, 23 insertions(+), 23 deletions(-) rename src/FilterLists.Agent/Core/Interfaces/{Clients/IAgentGitHubClient.cs => Repositories/IGitHubIssuesRepository.cs} (76%) rename src/FilterLists.Agent/Infrastructure/{Clients/AgentGitHubClient.cs => Repositories/GitHubIssuesRepository.cs} (79%) diff --git a/src/FilterLists.Agent/Core/Interfaces/Clients/IAgentGitHubClient.cs b/src/FilterLists.Agent/Core/Interfaces/Repositories/IGitHubIssuesRepository.cs similarity index 76% rename from src/FilterLists.Agent/Core/Interfaces/Clients/IAgentGitHubClient.cs rename to src/FilterLists.Agent/Core/Interfaces/Repositories/IGitHubIssuesRepository.cs index b78704d59..f199e7035 100644 --- a/src/FilterLists.Agent/Core/Interfaces/Clients/IAgentGitHubClient.cs +++ b/src/FilterLists.Agent/Core/Interfaces/Repositories/IGitHubIssuesRepository.cs @@ -2,9 +2,9 @@ using System.Threading.Tasks; using Octokit; -namespace FilterLists.Agent.Core.Interfaces.Clients +namespace FilterLists.Agent.Core.Interfaces.Repositories { - public interface IAgentGitHubClient + public interface IGitHubIssuesRepository { Task> GetAllIssuesAsync(RepositoryIssueRequest repositoryIssueRequest); diff --git a/src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs b/src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs index 04bdd59c7..27a50faf3 100644 --- a/src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs +++ b/src/FilterLists.Agent/Extensions/ServiceCollectionExtensions.cs @@ -30,10 +30,10 @@ public static void RegisterAgentServices(this IServiceCollection services) services.AddAgentHttpClient(); services.AddSingleton(); services.AddGitHubClient(); - services.AddSingleton(); services.AddArchiveRepository(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } private static void AddConfiguration(this IServiceCollection services) diff --git a/src/FilterLists.Agent/Features/Urls/CloseUrlValidationIssue.cs b/src/FilterLists.Agent/Features/Urls/CloseUrlValidationIssue.cs index 9f67fbe11..93225c5bd 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.Interfaces.Clients; +using FilterLists.Agent.Core.Interfaces.Repositories; 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 IAgentGitHubClient _gitHubClient; + private readonly IGitHubIssuesRepository _repo; - public Handler(IAgentGitHubClient agentGitHubClient) + public Handler(IGitHubIssuesRepository gitHubIssuesRepository) { - _gitHubClient = agentGitHubClient; + _repo = gitHubIssuesRepository; } protected override async Task Handle(Command request, CancellationToken cancellationToken) @@ -32,7 +32,7 @@ protected override async Task Handle(Command request, CancellationToken cancella updateIssue.State = ItemState.Closed; updateIssue.Body = issue.Body + "

Update:

This issue is being closed since all URLs seem to now be valid."; - await _gitHubClient.UpdateIssueAsync(issue.Number, updateIssue); + await _repo.UpdateIssueAsync(issue.Number, updateIssue); } private async Task GetOpenIssueOrNull() @@ -43,7 +43,7 @@ private async Task GetOpenIssueOrNull() State = ItemStateFilter.Open, Labels = {AgentBotLabel} }; - return (await _gitHubClient.GetAllIssuesAsync(issueRequest)).FirstOrDefault(); + return (await _repo.GetAllIssuesAsync(issueRequest)).FirstOrDefault(); } } } diff --git a/src/FilterLists.Agent/Features/Urls/CreateOrUpdateUrlValidationIssue.cs b/src/FilterLists.Agent/Features/Urls/CreateOrUpdateUrlValidationIssue.cs index 377e34e02..95a8507cd 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.Interfaces.Clients; +using FilterLists.Agent.Core.Interfaces.Repositories; 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 IAgentGitHubClient _gitHubClient; + private readonly IGitHubIssuesRepository _repo; private readonly IMediator _mediator; - public Handler(IAgentGitHubClient agentGitHubClient, IMediator mediator) + public Handler(IGitHubIssuesRepository gitHubIssuesRepository, IMediator mediator) { - _gitHubClient = agentGitHubClient; + _repo = gitHubIssuesRepository; _mediator = mediator; } @@ -50,13 +50,13 @@ private async Task GetOpenIssueOrNull() State = ItemStateFilter.Open, Labels = {AgentBotLabel} }; - return (await _gitHubClient.GetAllIssuesAsync(issueRequest)).FirstOrDefault(); + return (await _repo.GetAllIssuesAsync(issueRequest)).FirstOrDefault(); } private async Task CreateBaseIssue() { var newIssue = new NewIssue(IssueTitle); - return await _gitHubClient.CreateIssueAsync(newIssue); + return await _repo.CreateIssueAsync(newIssue); } private async Task UpdateIssue(Issue issue, @@ -69,7 +69,7 @@ private async Task UpdateIssue(Issue issue, updateIssue.AddLabel(DataLabel); updateIssue.Body = await _mediator.Send(new BuildGitHubIssueBody.Command(dataFileUrlValidationResults), cancellationToken); - await _gitHubClient.UpdateIssueAsync(issue.Number, updateIssue); + await _repo.UpdateIssueAsync(issue.Number, updateIssue); } } } diff --git a/src/FilterLists.Agent/Infrastructure/Clients/AgentGitHubClient.cs b/src/FilterLists.Agent/Infrastructure/Repositories/GitHubIssuesRepository.cs similarity index 79% rename from src/FilterLists.Agent/Infrastructure/Clients/AgentGitHubClient.cs rename to src/FilterLists.Agent/Infrastructure/Repositories/GitHubIssuesRepository.cs index 13a94c635..6a02d5f00 100644 --- a/src/FilterLists.Agent/Infrastructure/Clients/AgentGitHubClient.cs +++ b/src/FilterLists.Agent/Infrastructure/Repositories/GitHubIssuesRepository.cs @@ -1,23 +1,23 @@ using System.Collections.Generic; using System.Threading.Tasks; using FilterLists.Agent.AppSettings; -using FilterLists.Agent.Core.Interfaces.Clients; +using FilterLists.Agent.Core.Interfaces.Repositories; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Octokit; -namespace FilterLists.Agent.Infrastructure.Clients +namespace FilterLists.Agent.Infrastructure.Repositories { - public class AgentGitHubClient : IAgentGitHubClient + public class GitHubIssuesRepository : IGitHubIssuesRepository { 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 AgentGitHubClient(IGitHubClient gitHubClient, IOptions gitHubOptions, - IStringLocalizer stringLocalizer, ILogger logger) + public GitHubIssuesRepository(IGitHubClient gitHubClient, IOptions gitHubOptions, + IStringLocalizer stringLocalizer, ILogger logger) { _gitHubClient = gitHubClient; _gitHubSettings = gitHubOptions.Value;