#!/usr/bin/env php * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ 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'; use Suin\RSSWriter\Channel; use Suin\RSSWriter\Feed; use Suin\RSSWriter\Item; $head = basename($_SERVER['argv'][1] ?? 'master'); // Current change exec("git log --format=fuller --max-count=1 $head", $out); $log = exec("git log --pretty=format:%H,%at,%cn,%an,%s --max-count=1 $head"); $entry = [ 'repo' => substr(getcwd(), strlen(LOCAL)), 'head' => $head, 'desc' => implode("
\n", $out), ]; list( $entry['hash'], $entry['time'], $entry['commiter'], $entry['author'], $entry['comment'] ) = explode(',', $log, 5); if (substr($entry['repo'], -4) != '.git') { $entry['repo'] .= '.git'; } $short = substr($entry['hash'], 0, 7); printf("GIT2RSS Welcome %s\n", $entry['commiter']); // Load previous changes if (file_exists(__DIR__ . '/git2rss.json')) { $json = file_get_contents(__DIR__ . '/git2rss.json'); $histo = json_decode($json, true); printf("GIT2RSS %d entries loaded\n", count($histo)); } else { $histo = array(); } echo "GIT2RSS new entry: ${entry['author']} pushed to ${entry['repo']} (${entry['head']},$short): ${entry['comment']}\n"; // 50 recent changes, and save $histo = array_merge([$entry], $histo); while (count($histo) > FEEDSIZE) { array_pop($histo); } file_put_contents(__DIR__ . '/git2rss.json', json_encode($histo, JSON_PRETTY_PRINT)); // Generate RSS $feed = new Feed(); $channel = new Channel(); $channel ->title("Remi's RPM git repostiories") ->description('Recent changes') ->url(REMOTE) ->language('en-US') ->copyright('Copyright 2005-2020, Remi Collet') ->pubDate(time()) ->lastBuildDate(time()) ->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($entry['desc'] ?? $msg) ->url(REMOTE . "${entry['repo']}/commit/?id=${entry['hash']}") ->author($entry['author']) ->pubDate($entry['time']) ->guid("${entry['repo']}_${entry['hash']}", true) ->appendTo($channel); } // Save RSS file_put_contents(__DIR__ . '/index.html', $feed); printf("GIT2RSS %d entries saved\n", count($histo)); // standard usage passthru('git update-server-info');