Compare commits
No commits in common. "9dc5006663a1326902316eea1d309744cd6ad9f4" and "efd6d5ddbb260381901a95cc6679dede03009e69" have entirely different histories.
9dc5006663
...
efd6d5ddbb
|
@ -10,10 +10,8 @@ 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 must be one of"
|
print_err " which message type should be sent"
|
||||||
print_err " 'text' or 'notice', or 'auto'."
|
print_err " must be one of 'text' or 'notice'"
|
||||||
print_err " The special value 'auto' defaults to 'notice', unless"
|
|
||||||
print_err " 'DRONE_BUILD_STATUS' indicates a failure."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Blessed Stack Overflow
|
# Blessed Stack Overflow
|
||||||
|
@ -59,18 +57,6 @@ ensure_variables() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
get_message_type() {
|
|
||||||
if [ "$MSG_TYPE" == "auto" ]; then
|
|
||||||
if [ "$DRONE_BUILD_STATUS" == "failure" ]; then
|
|
||||||
MSG_TYPE="text"
|
|
||||||
else
|
|
||||||
MSG_TYPE="notice"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
printf '%s' "m.$MSG_TYPE"
|
|
||||||
}
|
|
||||||
|
|
||||||
send_message() {
|
send_message() {
|
||||||
local login_json
|
local login_json
|
||||||
local token
|
local token
|
||||||
|
@ -95,13 +81,13 @@ send_message() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
message_json="$(printf '%s' "$MESSAGE" |
|
message_json="$(printf '%s' "$MESSAGE" |
|
||||||
jq --raw-input --slurp "{msgtype: \"$(get_message_type)\", body: .}")"
|
jq --raw-input --slurp "{msgtype: \"$MSG_TYPE\", body: .}")"
|
||||||
curl -XPOST \
|
curl -XPOST \
|
||||||
-d "$message_json" \
|
-d "$message_json" \
|
||||||
"$ADDRESS/_matrix/client/r0/rooms/$(rawurlencode "$ROOM")/send/m.room.message?access_token=$(rawurlencode "$token")" 2>/dev/null
|
"$ADDRESS/_matrix/client/r0/rooms/$(rawurlencode "$ROOM")/send/m.room.message?access_token=$(rawurlencode "$token")" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
MSG_TYPE='auto'
|
MSG_TYPE='m.notice'
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
opt="$1"
|
opt="$1"
|
||||||
|
@ -111,19 +97,14 @@ while [ $# -gt 0 ]; do
|
||||||
-t|--type)
|
-t|--type)
|
||||||
arg="$1"
|
arg="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
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
|
||||||
fi
|
elif [ "$arg" != "text" ] && [ "$arg" != "notice" ]; then
|
||||||
|
|
||||||
for type in text notice auto; do
|
|
||||||
if [ "$arg" == "$type" ]; then
|
|
||||||
continue 2 # Go to next argument
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
print_err "Invalid message type '$arg'"
|
print_err "Invalid message type '$arg'"
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
MSG_TYPE="m.$arg"
|
||||||
;;
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
usage
|
usage
|
||||||
|
|
Loading…
Reference in a new issue