-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-rate-limit.ts
41 lines (34 loc) · 1.13 KB
/
check-rate-limit.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { graphql } from "@octokit/graphql";
import type { RateLimit } from "@octokit/graphql-schema";
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
if (!GITHUB_TOKEN) {
throw new Error("Missing required environment variables (GITHUB_TOKEN).");
}
const graphqlWithAuth = graphql.defaults({
headers: {
authorization: `token ${GITHUB_TOKEN}`,
},
});
async function checkRateLimit() {
try {
const { rateLimit }: { rateLimit: RateLimit } = await graphqlWithAuth(`
query getRateLimit {
rateLimit {
remaining
limit
cost
resetAt
used
}
}
`);
console.log('\n=== GitHub API Rate Limit Status ===');
console.log(`Used: ${rateLimit.used}/${rateLimit.limit}`);
console.log(`Remaining: ${rateLimit.remaining}/${rateLimit.limit}`);
console.log(`Resets at: ${new Date(rateLimit.resetAt).toLocaleString()}`);
console.log('==================================\n');
} catch (error) {
console.error('❌ Error checking rate limit:', error);
}
}
checkRateLimit();