-
Notifications
You must be signed in to change notification settings - Fork 1
/
gh-rate-limit
executable file
·41 lines (32 loc) · 1.06 KB
/
gh-rate-limit
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
#!/usr/bin/env bash
set -eo pipefail
GH_REST_API_VERSION="X-GitHub-Api-Version: 2022-11-28"
GH_ACCEPT="Accept: application/vnd.github+json"
export GH_PAGER="cat"
usage() {
cat << EOF
Usage: gh rate-limit
Options
-u : show 'used' rather than 'remaining'
-h : show this help, such as it is
Just shows you your current usage of the GH APIs and when your limit expires.
Has some utility, but isn't that interesting
EOF
exit 1
}
gh_api() {
gh api -H "$GH_REST_API_VERSION" -H "$GH_ACCEPT" "$@"
}
used=""
while getopts 'hu' flag; do
case "${flag}" in
u) used="true";;
h) usage ;;
*) usage ;;
esac
done
if [[ -z "$used" ]]; then
gh_api rate_limit | jq --raw-output '.resources | to_entries[] | {name: .key} + .value | "\(.name) \(.remaining)/\(.limit) \(.reset | strflocaltime("%H:%M:%S") )"' | column -t -N "RESOURCE,REMAINING,RESETS"
else
gh_api rate_limit | jq --raw-output '.resources | to_entries[] | {name: .key} + .value | "\(.name) \(.used)/\(.limit) \(.reset | strflocaltime("%H:%M:%S") )"' | column -t -N "RESOURCE,USAGE,RESETS"
fi