mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
convert AgentGitHubClient to transient GitHubIssuesRepository
This commit is contained in:
parent
5c22d9fd44
commit
737149d98e
5 changed files with 23 additions and 23 deletions
|
|
@ -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<IReadOnlyList<Issue>> GetAllIssuesAsync(RepositoryIssueRequest repositoryIssueRequest);
|
||||
|
||||
|
|
@ -30,10 +30,10 @@ public static void RegisterAgentServices(this IServiceCollection services)
|
|||
services.AddAgentHttpClient();
|
||||
services.AddSingleton<IFilterListsApiClient, FilterListsApiClient>();
|
||||
services.AddGitHubClient();
|
||||
services.AddSingleton<IAgentGitHubClient, AgentGitHubClient>();
|
||||
services.AddArchiveRepository();
|
||||
services.AddTransient<IListInfoRepository, ListInfoRepository>();
|
||||
services.AddTransient<IUrlRepository, UrlRepository>();
|
||||
services.AddTransient<IGitHubIssuesRepository, GitHubIssuesRepository>();
|
||||
}
|
||||
|
||||
private static void AddConfiguration(this IServiceCollection services)
|
||||
|
|
|
|||
|
|
@ -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<Command>
|
||||
{
|
||||
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 +
|
||||
"<h1>Update:</h1>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<Issue> GetOpenIssueOrNull()
|
||||
|
|
@ -43,7 +43,7 @@ private async Task<Issue> GetOpenIssueOrNull()
|
|||
State = ItemStateFilter.Open,
|
||||
Labels = {AgentBotLabel}
|
||||
};
|
||||
return (await _gitHubClient.GetAllIssuesAsync(issueRequest)).FirstOrDefault();
|
||||
return (await _repo.GetAllIssuesAsync(issueRequest)).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Command>
|
|||
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<Issue> GetOpenIssueOrNull()
|
|||
State = ItemStateFilter.Open,
|
||||
Labels = {AgentBotLabel}
|
||||
};
|
||||
return (await _gitHubClient.GetAllIssuesAsync(issueRequest)).FirstOrDefault();
|
||||
return (await _repo.GetAllIssuesAsync(issueRequest)).FirstOrDefault();
|
||||
}
|
||||
|
||||
private async Task<Issue> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<AgentGitHubClient> _localizer;
|
||||
private readonly ILogger<AgentGitHubClient> _logger;
|
||||
private readonly IStringLocalizer<GitHubIssuesRepository> _localizer;
|
||||
private readonly ILogger<GitHubIssuesRepository> _logger;
|
||||
|
||||
public AgentGitHubClient(IGitHubClient gitHubClient, IOptions<GitHubSettings> gitHubOptions,
|
||||
IStringLocalizer<AgentGitHubClient> stringLocalizer, ILogger<AgentGitHubClient> logger)
|
||||
public GitHubIssuesRepository(IGitHubClient gitHubClient, IOptions<GitHubSettings> gitHubOptions,
|
||||
IStringLocalizer<GitHubIssuesRepository> stringLocalizer, ILogger<GitHubIssuesRepository> logger)
|
||||
{
|
||||
_gitHubClient = gitHubClient;
|
||||
_gitHubSettings = gitHubOptions.Value;
|
||||
Loading…
Reference in a new issue