From a860637a0bffdd77369c31fc28ce99f028585681 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 27 Mar 2017 17:26:05 +0200 Subject: minor cleanup --- git2rss | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/git2rss b/git2rss index e8ce8c3..e36bb12 100755 --- a/git2rss +++ b/git2rss @@ -12,8 +12,10 @@ if (PHP_SAPI != 'cli') die ("CLI only"); +// Configuration define('LOCAL', dirname(__DIR__) . '/'); define('REMOTE', 'https://git.remirepo.net/cgit/'); +define('FEEDSIZE', 50); require __DIR__ . '/vendor/autoload.php'; @@ -21,6 +23,7 @@ use Suin\RSSWriter\Channel; use Suin\RSSWriter\Feed; use Suin\RSSWriter\Item; +// Load previous changes if (file_exists(__DIR__ . '/git2rss.json')) { $json = file_get_contents(__DIR__ . '/git2rss.json'); $histo = json_decode($json, true); @@ -28,7 +31,6 @@ if (file_exists(__DIR__ . '/git2rss.json')) { $histo = array(); } - // Current change $log = exec("git log --pretty=format:%H,%at,%an,%s -1"); $entry = [ @@ -39,14 +41,12 @@ list($entry['hash'], $entry['time'], $entry['author'], $entry['comment']) = expl if (substr($entry['repo'], -4) != '.git') { $entry['repo'] .= '.git'; } -// print_r($entry); $short = substr($entry['hash'], 0, 7); -echo "RSS ENTRY: ${entry['author']} pushed to ${entry['repo']} (${entry['head']},$short): ${entry['comment']}"; - +echo "\nRSS ENTRY: ${entry['author']} pushed to ${entry['repo']} (${entry['head']},$short): ${entry['comment']}\n"; -// 50 recent changes +// 50 recent changes, and save $histo = array_merge([$entry], $histo); -while (count($histo) > 50) { +while (count($histo) > FEEDSIZE) { array_pop($histo); } file_put_contents(__DIR__ . '/git2rss.json', json_encode($histo, JSON_PRETTY_PRINT)); -- cgit