Skip to content

Instantly share code, notes, and snippets.

@tornaria
Created March 12, 2023 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tornaria/38b82815f5705077244ef4bb0f685e12 to your computer and use it in GitHub Desktop.
Save tornaria/38b82815f5705077244ef4bb0f685e12 to your computer and use it in GitHub Desktop.
open changelog for a package
#! /bin/sh
# xchangelog [-q] PKG - open changelog for a package
if [ "$1" = "-q" ]; then
QUIET=yes
shift
fi
# tpl_get_var TEMPLATE VAR
tpl_get_var() {
[ -r "$1" ] || return 1
bash -c "
vopt_enable(){ :; }
vopt_if(){ :; }
vopt_conflict(){ :; }
vopt_with(){ :; }
source '$1' && [ -n \"\$$2\" ] && echo \$$2"
}
changelog_from_template() {
template="$(xdistdir)/srcpkgs/$1/template"
tpl_get_var "$template" changelog
}
changelog_from_db() {
xbps-query -p changelog "$1" ||
xbps-query -Rp changelog "$1"
}
changelog_from_url() {
case "$1" in
http*://*) echo "$1" ;;
*) return 1 ;;
esac
}
changelog=$(
changelog_from_template "$1" ||
changelog_from_db "$1" ||
changelog_from_url "$1"
)
if [ -z "$changelog" ]; then
echo "changelog not available, please set changelog= in template!"
exit 1
fi
if [ -n "$QUIET" ]; then
echo "$changelog"
exit 0
fi
curl_github_releases() {
curl -sL "https://api.github.com/repos/${changelog#*github.com/}" |
jq -r '.[] | (
"==================================================\n" +
"tag: " + .tag_name + "\n" +
"--------------------------------------------------\n" +
.body + "\n" )'
}
curl_changelog() {
case "$changelog" in
http*//github.com/*/releases)
curl_github_releases
;;
*)
curl -sL "$changelog"
;;
esac
}
curl_changelog | less -iF -+e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment