From a50de39343076e0ee277c860471a1e702086cc11 Mon Sep 17 00:00:00 2001 From: suchAdemon Date: Thu, 15 Sep 2022 16:31:33 +0200 Subject: [PATCH] gitea_wait_for_pr.sh: added opts + better closed message --- gitea_wait_for_pr.sh | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/gitea_wait_for_pr.sh b/gitea_wait_for_pr.sh index 2ec58ab..964f47a 100755 --- a/gitea_wait_for_pr.sh +++ b/gitea_wait_for_pr.sh @@ -1,7 +1,37 @@ #!/bin/bash -sleep_time="${1:-30}" +sleep_time=30 +skip_wait=" -A \"continue\"" +count_only=false -if [ "${sleep_time}" == "count" ]; then +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 - 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 @@ -19,6 +49,7 @@ 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}" @@ -31,7 +62,7 @@ while true; do sleep $sleep_time else echo "$(date +"%F %T") - PR got closed" - notify-send -u critical -a PR_watcher -A "continue" "${pr_data}" "PR ${pr_nr} 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