-
-
Save clue/431368a31405b76ab5cc643c7b00ad37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$org = isset($argv[1]) ? $argv[1] : 'leproxy'; | |
function fetch($url) { | |
fwrite(STDERR, 'Fetch ' . $url . PHP_EOL); | |
// optionally pass GITHUB_TOKEN env variable (create one on https://github.com/settings/tokens first) | |
$data = file_get_contents($url, false, stream_context_create(array('http' => array('header' => array( | |
'User-Agent: github-releases v1', | |
'Authorization: token ' . getenv('GITHUB_TOKEN') | |
))))); | |
if ($data === false) { | |
exit(1); | |
} | |
$all = json_decode($data, true); | |
if ($all === null) { | |
exit(1); | |
} | |
// http://php.net/manual/en/reserved.variables.httpresponseheader.php | |
foreach ($http_response_header ?? [] as $line) { | |
if (preg_match('/link: <([^>]+)>; rel="next"/i', $line, $m)) { | |
return array_merge($all, fetch($m[1])); | |
} | |
} | |
return $all; | |
} | |
$repos = fetch('https://api.github.com/orgs/' . $org . '/repos'); | |
$releases = array(); | |
foreach ($repos as $repo) { | |
$some = fetch('https://api.github.com/repos/' . $repo['full_name'] . '/releases?per_page=100'); | |
foreach ($some as $one) { | |
$time = (int)(new \DateTime($one['created_at']))->format('U'); | |
// sort by time (latest first) and otherwise project name | |
$releases[(PHP_INT_MAX - $time) . '-' . $repo['full_name']] = array('project' => $repo) + $one; | |
} | |
} | |
ksort($releases, SORT_NATURAL); | |
echo '# Changelog' . PHP_EOL; | |
foreach ($releases as $release) { | |
$version = ltrim($release['tag_name'], 'v'); | |
$date = (new DateTime($release['created_at']))->format('Y-m-d'); | |
$body = preg_replace('/\r?\n/', PHP_EOL, rtrim($release['body'])); | |
//echo PHP_EOL . '## [' . $version . '] - ' . $date . PHP_EOL . PHP_EOL; | |
echo PHP_EOL . '## ' . $release['project']['full_name'] . ' ' . $version . ' (' . $date . ')' . PHP_EOL . PHP_EOL; | |
echo $body . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment