/** * @param string $rfcCode */ public function notify($rfcCode) { $oldRfcPath = sprintf('%s/%s.html', $this->config->get('storagePath'), $rfcCode); try { // Build current RFC $currentRfc = $this->rfcService->getRfc($rfcCode); } catch (\InvalidArgumentException $e) { throw new \RuntimeException('Invalid RFC code, check rfc:list for valid codes'); } if (!file_exists($oldRfcPath)) { file_put_contents($oldRfcPath, $currentRfc->getRawContent()); $oldRfc = new \MikeyMike\RfcDigestor\Entity\Rfc(); } else { try { // Get oldRfc $oldRfc = $this->rfcService->getRfcFromStorage($rfcCode); } catch (\InvalidArgumentException $e) { throw new \RuntimeException($e->getMessage()); } } // Get diffs $diffs = $this->diffService->rfcDiff($currentRfc, $oldRfc); // Only send email if we have diffs if (count(array_filter($diffs)) === 0) { return; } foreach ($this->notifiers as $notifier) { $notifier->notify($currentRfc, $diffs); } file_put_contents($oldRfcPath, $currentRfc->getRawContent()); }
/** * @dataProvider rfcDiffDataProvider */ public function testRfcDiffReturnsCorrectDiff($details, $changeLogs, $votes, $expectedDiff) { $rfc1 = new Rfc(); $rfc2 = new Rfc(); $rfc1->setDetails($details[0]); $rfc1->setChangeLog($changeLogs[0]); $rfc1->setVotes($votes[0]); $rfc2->setDetails($details[1]); $rfc2->setChangeLog($changeLogs[1]); $rfc2->setVotes($votes[1]); $this->assertSame($expectedDiff, $this->diffService->rfcDiff($rfc1, $rfc2)); }
/** * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { if (posix_isatty(STDOUT)) { $output->writeln('<info>щ(ºДºщ) This command is pointless when not run on a cron</info>'); } $currRfcList = $this->rfcService->getLists(); $storageFile = sprintf('%s/rfcList.json', $this->config->get('storagePath')); if (!file_exists($storageFile)) { file_put_contents($storageFile, json_encode($currRfcList)); return; } $prevRfcList = json_decode(file_get_contents($storageFile), true); $diffs = $this->diffService->listDiff($currRfcList, $prevRfcList); if (empty($diffs)) { file_put_contents($storageFile, json_encode($currRfcList)); return; } $email = $this->twig->render('list.twig', ['changes' => $diffs]); $message = $this->mailer->createMessage()->setSubject('Some RFCs have moved!')->setFrom('*****@*****.**')->setTo($input->getArgument('email'))->setBody($email, 'text/html'); $this->mailer->send($message); file_put_contents($storageFile, json_encode($currRfcList)); }