Skip to content

Commit 317db84

Browse files
committed
Redirect to github in case of GH rate limit reached
1 parent d764c21 commit 317db84

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

bin/sign.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
echo 'Failed to sign';
99
exit(1);
1010
}
11-
openssl_free_key($pkeyid);
1211

1312
$sha384sig = base64_encode($sha384sig);
1413
file_put_contents($_SERVER['argv'][1].'.sig', json_encode(['sha384' => $sha384sig], JSON_UNESCAPED_SLASHES));

src/Controller/ChangelogController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ public function changelog(string $version, \Parsedown $parsedown, string $docDir
2222
if (!Preg::isMatchStrictGroups('{(?:^|\n)### \['.preg_quote($version).'\] (?P<date>.*)\n\n(?P<changelog>(?:^ \*.*\n)+)}mi', $changelog, $match)) {
2323
$resp = $client->request('GET', 'https://api.github.com/repos/composer/composer/releases/tags/' . $version);
2424
if ($resp->getStatusCode() >= 300) {
25+
if ($resp->getHeaders(false)['x-ratelimit-remaining'][0] === '0') {
26+
return $this->redirect('https://github.com/composer/composer/releases/tag/' . $version);
27+
}
2528
throw $this->createNotFoundException('Requested page was not found.');
2629
}
2730

2831
$data = json_decode($resp->getContent(false), true, flags: JSON_THROW_ON_ERROR);
29-
if (!is_array($data) || !isset($data['body']) || !is_string($data['body'])) {
32+
if (!is_array($data) || !isset($data['body'], $data['created_at']) || !is_string($data['body']) || !is_string($data['created_at'])) {
3033
throw $this->createNotFoundException('Requested page was not found.');
3134
}
32-
$match = ['changelog' => $data['body']];
35+
36+
$match = ['changelog' => $data['body'], 'date' => substr($data['created_at'], 0, 10)];
3337
}
3438

3539
$changelog = $parsedown->text($match['changelog']);

0 commit comments

Comments
 (0)