initial impl of CloseUrlValidationIssue

This commit is contained in:
Collin M. Barrett 2019-07-02 15:29:30 -05:00
parent b51039d6f1
commit db25be46ec

View file

@ -1,7 +1,9 @@
using System.Threading;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FilterLists.Agent.Infrastructure.Clients;
using MediatR;
using Octokit;
namespace FilterLists.Agent.Features.Urls
{
@ -14,7 +16,6 @@ public class Command : IRequest
public class Handler : AsyncRequestHandler<Command>
{
private const string AgentBotLabel = "agent bot";
private const string IssueTitle = "Url Validation Errors";
private readonly IAgentGitHubClient _gitHubClient;
public Handler(IAgentGitHubClient agentGitHubClient)
@ -24,6 +25,25 @@ public Handler(IAgentGitHubClient agentGitHubClient)
protected override async Task Handle(Command request, CancellationToken cancellationToken)
{
var issue = await GetOpenIssueOrNull();
if (issue is null)
return;
var updateIssue = issue.ToUpdate();
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.UpdateIssue(issue.Number, updateIssue);
}
private async Task<Issue> GetOpenIssueOrNull()
{
var issueRequest = new RepositoryIssueRequest
{
Filter = IssueFilter.All,
State = ItemStateFilter.Open,
Labels = {AgentBotLabel}
};
return (await _gitHubClient.GetAllIssues(issueRequest)).FirstOrDefault();
}
}
}