matrix-notifier: add 'auto' message type

This is useful to only ping me when the build is failing.
This commit is contained in:
Bruno BELANYI 2021-06-12 19:04:17 +02:00
parent abf66aa479
commit 7b71469624

View file

@ -10,8 +10,10 @@ usage() {
print_err " -h, --help" print_err " -h, --help"
print_err " print this usage screen and exit" print_err " print this usage screen and exit"
print_err " -t, --type" print_err " -t, --type"
print_err " which message type should be sent" print_err " which message type should be sent must be one of"
print_err " must be one of 'text' or 'notice'" print_err " 'text' or 'notice', or 'auto'."
print_err " The special value 'auto' defaults to 'notice', unless"
print_err " 'DRONE_BUILD_STATUS' indicates a failure."
} }
# Blessed Stack Overflow # Blessed Stack Overflow
@ -100,11 +102,17 @@ while [ $# -gt 0 ]; do
if [ -z "$arg" ]; then if [ -z "$arg" ]; then
print_err "Must give a message type when using '-t|--type'" print_err "Must give a message type when using '-t|--type'"
exit 1 exit 1
elif [ "$arg" != "text" ] && [ "$arg" != "notice" ]; then elif [ "$arg" == "text" ] || [ "$arg" == "notice" ]; then
MSG_TYPE="m.$arg"
elif [ "$arg" == "auto" ]; then
MSG_TYPE="m.notice"
if [ "$DRONE_BUILD_STATUS" == "failure" ]; then
MSG_TYPE="m.text"
fi
else
print_err "Invalid message type '$arg'" print_err "Invalid message type '$arg'"
exit 1 exit 1
fi fi
MSG_TYPE="m.$arg"
;; ;;
-h|--help) -h|--help)
usage usage