1 contributor
#!/bin/bash
source_path=${1:-"$HOME/scripts/flightgear/source"}
function xmlgetnext () {
local IFS='>'
read -d '<' TAG VALUE
# by design, the first TAG/VALUE pair is empty
# to avoid infinite loops at end of file parsing we return an error
# the next time we find an empty TAG
if test -z "$TAG"; then
test ${xmlgetnext_firstentry:-1} -eq 1 && xmlgetnext_firstentry=0 || return 1;
fi
# process $TAG only if necessary
local _TAG=$(printf '%q' $TAG)
if test ${_TAG:0:1} = '$'; then
TAG=$(tr '\n' ' ' <<< $TAG | sed 's/ */ /g; s/ *$//')
fi
}
exit_trap () {
rm $apixml
}
function showRSS () {
echo -e "${1^^}\n${1//[[:alnum:]]/-}"
revparse=$(git -C "$source_path/$1" rev-parse HEAD)
wget -qO- https://sourceforge.net/p/flightgear/$1/feed | while xmlgetnext; do
case "${TAG:0:1}" in
''|'?'|'!')
continue;;
/)
property=${property%/*};;
*)
if test "${TAG: -1}" != '/'; then
property+=/${TAG%% *}
fi;;
esac
case "$property" in
'/rss/channel/item/title')
title=$VALUE
;;
'/rss/channel/item/link')
sha1=${VALUE/https:\/\/sourceforge.net\/p\/flightgear\/${1}\/ci\/}
;;
'/rss/channel/item/pubDate')
pubDate=$(date +'%e %B' -d "$VALUE")
;;
esac
if test "$TAG" = "/item"; then
if test $revparse/ = $sha1; then
title="* ${title}"
else
title=" ${title}"
fi
echo "$title (${pubDate/# })"
fi
done
}
function showGitlab () {
echo -e "${1^^}\n${1//[[:alnum:]]/-}"
revparse=$(git -C "$source_path/$1" rev-parse HEAD)
curl --silent https://gitlab.com/api/v4/projects/flightgear%2F${1,,}/repository/commits \
| jq -r '.[] | (.id + "|" + .title + "|" + .created_at)' \
| awk -v revparse=$revparse -F '|' '
{
printf("%s %s (%s)\n",
$1 == revparse ? "*" : " ",
$2,
strftime("%e %B", mktime(gensub(/[^0-9]/, " ", "g", $3))))
}
'
}
cat << EOF
$(showGitlab OpenSceneGraph)
$(showRSS simgear)
$(showRSS flightgear)
$(showRSS fgdata)
EOF