Skip to content

Commit 7a88ef1

Browse files
committed
GitHub rate limit
1 parent 1177b6f commit 7a88ef1

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

gh_rate_limit

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
3+
# Check if gh CLI is installed
4+
if ! command -v gh &> /dev/null; then
5+
echo "GitHub CLI (gh) is not installed. Please install it first."
6+
exit 1
7+
fi
8+
9+
# Check if jq is installed
10+
if ! command -v jq &> /dev/null; then
11+
echo "jq is not installed. Please install it first."
12+
exit 1
13+
fi
14+
15+
# Fetch rate limit information
16+
rate_limit_data=$(gh api rate_limit)
17+
18+
# Parse and display the information
19+
echo "=========================================="
20+
echo "GitHub API Rate Limit Status"
21+
echo "=========================================="
22+
echo ""
23+
24+
# Core API
25+
echo "Core API:"
26+
core_limit=$(echo "$rate_limit_data" | jq -r '.resources.core.limit')
27+
core_used=$(echo "$rate_limit_data" | jq -r '.resources.core.used')
28+
core_remaining=$(echo "$rate_limit_data" | jq -r '.resources.core.remaining')
29+
core_reset=$(echo "$rate_limit_data" | jq -r '.resources.core.reset')
30+
core_reset_time=$(date -r "$core_reset" 2>/dev/null || date -d "@$core_reset" 2>/dev/null || echo "N/A")
31+
32+
echo " Limit: $core_limit"
33+
echo " Used: $core_used"
34+
echo " Remaining: $core_remaining"
35+
echo " Resets at: $core_reset_time"
36+
echo ""
37+
38+
# Search API
39+
echo "Search API:"
40+
search_limit=$(echo "$rate_limit_data" | jq -r '.resources.search.limit')
41+
search_used=$(echo "$rate_limit_data" | jq -r '.resources.search.used')
42+
search_remaining=$(echo "$rate_limit_data" | jq -r '.resources.search.remaining')
43+
search_reset=$(echo "$rate_limit_data" | jq -r '.resources.search.reset')
44+
search_reset_time=$(date -r "$search_reset" 2>/dev/null || date -d "@$search_reset" 2>/dev/null || echo "N/A")
45+
46+
echo " Limit: $search_limit"
47+
echo " Used: $search_used"
48+
echo " Remaining: $search_remaining"
49+
echo " Resets at: $search_reset_time"
50+
echo ""
51+
52+
# GraphQL API
53+
echo "GraphQL API:"
54+
graphql_limit=$(echo "$rate_limit_data" | jq -r '.resources.graphql.limit')
55+
graphql_used=$(echo "$rate_limit_data" | jq -r '.resources.graphql.used')
56+
graphql_remaining=$(echo "$rate_limit_data" | jq -r '.resources.graphql.remaining')
57+
graphql_reset=$(echo "$rate_limit_data" | jq -r '.resources.graphql.reset')
58+
graphql_reset_time=$(date -r "$graphql_reset" 2>/dev/null || date -d "@$graphql_reset" 2>/dev/null || echo "N/A")
59+
60+
echo " Limit: $graphql_limit"
61+
echo " Used: $graphql_used"
62+
echo " Remaining: $graphql_remaining"
63+
echo " Resets at: $graphql_reset_time"
64+
echo ""
65+
66+
# Show percentage remaining for core API
67+
if [ "$core_limit" -gt 0 ]; then
68+
percentage=$((core_remaining * 100 / core_limit))
69+
echo "Core API Usage: $percentage% remaining"
70+
71+
if [ "$percentage" -lt 10 ]; then
72+
echo "⚠️ WARNING: Running low on API calls!"
73+
fi
74+
fi
75+
76+
echo "=========================================="

0 commit comments

Comments
 (0)