Skip to content

Commit 786ddc9

Browse files
ipmbclaude
andcommitted
Add GitHub token authentication support to avoid rate limits
- Add optional GITHUB_TOKEN authentication to increase API rate limits from 60 to 5000 requests/hour - Include proper Accept header for GitHub API v3 - Provide clearer error messages when rate limits are hit - Update README with optional token usage instructions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f8ae8b9 commit 786ddc9

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,16 @@ The version of the CLI that was setup
2020
- name: AppPack CLI
2121
uses: apppackio/setup-apppack-cli@v1
2222
```
23+
24+
### With GitHub Token (Optional)
25+
26+
If you encounter GitHub API rate limit errors (403), you can provide a GitHub token:
27+
28+
```yaml
29+
- name: AppPack CLI
30+
uses: apppackio/setup-apppack-cli@v1
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
```
34+
35+
This increases the rate limit from 60 to 5,000 requests per hour.

index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,32 @@ async function run() {
7272
// Download a JSON file from a URL
7373
async function downloadJson(url) {
7474
return new Promise((resolve, reject) => {
75+
const headers = {
76+
"User-Agent": "apppackio/setup-apppack",
77+
"Accept": "application/vnd.github+json"
78+
};
79+
80+
// Use GitHub token if available for higher rate limits
81+
const token = process.env.GITHUB_TOKEN;
82+
if (token) {
83+
headers["Authorization"] = `Bearer ${token}`;
84+
}
85+
7586
const req = https.get(
7687
url,
77-
{ headers: { "User-Agent": "apppackio/setup-apppack" } },
88+
{ headers },
7889
(res) => {
7990
let data = "";
8091

8192
// Check for non-success status codes
8293
if (res.statusCode !== 200) {
8394
if (res.statusCode === 404) {
8495
reject(new Error(`Release not found (404). Please check if the version exists.`));
96+
} else if (res.statusCode === 403) {
97+
const rateLimitMsg = token
98+
? `GitHub API rate limit exceeded (403). Even with authentication, you may have hit the limit.`
99+
: `GitHub API rate limit exceeded (403). Consider setting GITHUB_TOKEN to increase rate limits from 60 to 5000 requests/hour.`;
100+
reject(new Error(rateLimitMsg));
85101
} else {
86102
reject(new Error(`GitHub API request failed with status ${res.statusCode}`));
87103
}

0 commit comments

Comments
 (0)