-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrate_limit.sh
More file actions
executable file
·37 lines (31 loc) · 1.02 KB
/
rate_limit.sh
File metadata and controls
executable file
·37 lines (31 loc) · 1.02 KB
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
#!/usr/bin/env bash
# Show GitHub GraphQL API rate limit status
# MIT License — Copyright 2026 Paul van Oorschot
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/_common.sh"
JSON_MODE=false
for arg in "$@"; do
case "$arg" in
--json) JSON_MODE=true ;;
--help|-h)
echo "Usage: rate_limit.sh [--json]"
echo "Show current GitHub GraphQL API rate limit status."
exit 0 ;;
esac
done
require_gh
QUERY='{ rateLimit { limit cost remaining resetAt } }'
result=$(graphql_query "$QUERY")
if $JSON_MODE; then
echo "$result" | jq '.data.rateLimit'
exit 0
fi
limit=$(echo "$result" | jq -r '.data.rateLimit.limit')
remaining=$(echo "$result" | jq -r '.data.rateLimit.remaining')
used=$((limit - remaining))
reset_at=$(echo "$result" | jq -r '.data.rateLimit.resetAt')
reset_fmt=$(date -d "$reset_at" '+%Y-%m-%d %H:%M:%S UTC' 2>/dev/null || echo "$reset_at")
echo "GitHub GraphQL Rate Limit:"
echo " Used: $used / $limit"
echo " Remaining: $remaining"
echo " Resets at: $reset_fmt"