Compare commits
No commits in common. "5f1fb1c1a460f77370c2c2a79fa697cb31f84b09" and "75d482cd6b0045fa463f0375d2bdf4b2ea4a3d1d" have entirely different histories.
5f1fb1c1a4
...
75d482cd6b
|
@ -31,4 +31,4 @@ export MESSAGE='This is my test message'
|
||||||
This script is packaged with `Nix`, you can just use `nix run .` to run it.
|
This script is packaged with `Nix`, you can just use `nix run .` to run it.
|
||||||
|
|
||||||
The only dependencies are `bash`, `curl`, and `jq`, install those and you should
|
The only dependencies are `bash`, `curl`, and `jq`, install those and you should
|
||||||
be ready to go! Format is needed when using formatting (enabled by default).
|
be ready to go!
|
||||||
|
|
|
@ -75,7 +75,7 @@
|
||||||
packages = {
|
packages = {
|
||||||
matrix-notifier = pkgs.stdenvNoCC.mkDerivation rec {
|
matrix-notifier = pkgs.stdenvNoCC.mkDerivation rec {
|
||||||
pname = "matrix-notifier";
|
pname = "matrix-notifier";
|
||||||
version = "0.2.0";
|
version = "0.1.2";
|
||||||
|
|
||||||
src = ./matrix-notifier;
|
src = ./matrix-notifier;
|
||||||
|
|
||||||
|
@ -99,7 +99,6 @@
|
||||||
wrapperPath = with pkgs; lib.makeBinPath [
|
wrapperPath = with pkgs; lib.makeBinPath [
|
||||||
curl
|
curl
|
||||||
jq
|
jq
|
||||||
pandoc
|
|
||||||
];
|
];
|
||||||
|
|
||||||
fixupPhase = ''
|
fixupPhase = ''
|
||||||
|
|
|
@ -9,9 +9,6 @@ usage() {
|
||||||
print_err ""
|
print_err ""
|
||||||
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 " -f, --format"
|
|
||||||
print_err " should the message be formatted using 'pandoc'."
|
|
||||||
print_err " Must be either 'true' or 'false'."
|
|
||||||
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 must be one of"
|
||||||
print_err " 'text' or 'notice', or 'auto'."
|
print_err " 'text' or 'notice', or 'auto'."
|
||||||
|
@ -40,12 +37,7 @@ rawurlencode() {
|
||||||
|
|
||||||
default_drone_message() {
|
default_drone_message() {
|
||||||
local msg="Build ${DRONE_BUILD_STATUS}"
|
local msg="Build ${DRONE_BUILD_STATUS}"
|
||||||
local drone_url="${DRONE_SYSTEM_PROTO}://${DRONE_SYSTEM_HOST}/${DRONE_REPO}/${DRONE_BUILD_NUMBER}"
|
msg="$msg ${DRONE_SYSTEM_PROTO}://${DRONE_SYSTEM_HOST}/${DRONE_REPO}/${DRONE_BUILD_NUMBER}"
|
||||||
if [ "$FORMAT" == "true" ]; then
|
|
||||||
msg="$msg [${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}#${DRONE_COMMIT:0:8}]($drone_url)"
|
|
||||||
else
|
|
||||||
msg="$msg $drone_url"
|
|
||||||
fi
|
|
||||||
msg="$msg (${DRONE_TAG:-$DRONE_BRANCH})"
|
msg="$msg (${DRONE_TAG:-$DRONE_BRANCH})"
|
||||||
printf '%s' "$msg"
|
printf '%s' "$msg"
|
||||||
}
|
}
|
||||||
|
@ -79,16 +71,6 @@ get_message_type() {
|
||||||
printf '%s' "m.$MSG_TYPE"
|
printf '%s' "m.$MSG_TYPE"
|
||||||
}
|
}
|
||||||
|
|
||||||
make_message_json() {
|
|
||||||
{
|
|
||||||
printf '%s' "$1" |
|
|
||||||
jq --raw-input --slurp "{msgtype: \"$(get_message_type)\", body: .}"
|
|
||||||
[ "$FORMAT" == "true" ] && printf '%s' "$1" |
|
|
||||||
pandoc |
|
|
||||||
jq --raw-input --slurp "{format: \"org.matrix.custom.html\", formatted_body: .}"
|
|
||||||
} | jq -s 'add'
|
|
||||||
}
|
|
||||||
|
|
||||||
send_message() {
|
send_message() {
|
||||||
local login_json
|
local login_json
|
||||||
local token
|
local token
|
||||||
|
@ -112,32 +94,20 @@ send_message() {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
message_json="$(make_message_json "$MESSAGE")"
|
message_json="$(printf '%s' "$MESSAGE" |
|
||||||
|
jq --raw-input --slurp "{msgtype: \"$(get_message_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='auto'
|
||||||
FORMAT='true'
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
opt="$1"
|
opt="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
-f|--format)
|
|
||||||
arg="$1"
|
|
||||||
shift
|
|
||||||
|
|
||||||
if [ "$arg" == "true" ] || [ "$arg" == "false" ]; then
|
|
||||||
FORMAT="$arg"
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
print_err "Must give value 'true' or 'false' with '-t|--type'"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
-t|--type)
|
-t|--type)
|
||||||
arg="$1"
|
arg="$1"
|
||||||
shift
|
shift
|
||||||
|
|
Loading…
Reference in a new issue