diff options
author | Remi Collet <fedora@famillecollet.com> | 2017-03-27 15:13:27 +0200 |
---|---|---|
committer | Remi Collet <fedora@famillecollet.com> | 2017-03-27 15:13:27 +0200 |
commit | abb805147ef0528018ce7c9a66f0805f6607f1c7 (patch) | |
tree | d95a2b9fb8e50411dbef5f9649146215fb5ce18f | |
parent | 44ecc6ffc42eca97f9ae71799ba9a866183d1120 (diff) |
initial version
-rw-r--r-- | .gitignore | 2 | ||||
-rwxr-xr-x | git2rss | 54 |
2 files changed, 40 insertions, 16 deletions
@@ -1,2 +1,4 @@ vendor composer.lock +git2rss.json +index.html @@ -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(); |