|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Command; |
| 4 | + |
| 5 | +use App\Api\Issue\IssueApi; |
| 6 | +use App\Service\RepositoryProvider; |
| 7 | +use Symfony\Component\Console\Command\Command; |
| 8 | +use Symfony\Component\Console\Input\InputArgument; |
| 9 | +use Symfony\Component\Console\Input\InputInterface; |
| 10 | +use Symfony\Component\Console\Output\OutputInterface; |
| 11 | + |
| 12 | +/** |
| 13 | + * Close issues not been updated in a long while |
| 14 | + * |
| 15 | + * @author Tobias Nyholm <tobias.nyholm@gmail.com> |
| 16 | + */ |
| 17 | +class CloseStaleIssuesCommand extends Command |
| 18 | +{ |
| 19 | + protected static $defaultName = 'app:issue:close-stale'; |
| 20 | + private $repositoryProvider; |
| 21 | + private $issueApi; |
| 22 | + |
| 23 | + public function __construct(RepositoryProvider $repositoryProvider, IssueApi $issueApi) |
| 24 | + { |
| 25 | + parent::__construct(); |
| 26 | + $this->repositoryProvider = $repositoryProvider; |
| 27 | + $this->issueApi = $issueApi; |
| 28 | + } |
| 29 | + |
| 30 | + protected function configure() |
| 31 | + { |
| 32 | + $this->addArgument('repository', InputArgument::REQUIRED, 'The full name to the repository, eg symfony/symfony-docs'); |
| 33 | + } |
| 34 | + |
| 35 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 36 | + { |
| 37 | + /** @var string $repositoryName */ |
| 38 | + $repositoryName = $input->getArgument('repository'); |
| 39 | + $repository = $this->repositoryProvider->getRepository($repositoryName); |
| 40 | + if (null === $repository) { |
| 41 | + $output->writeln('Repository not configured'); |
| 42 | + return 1; |
| 43 | + } |
| 44 | + |
| 45 | + $notUpdatedAfter = new \DateTimeImmutable('-3months'); |
| 46 | + $issues = $this->issueApi->findStaleIssues($repository, $notUpdatedAfter); |
| 47 | + |
| 48 | + foreach ($issues as $issue) { |
| 49 | + $this->issueApi->commentOnIssue($repository, $issue['number'], <<<TXT |
| 50 | +Hey, |
| 51 | +
|
| 52 | +Is this issue still relevant? It has not been any activity in a while. I will close this if nobody makes a comment soon. |
| 53 | +
|
| 54 | +Cheers! |
| 55 | +
|
| 56 | +Carsonbot |
| 57 | +TXT |
| 58 | +); |
| 59 | + |
| 60 | + // TODO add a scheduled task to process this issue again after 2 weeks |
| 61 | + } |
| 62 | + |
| 63 | + return 0; |
| 64 | + } |
| 65 | +} |
0 commit comments