summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2017-03-27 17:26:05 +0200
committerRemi Collet <fedora@famillecollet.com>2017-03-27 17:26:05 +0200
commita860637a0bffdd77369c31fc28ce99f028585681 (patch)
tree48f7d6ef4cf84d2c30242ba24c973709a9c05a97
parent4abf28202c54b48395d025dfb967efd73b2b2524 (diff)
minor cleanup
-rwxr-xr-xgit2rss12
1 files 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));