#!/usr/bin/env php
Version $version
HEAD;
$bug_map = [
'/Fixed bug #([0-9]+)/' => '',
'/Fixed PECL bug #([0-9]+)/' => '',
'/Implemented FR #([0-9]+)/' => '',
'/GitHub PR #([0-9]+)/' => '',
'/GH-([0-9]+)/' => '',
'/GHSA-([0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4})/'
=> '',
];
foreach($entries as $module => $items) {
echo "- $module:\n
\n";
foreach($items as $item) {
// strip author
$item = preg_replace('/(\.(\s+\(CVE-\d+-\d+\))?)\s+\(.+?\)\s*$/', '\\1', $item);
// encode HTML
$item = htmlspecialchars($item, ENT_NOQUOTES);
// convert bug numbers
$item = preg_replace(array_keys($bug_map), array_values($bug_map), $item);
echo " - $item
\n";
}
echo "
\n";
}
echo "
\n\n\n";
if ($changelog) {
$contents = ob_get_clean();
$log = file_get_contents($changelog);
if (empty($log)) {
fprintf(STDERR, "Unable to read $changelog\n");
exit(1);
}
$parts = explode('.', $version, 3);
if (count($parts) < 2) {
fprintf(STDERR, "Unable to parse branch from $version\n");
exit(1);
}
$tag = "";
if (strpos($log, $tag) === false) {
fprintf(STDERR, "Unable to find branch tag in ChangeLog\n");
exit(1);
}
$log = str_replace($tag, "$tag\n\n$contents", $log);
file_put_contents($changelog, $log);
}