Skip to content

Commit b554b64

Browse files
committed
Use GITHUB_TOKEN to avoid rate limiting
1 parent b5d81aa commit b554b64

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

populate_projects.sh

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ set -e -u -o pipefail
44

55
cd projects
66

7+
github_auth=()
8+
if [[ -n "${GITHUB_TOKEN:-}" ]]; then
9+
github_auth=(--header "Authorization: Bearer $GITHUB_TOKEN")
10+
fi
11+
712
for d in */; do
813
d="${d%/}"
914
pushd "$d"
@@ -15,10 +20,10 @@ for d in */; do
1520
mkdocs_yml="${BASH_REMATCH[3]}"
1621
else
1722
repo="${d//--//}"
18-
branch=$(curl -sfL "https://api.github.com/repos/$repo" | jq -r '.default_branch')
23+
branch=$(curl -sfL "${github_auth[@]}" "https://api.github.com/repos/$repo" | jq -r '.default_branch')
1924
mkdocs_yml='mkdocs.yml'
2025
fi
21-
[[ "$(curl -sfL "https://api.github.com/repos/$repo/commits?per_page=1&sha=$branch" | jq -r '.[0].commit.url')" =~ ^https://api.github.com/repos/([^/]+/[^/]+)/git/commits/([0-9a-f]+)$ ]]
26+
[[ "$(curl -sfL "${github_auth[@]}" "https://api.github.com/repos/$repo/commits?per_page=1&sha=$branch" | jq -r '.[0].commit.url')" =~ ^https://api.github.com/repos/([^/]+/[^/]+)/git/commits/([0-9a-f]+)$ ]]
2227
repo="${BASH_REMATCH[1]}"
2328
commit="${BASH_REMATCH[2]}"
2429
echo "https://github.com/$repo/blob/$branch/$mkdocs_yml" | tee /dev/stderr >project.txt

0 commit comments

Comments
 (0)