tree-sitter updater: use GITHUB_TOKEN if present

The updater makes a lot of requets to the github API, which is rate
limited. We can do more requets if we are authenticated

authored by José Luis Lafuente and committed by Profpatsch 5321a6b8 08aefdc2

+19 -7
+2 -1
pkgs/development/tools/parsing/tree-sitter/default.nix
··· 27 27 # to update: 28 28 # 1) change all these hashes 29 29 # 2) nix-build -A tree-sitter.updater.update-all-grammars 30 - # 3) run the ./result script that is output by that (it updates ./grammars) 30 + # 3) OPTIONAL: Set GITHUB_TOKEN env variable to avoid api rate limit 31 + # 4) run the ./result script that is output by that (it updates ./grammars) 31 32 version = "0.20.1"; 32 33 sha256 = "sha256-JKbL05hFWI0jhAnRT9D0SWCoRPFqoMD4+LQQ1zyWc7g="; 33 34 cargoSha256 = "sha256-64O+3GrDqhRGth20B2/+jNDYSnwvT3SqYVqYNthiCB0=";
+17 -6
pkgs/development/tools/parsing/tree-sitter/update.nix
··· 360 360 # generic bash script to find the latest github release for a repo 361 361 latestGithubRelease = { orga, repo }: writeShellScript "latest-github-release" '' 362 362 set -euo pipefail 363 - res=$(${curl}/bin/curl \ 364 - --silent \ 365 - "https://api.github.com/repos/${urlEscape orga}/${urlEscape repo}/releases/latest") 363 + 364 + args=( '--silent' ) 365 + if [ -n "$GITHUB_TOKEN" ]; then 366 + args+=( "-H" "Authorization: token ''${GITHUB_TOKEN}" ) 367 + fi 368 + args+=( "https://api.github.com/repos/${urlEscape orga}/${urlEscape repo}/releases/latest" ) 369 + 370 + res=$(${curl}/bin/curl "''${args[@]}") 371 + 366 372 if [[ "$(printf "%s" "$res" | ${jq}/bin/jq '.message?')" =~ "rate limit" ]]; then 367 373 echo "rate limited" >&2 368 374 fi ··· 378 384 # find the latest repos of a github organization 379 385 latestGithubRepos = { orga }: writeShellScript "latest-github-repos" '' 380 386 set -euo pipefail 381 - res=$(${curl}/bin/curl \ 382 - --silent \ 383 - 'https://api.github.com/orgs/${urlEscape orga}/repos?per_page=100') 387 + 388 + args=( '--silent' ) 389 + if [ -n "$GITHUB_TOKEN" ]; then 390 + args+=( "-H" "Authorization: token ''${GITHUB_TOKEN}" ) 391 + fi 392 + args+=( 'https://api.github.com/orgs/${urlEscape orga}/repos?per_page=100' ) 393 + 394 + res=$(${curl}/bin/curl "''${args[@]}") 384 395 385 396 if [[ "$(printf "%s" "$res" | ${jq}/bin/jq '.message?')" =~ "rate limit" ]]; then 386 397 echo "rate limited" >&2 #