Skip to content

Commit 02d003e

Browse files
authored
fix: rate limit on GitHub API calls
1 parent 17de109 commit 02d003e

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636

3737
- name: Deploy
3838
run: php ./tempest deploy
39+
env:
40+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3941

4042

4143

deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ php8.4 tempest cache:clear --all
1717
php8.4 tempest discovery:generate
1818
php8.4 tempest migrate:up --force
1919
php8.4 tempest static:clean --force
20-
php8.4 tempest static:generate
20+
php8.4 tempest static:generate --verbose=true
2121

2222
# Supervisor
2323
sudo supervisorctl restart all

src/GitHub/GetLatestRelease.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Tempest\HttpClient\HttpClient;
77
use Throwable;
88

9+
use function Tempest\env;
10+
911
final class GetLatestRelease
1012
{
1113
public function __construct(
@@ -15,12 +17,23 @@ public function __construct(
1517

1618
public function __invoke(): ?string
1719
{
20+
// Added by Aidan Casey to combat the GitHub rate limits.
21+
// We will inject the GH_TOKEN using our workflow.
22+
$headers = [];
23+
24+
if ($githubToken = env('GH_TOKEN')) {
25+
$headers['Authorization'] = 'Bearer ' . $githubToken;
26+
}
27+
1828
// Default release to the currently running version of Tempest.
1929
$defaultRelease = sprintf('v%s', Kernel::VERSION);
2030

2131
try {
2232
$body = $this->httpClient
23-
->get('https://api.github.com/repos/tempestphp/tempest-framework/releases/latest')
33+
->get(
34+
uri: 'https://api.github.com/repos/tempestphp/tempest-framework/releases/latest',
35+
headers: $headers,
36+
)
2437
->body;
2538

2639
return json_decode($body)->tag_name ?? $defaultRelease;

src/GitHub/GetStargazersCount.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Tempest\HttpClient\HttpClient;
66
use Throwable;
77

8+
use function Tempest\env;
9+
810
final class GetStargazersCount
911
{
1012
public function __construct(
@@ -14,8 +16,19 @@ public function __construct(
1416

1517
public function __invoke(): ?string
1618
{
19+
// Added by Aidan Casey to combat the GitHub rate limits.
20+
// We will inject the GH_TOKEN using our workflow.
21+
$headers = [];
22+
23+
if ($githubToken = env('GH_TOKEN')) {
24+
$headers['Authorization'] = 'Bearer ' . $githubToken;
25+
}
26+
1727
try {
18-
$body = $this->httpClient->get('https://api.github.com/repos/tempestphp/tempest-framework')->body;
28+
$body = $this->httpClient->get(
29+
uri: 'https://api.github.com/repos/tempestphp/tempest-framework',
30+
headers: $headers,
31+
)->body;
1932
$stargazers = json_decode($body)->stargazers_count ?? null;
2033

2134
return $stargazers > 999

0 commit comments

Comments
 (0)