/** * @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()); }
/** * @param InputInterface $input * @param OutputInterface $output * * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { $lists = $this->rfcService->getLists([RfcService::IN_VOTING]); $rfcs = array_pop($lists); $table = new Table($output); $voteStyle = new TableStyle(); $voteStyle->setCellRowFormat('<comment>%s</comment>'); $rfcStyle = new TableStyle(); $rfcStyle->setCellRowFormat('<info>%s</info>'); foreach ($rfcs as $i => $rfcDetails) { $rfcCode = $rfcDetails[1]; // Build RFC $rfc = $this->rfcService->getRfc($rfcCode); $table->addRow([$rfcDetails[0]], $rfcStyle); $table->addRow(new TableSeparator()); foreach ($rfc->getVotes() as $title => $vote) { $table->addRow([$title], $voteStyle); array_shift($vote['counts']); foreach ($vote['counts'] as $key => $total) { $table->addRow([$key, $total]); } } if ($rfcDetails !== end($rfcs)) { $table->addRow(new TableSeparator()); } } $table->render(); }
/** * Execute Command * * @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>'); } // Get a list of RFCs using RFCService $list = $this->rfcService->getLists(array(RfcService::IN_VOTING)); // Call notify:rfc for each one in voting list $command = $this->getApplication()->find('notify:rfc'); $args = ['command' => 'notify:rfc']; foreach (reset($list) as $name => $listing) { $args['rfc'] = array_pop($listing); $inputArgs = new ArrayInput($args); $command->run($inputArgs, $output); } }
/** * @dataProvider getListsDataProvider */ public function testGetLists($sections, $expected) { // Use reflection to replace the RFC URL path $rfcFilePath = realpath(__DIR__ . '/../resources/rfcListings.html'); $reflectionClass = new \ReflectionClass($this->rfcService); $reflectionProperty = $reflectionClass->getProperty('rfcUrl'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($this->rfcService, $rfcFilePath); $this->assertSame($expected, $this->rfcService->getLists($sections)); }
/** * @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)); }
/** * Execute Command * * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $sections = ['voting' => RfcService::IN_VOTING, 'discussion' => RfcService::DISCUSSION, 'draft' => RfcService::DRAFT, 'accepted' => RfcService::ACCEPTED, 'declined' => RfcService::DECLINED, 'withdrawn' => RfcService::WITHDRAWN, 'inactive' => RfcService::INACTIVE]; $sections = array_intersect_key($sections, array_filter($input->getOptions())); if (count($sections) === 0 && !$input->getOption('all')) { $sections[] = RfcService::IN_VOTING; } $table = new Table($output); $titleStyle = new TableStyle(); $titleStyle->setCellRowFormat('<comment>%s</comment>'); $lists = $this->rfcService->getLists($sections); $table->setHeaders(['RFC', 'RFC Code']); foreach ($lists as $heading => $list) { $table->addRow([$heading], $titleStyle); $table->addRow(new TableSeparator()); foreach ($list as $listing) { $table->addRow($listing); } if ($list !== end($lists)) { $table->addRow(new TableSeparator()); } } $table->render(); }