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
main
José Luis Lafuente 2 years ago committed by Profpatsch
parent 08aefdc2ca
commit 5321a6b82a
  1. 3
      pkgs/development/tools/parsing/tree-sitter/default.nix
  2. 23
      pkgs/development/tools/parsing/tree-sitter/update.nix

@ -27,7 +27,8 @@ let
# to update:
# 1) change all these hashes
# 2) nix-build -A tree-sitter.updater.update-all-grammars
# 3) run the ./result script that is output by that (it updates ./grammars)
# 3) OPTIONAL: Set GITHUB_TOKEN env variable to avoid api rate limit
# 4) run the ./result script that is output by that (it updates ./grammars)
version = "0.20.1";
sha256 = "sha256-JKbL05hFWI0jhAnRT9D0SWCoRPFqoMD4+LQQ1zyWc7g=";
cargoSha256 = "sha256-64O+3GrDqhRGth20B2/+jNDYSnwvT3SqYVqYNthiCB0=";

@ -360,9 +360,15 @@ let
# generic bash script to find the latest github release for a repo
latestGithubRelease = { orga, repo }: writeShellScript "latest-github-release" ''
set -euo pipefail
res=$(${curl}/bin/curl \
--silent \
"https://api.github.com/repos/${urlEscape orga}/${urlEscape repo}/releases/latest")
args=( '--silent' )
if [ -n "$GITHUB_TOKEN" ]; then
args+=( "-H" "Authorization: token ''${GITHUB_TOKEN}" )
fi
args+=( "https://api.github.com/repos/${urlEscape orga}/${urlEscape repo}/releases/latest" )
res=$(${curl}/bin/curl "''${args[@]}")
if [[ "$(printf "%s" "$res" | ${jq}/bin/jq '.message?')" =~ "rate limit" ]]; then
echo "rate limited" >&2
fi
@ -378,9 +384,14 @@ let
# find the latest repos of a github organization
latestGithubRepos = { orga }: writeShellScript "latest-github-repos" ''
set -euo pipefail
res=$(${curl}/bin/curl \
--silent \
'https://api.github.com/orgs/${urlEscape orga}/repos?per_page=100')
args=( '--silent' )
if [ -n "$GITHUB_TOKEN" ]; then
args+=( "-H" "Authorization: token ''${GITHUB_TOKEN}" )
fi
args+=( 'https://api.github.com/orgs/${urlEscape orga}/repos?per_page=100' )
res=$(${curl}/bin/curl "''${args[@]}")
if [[ "$(printf "%s" "$res" | ${jq}/bin/jq '.message?')" =~ "rate limit" ]]; then
echo "rate limited" >&2 #

Loading…
Cancel
Save