diff --git a/src/FilterLists.Agent/Features/Urls/CloseUrlValidationIssue.cs b/src/FilterLists.Agent/Features/Urls/CloseUrlValidationIssue.cs index 3c0ce3929..7dfb6be7a 100644 --- a/src/FilterLists.Agent/Features/Urls/CloseUrlValidationIssue.cs +++ b/src/FilterLists.Agent/Features/Urls/CloseUrlValidationIssue.cs @@ -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 { 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 + + "

Update:

This issue is being closed since all URLs seem to now be valid."; + await _gitHubClient.UpdateIssue(issue.Number, updateIssue); + } + + private async Task GetOpenIssueOrNull() + { + var issueRequest = new RepositoryIssueRequest + { + Filter = IssueFilter.All, + State = ItemStateFilter.Open, + Labels = {AgentBotLabel} + }; + return (await _gitHubClient.GetAllIssues(issueRequest)).FirstOrDefault(); } } }