protected function execute(Input\InputInterface $input, Output\OutputInterface $output)
 {
     $this->stopwatch->start('changelog');
     $io = new SymfonyStyle($input, $output);
     $io->title('Localheinz GitHub Changelog');
     $authToken = $input->getOption('auth-token');
     if (null !== $authToken) {
         $this->client->authenticate($authToken, Client::AUTH_HTTP_TOKEN);
     }
     $owner = $input->getArgument('owner');
     $repository = $input->getArgument('repository');
     $startReference = $input->getArgument('start-reference');
     $endReference = $input->getArgument('end-reference');
     $range = $this->range($startReference, $endReference);
     $io->section(sprintf('Pull Requests for %s/%s %s', $owner, $repository, $range));
     try {
         $range = $this->pullRequestRepository->items($owner, $repository, $startReference, $endReference);
     } catch (\Exception $exception) {
         $io->error(sprintf('An error occurred: %s', $exception->getMessage()));
         return 1;
     }
     $pullRequests = $range->pullRequests();
     if (!count($pullRequests)) {
         $io->warning('Could not find any pull requests');
     } else {
         $template = $input->getOption('template');
         $pullRequests = array_reverse($pullRequests);
         array_walk($pullRequests, function (Resource\PullRequestInterface $pullRequest) use($output, $template) {
             $message = str_replace(['%title%', '%id%'], [$pullRequest->title(), $pullRequest->id()], $template);
             $output->writeln($message);
         });
         $io->newLine();
         $io->success(sprintf('Found %s pull request%s.', count($pullRequests), count($pullRequests) === 1 ? '' : 's', $range));
     }
     $event = $this->stopwatch->stop('changelog');
     $io->writeln($this->formatStopwatchEvent($event));
     return 0;
 }
 public function testItemsHandlesMergeCommitWherePullRequestWasNotFound()
 {
     $faker = $this->getFaker();
     $owner = $faker->userName;
     $repository = $faker->slug();
     $startReference = $faker->sha1;
     $endReference = $faker->sha1;
     $commitRepository = $this->getCommitRepositoryMock();
     $id = 9000;
     $mergeCommit = new Resource\Commit($faker->sha1, sprintf('Merge pull request #%s from localheinz/fix/directory', $id));
     $range = $this->getRangeMock();
     $range->expects($this->any())->method('commits')->willReturn([$mergeCommit]);
     $range->expects($this->never())->method('withPullRequest');
     $commitRepository->expects($this->once())->method('items')->with($this->equalTo($owner), $this->equalTo($repository), $this->equalTo($startReference), $this->equalTo($endReference))->willReturn($range);
     $pullRequestApi = $this->getPullRequestApiMock();
     $pullRequestApi->expects($this->once())->method('show')->with($this->equalTo($owner), $this->equalTo($repository), $this->equalTo($id))->willReturn(null);
     $pullRequestRepository = new Repository\PullRequestRepository($pullRequestApi, $commitRepository);
     $pullRequestRepository->items($owner, $repository, $startReference, $endReference);
 }