From 8deb04d803628abe4c14d65c9abc0b9245e7aab6 Mon Sep 17 00:00:00 2001 From: John Locke Date: Thu, 18 Aug 2016 16:15:43 -0700 Subject: [PATCH] Add support for prefix and link params --- README.md | 2 ++ bin/out | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/README.md b/README.md index a941124..9ecb10f 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,8 @@ Send message to specified Matrix Room, with the configured parameters * `data_file`: *Optional.* (string) Filename to post using a custom_event message type. If unset, defaults to the data_file on the resource. If it exists, the file must contain valid JSON. * `trigger`: *Optional.* (string) Arbitrary test to add to a "trigger" data item on custom message types. * `always_notify`: If true, send a notice even if text_file and data_file are empty. If false, and a text_file is specified but empty, a notification will not be sent. +* `prefix`: If set, this will be added to the beginning of a message. Commonly used with $BUILD_PIPELINE_NAME to indicate which pipeline is sending this message. +* `link`: If set to true, will wrap the text in a link to the build using the pattern $ATC_EXTERNAL_URL/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME ## Example diff --git a/bin/out b/bin/out index b8d166a..a052684 100755 --- a/bin/out +++ b/bin/out @@ -40,6 +40,9 @@ thismsgtype="$(jq -r '.params.msgtype // ""' < "${payload}")" always_notify="$(jq -r '.params.always_notify // "false"' < "${payload}")" debug="$(jq -r '.params.debug // "false"' < "${payload}")" silent="$(jq -r '.params.silent // "true"' < "${payload}")" +link="$(jq -r '.params.link // "false"' < "${payload}")" +prefix="$(jq -r '.params.prefix // ""' < "${payload}")" + TEXT_FILE_CONTENT="" [[ -n "${text_file}" && -f "${text_file}" ]] && TEXT_FILE_CONTENT="$(cat "${text_file}")" @@ -54,6 +57,12 @@ then [[ -z "${text}" ]] && text="_(missing notification text)_" text="$(echo -n "${text}" | jq -R -s .)" + [ "${link}" == "true" ] && text="${text}" + if [ -n "$prefix" ]; then + prefix="$(eval printf ${prefix} )" + text="${prefix}: ${text}" + fi + [[ "${token}" != "null" ]] && username="$(eval "printf ${token}" | jq -R -s .)" [[ "${room_id}" != "null" ]] && room_id="$(eval "printf ${room_id}" | jq -R -s .)" body="$(cat <