website/scripts/gen-changelog

71 lines
No EOL
1.9 KiB
PHP
Executable file

#!/usr/bin/php
<?php
function error($text) {
echo $text . "\n";
exit(1);
}
function output($text) {
echo $text . "\n";
}
function getJSON($url) {
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => [
'User-Agent: ssddanbrown',
]
]);
$data = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if (!empty($err)) error($err);
return json_decode($data, true);
}
// Check a milestone is provided
if (count($argv) < 2) {
error("Milestone ID required");
}
// Get milestone info from GitHub
$milestoneID = intval($argv[1]);
$issueURL = 'https://api.github.com/repos/BookStackApp/BookStack/issues?milestone='. $milestoneID .'&state=all';
$issues = getJSON($issueURL);
// Get BookStack version and check if a feature or minor release
$milestone = $issues[0]['milestone'];
$versionMatch = [];
preg_match('/v[0-9.]{5,7}/', $milestone['title'], $versionMatch);
$version = $versionMatch[0];
$splitVersion = explode('.', $version);
$isFeature = intval(array_pop($splitVersion)) === 0;
// Output title
output("# BookStack Beta {$version}\n");
// Output header text and links
if ($isFeature) {
$urlVersion = implode('0', $splitVersion);
output("- [Update instructions](https://www.bookstackapp.com/docs/admin/updates)");
output("- [Update details on blog](https://www.bookstackapp.com/blog/beta-release-{$urlVersion}/)");
output("\n### Full List of Changes\n");
} else {
output("\nThis release contains the following fixes and changes:\n");
}
// Output issues
foreach ($issues as $issue) {
$output = '* ';
$output .= trim($issue['title'], '.') . '.';
if (isset($issue['pull_request']) && $issue['user']['login'] !== 'ssddanbrown') {
$output .= " Thanks to [@{$issue['user']['login']}]({$issue['html_url']}).";
}
$output .= " ([#{$issue['number']}]({$issue['html_url']}))";
output($output);
}