dotfiles/home/dot-local/lib/bash/github-api.sh

20 lines
674 B
Bash
Raw Normal View History

2022-02-03 18:33:04 +00:00
# -*- mode: bash -*-
[[ ! "${LIB_SHELL_GITHUB}" ]] && LIB_SHELL_GITHUB="Y" || return
has_software 'jq' 'curl'
function github_api() {
curl -L --silent -H "Accept: application/vnd.github.v3.raw+json" \
${TOKEN:+ -H "Authorization: Token ${TOKEN}"} "$@"
}
github_get_latest_release() {
local user="${1:?'require name'}" repo="${2:-"$1"}"
github_api "https://api.github.com/repos/${user}/${repo}/releases/latest"
}
github_latest_release_assets() {
local name="\$doc.tag_name"
local link="(\$doc.assets[] | select(.name ${SUFFIX:+"| endswith(\"${SUFFIX}\")"}).browser_download_url)"
github_get_latest_release "$@" | jq -r ". as \$doc | ${name} + \" \" + ${link}"
}