Use ls-remote to get default branch

Calling GitHub API on macOS without the token hits rate limit
This commit is contained in:
Shivam Mathur 2022-12-19 08:19:07 +05:30
parent b3a12ce01e
commit 1a42045d48
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A

View File

@ -4,7 +4,7 @@ fetch_brew_tap() {
tap_user=$(dirname "$tap") tap_user=$(dirname "$tap")
tap_name=$(basename "$tap") tap_name=$(basename "$tap")
mkdir -p "$tap_dir/$tap_user" mkdir -p "$tap_dir/$tap_user"
branch="$(get -s -n "" "https://api.github.com/repos/$tap" | grep default_branch | cut -d: -f 2 | grep -Eo '[^\", ]+' | tr -d '\n')" branch="$(git ls-remote --symref "https://github.com/$tap" HEAD | grep -Eo 'refs/heads/.*' | tr '\t' '\n' | head -1 | cut -d '/' -f 3)"
get -s -n "" "https://github.com/$tap/archive/$branch.tar.gz" | sudo tar -xzf - -C "$tap_dir/$tap_user" get -s -n "" "https://github.com/$tap/archive/$branch.tar.gz" | sudo tar -xzf - -C "$tap_dir/$tap_user"
sudo mv "$tap_dir/$tap_user/$tap_name-$branch" "$tap_dir/$tap_user/$tap_name" sudo mv "$tap_dir/$tap_user/$tap_name-$branch" "$tap_dir/$tap_user/$tap_name"
} }