summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rwxr-xr-xgit2rss54
2 files changed, 40 insertions, 16 deletions
diff --git a/.gitignore b/.gitignore
index 7579f74..eabced1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
vendor
composer.lock
+git2rss.json
+index.html
diff --git a/git2rss b/git2rss
index ab6be66..5a141d4 100755
--- a/git2rss
+++ b/git2rss
@@ -1,6 +1,11 @@
#!/usr/bin/env php
<?php
+if (PHP_SAPI != 'cli') die ("CLI only");
+
+define('LOCAL', dirname(__DIR__, 2) . '/');
+define('REMOTE', 'https://git.remirepo.net/cgit/');
+
require __DIR__ . '/vendor/autoload.php';
use Suin\RSSWriter\Channel;
@@ -14,20 +19,32 @@ if (file_exists(__DIR__ . '/git2rss.json')) {
$histo = array();
}
-$repo = basename(getcwd(), '.git');
-$head = basename($_SERVER['argv'][1] ?: 'master');
+
+// Current change
$log = exec("git log --pretty=format:%H,%at,%an,%s -1");
-$log = list($hash,$time,$author,$comment)=explode(',', $log, 4);
-$short = substr($hash, 0, 7);
-$msg = "$author pushed to $repo ($head,$short): $comment";
+$entry = [
+ 'repo' => substr(getcwd(), strlen(LOCAL)),
+ 'head' => basename($_SERVER['argv'][1] ?? 'master'),
+];
+list($entry['hash'], $entry['time'], $entry['author'], $entry['comment']) = explode(',', $log, 4);
+if (substr($entry['repo'], -4) != '.git') {
+ $entry['repo'] .= '.git';
+}
+// 50 recent changes
+$histo = array_merge([$entry], $histo);
+while (count($histo) > 50) {
+ array_pop($histo);
+}
+file_put_contents(__DIR__ . '/git2rss.json', json_encode($histo, JSON_PRETTY_PRINT));
+// RSS
$feed = new Feed();
$channel = new Channel();
$channel
->title("Remi's RPM git repostiories")
->description('Change')
- ->url('https://git.remirepo.net/cgit')
+ ->url(REMOTE)
->language('en-US')
->copyright('Copyright 2005-2017, Remi Collet')
->pubDate(time())
@@ -35,14 +52,19 @@ $channel
->ttl(60)
->appendTo($feed);
+foreach ($histo as $entry) {
+ $short = substr($entry['hash'], 0, 7);
+ $msg = "${entry['author']} pushed to ${entry['repo']} (${entry['head']},$short): ${entry['comment']}";
+
+ $item = new Item();
+ $item
+ ->title($msg)
+ ->description($msg)
+ ->url(REMOTE . "${entry['repo']}/commit/?id=${entry['hash']}")
+ ->author($entry['author'])
+ ->pubDate($entry['time'])
+ ->guid("${entry['repo']}_${entry['hash']}", true)
+ ->appendTo($channel);
+}
+file_put_contents(__DIR__ . '/index.html', $feed);
-$item = new Item();
-$item
- ->title($msg)
- ->description($msg)
- ->url('https://git.remirepo.net/cgit')
- ->author($author)
- ->pubDate($time)
- ->guid("${repo}_${hash}", true)
- ->appendTo($channel);
-echo $feed; // or echo $feed->render();