summaryrefslogtreecommitdiffstats
path: root/git2rss
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2017-03-27 15:13:27 +0200
committerRemi Collet <fedora@famillecollet.com>2017-03-27 15:13:27 +0200
commitabb805147ef0528018ce7c9a66f0805f6607f1c7 (patch)
treed95a2b9fb8e50411dbef5f9649146215fb5ce18f /git2rss
parent44ecc6ffc42eca97f9ae71799ba9a866183d1120 (diff)
initial version
Diffstat (limited to 'git2rss')
-rwxr-xr-xgit2rss54
1 files changed, 38 insertions, 16 deletions
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();