git-scripts/gitea_wait_for_pr.sh

69 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
sleep_time=30
skip_wait=" -A \"continue\""
count_only=false
usage() {
echo "#####################################################################"
echo "# Usage:"
echo "#--------------------------------------------------------------------"
echo "#"
echo "# -c - counts all running wait scripts (output is json)"
echo "# -s - skips the waiting of notifiaction confirmation"
echo "# -t <seconds> - sets sleep time between rechecks (default: ${sleep_time})"
echo "#"
echo "# -h/? - displays this help message"
echo "#"
echo "#####################################################################"
exit 64
}
optstring="t:sc?h"
while getopts ${optstring} c; do
case ${c} in
c) count_only=true ;;
s) skip_wait="" ;;
t) sleep_time=${OPTARG} ;;
*) usage ;;
[h\?]) usage ;;
esac
done
if $count_only ; then
counter=$(ps afxj | grep -v grep | grep -E "bash .*gitea_wait_for_pr.sh$" | wc -l)
if [ $counter -gt 0 ]; then
i3status_state="Critical"
msg_counter="Watching: ${counter}"
else
i3status_state="Idle"
msg_counter="NoPRW"
fi
echo "{\"state\":\"${i3status_state}\", \"text\":\"${msg_counter}\"}"
exit 0
fi
pr_data=$(tea pr ls | grep -vE '^\+-----|^\| INDEX|^\| +\|' | column | sed -E 's/^\|//g;s/ *\| */|/g;s/\|\|/\|/g' | column -dt -s "\|" -o " " | rofi -dmenu -i -config ~/VersionControl/configs/ALL_config/.global_rofi.conf -matching regex)
pr_nr=$(awk '{print $1}' <<<"${pr_data}")
pr_msg="$(sed -E 's/^ +[0-9]+ +//g;s/ .*//g' <<<"${pr_data}")"
if ! grep -qE "^[0-9]+$" <<<"${pr_nr}" ; then
echo "pr_nr is not a number: ${pr_nr}"
exit 1
fi
while true; do
if tea pr ls | grep -qE "^\| *${pr_nr} *\|" ; then
echo "$(date +"%F %T") - PR still open (recheck in ${sleep_time})"
sleep $sleep_time
else
echo "$(date +"%F %T") - PR got closed"
notify-send -u critical -a PR_watcher${skip_wait} "${pr_data}" "Closed: [$(basename "$(git rev-parse --show-toplevel)")/${pr_nr}] ${pr_msg}"
break
fi
done