diff --git a/README.md b/README.md index 1d7f210..03d32cd 100644 --- a/README.md +++ b/README.md @@ -117,8 +117,6 @@ the following will be sent under these conditions: Optional: -- `channel`: *Optional.* Override channel to send message to. `#channel` and `@user` forms are allowed. You can notify multiple channels separated by whitespace, like `#channel @user`. -- `channel_file`: *Optional.* File that contains a list of channels to send message to. If `channel` is also specified, the two lists will be concatenated. - `env_file`: *Optional.* File that contains a list of `key=value` environment variables that will be available in your slack messages template - `username`: *Optional.* Override name of the sender of the message. - `icon_url`: *Optional.* Override icon by providing URL to the image. @@ -141,7 +139,6 @@ jobs: plan: - put: slack-alert params: - channel: '#my_channel' text_file: results/message.txt text: | The build had a result. Check it out at: @@ -168,8 +165,7 @@ body: { "text": ":some_emoji:\n", "username": "concourse", "icon_url": null, - "icon_emoji": null, - "channel": null + "icon_emoji": null } > cat test/combined_text_template_and_file_missing.out | ./out . @@ -178,8 +174,7 @@ body: { "text": ":some_emoji:\n_(no notification provided)_\n", "username": "concourse", "icon_url": null, - "icon_emoji": null, - "channel": null + "icon_emoji": null } > cat test/combined_text_template_and_file.out | ./out . @@ -188,8 +183,7 @@ body: { "text": ":some_emoji:\nThis text came from sample.txt. It could have been generated by a previous Concourse task.\n\nMultiple lines are allowed.\n", "username": "concourse", "icon_url": null, - "icon_emoji": null, - "channel": null + "icon_emoji": null } > cat test/text_file_empty.out | ./out . @@ -198,8 +192,7 @@ body: { "text": "_(missing notification text)_\n", "username": "concourse", "icon_url": null, - "icon_emoji": null, - "channel": null + "icon_emoji": null } > cat test/text_file.out | ./out . @@ -208,8 +201,7 @@ body: { "text": "This text came from sample.txt. It could have been generated by a previous Concourse task.\n\nMultiple lines are allowed.\n", "username": "concourse", "icon_url": null, - "icon_emoji": null, - "channel": null + "icon_emoji": null } > cat test/text.out | ./out . @@ -218,8 +210,7 @@ body: { "text": "Inline static text\n", "username": "concourse", "icon_url": null, - "icon_emoji": null, - "channel": null + "icon_emoji": null } ``` diff --git a/ci/pipeline.yml b/ci/pipeline.yml index fdb790b..8773251 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -42,7 +42,6 @@ meta: slack: webhook: (( param "Please specify your Slack Incoming Webhook Integration URL" )) notification: '(( concat ":concourse-fail: <" meta.url "/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME| Failed to build " meta.name "! Click for details.>" ))' - channel: (( param "Please specify the channel (#name) or user (@user) to send messages to" )) username: concourse icon: http://cl.ly/image/3e1h0H3H2s0P/concourse-logo.png @@ -66,7 +65,6 @@ jobs: on_failure: put: notify params: - channel: (( grab meta.slack.channel )) username: (( grab meta.slack.username )) icon_url: (( grab meta.slack.icon )) text: (( grab meta.slack.notification )) diff --git a/ci/settings.yml b/ci/settings.yml index 685313e..fb288e8 100644 --- a/ci/settings.yml +++ b/ci/settings.yml @@ -25,4 +25,3 @@ meta: slack: webhook: (( vault "secret/pipelines/slack-notification-resource/slack:webhook" )) - channel: '#botspam' diff --git a/out b/out index 205699a..f561904 100755 --- a/out +++ b/out @@ -34,8 +34,6 @@ icon_url="$(jq '(.params.icon_url // null)' < "${payload}")" icon_emoji="$(jq '(.params.icon_emoji // null)' < "${payload}")" link_names="$(jq -r '(.params.link_names // false)' < "${payload}")" -channels="$(jq -r '(.params.channel // null)' < "${payload}")" -channel_file="$(jq -r '(.params.channel_file // null)' < "${payload}")" attachments_file="$(jq -r '.params.attachments_file // ""' < "${payload}")" attachments=$(jq -r '(.params.attachments // null)' < $payload) @@ -82,11 +80,6 @@ fi attachments=$(echo "$attachments" | envsubst) -[[ -n "${channel_file}" && -f "${channel_file}" ]] && channels="${channels} $(cat "${channel_file}")" - -for channel in ${channels} -do - debug_info="" metadata="" body="" @@ -127,7 +120,6 @@ then [[ "${username}" != "null" ]] && username="$(eval "printf ${username}" | jq -R -s .)" [[ "${icon_url}" != "null" ]] && icon_url="$(eval "printf ${icon_url}" | jq -R -s .)" [[ "${icon_emoji}" != "null" ]] && icon_emoji="$(eval "printf ${icon_emoji}" | jq -R -s .)" - [[ "${channel}" != "null" ]] && channel=\"${channel}\" && channel="$(eval "printf ${channel}" | jq -R -s .)" body="$(cat <&2 + cat <&2 ------------------------------------------------------------------------------ TESTING: $1 @@ -28,11 +28,13 @@ Input: $(cat ${base_dir}/${1}.out) Output: -EOM +EOF result="$(cd $base_dir && cat ${1}.out | $cmd . 2>&1 | tee /dev/stderr)" - echo >&2 "" - echo >&2 "Result:" + cat <&2 + +Result: +EOF echo "$result" # to be passed into jq -e } @@ -50,77 +52,71 @@ username="concourse" test combined_text_template_and_file | jq -e " .webhook_url == $(echo $webhook_url | jq -R .) and - .body.channel == null and .body.icon_url == null and .body.icon_emoji == null and .body.link_names == false and .body.username == $(echo $username | jq -R .) and .body.text == \"${base_text}\n${sample_text}\" and .body.attachments == null and - ( .body | keys | contains([\"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and - ( .body | keys | length == 7 )" + ( .body | keys | contains([\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and + ( .body | keys | length == 6 )" test combined_text_template_and_file_empty | jq -e " .webhook_url == $(echo $webhook_url | jq -R .) and - .body.channel == null and .body.icon_url == null and .body.icon_emoji == null and .body.link_names == false and .body.username == $(echo $username | jq -R .) and .body.text == \"${base_text}\n${missing_text}\n\" and .body.attachments == null and - ( .body | keys | contains([\"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and - ( .body | keys | length == 7 )" + ( .body | keys | contains([\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and + ( .body | keys | length == 6 )" test combined_text_template_and_file_missing | jq -e " .webhook_url == $(echo $webhook_url | jq -R .) and - .body.channel == null and .body.icon_url == null and .body.icon_emoji == null and .body.link_names == false and .body.username == $(echo $username | jq -R .) and .body.text == \"${base_text}\n${missing_text}\n\" and .body.attachments == null and - ( .body | keys | contains([\"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and - ( .body | keys | length == 7 )" + ( .body | keys | contains([\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and + ( .body | keys | length == 6 )" test text | jq -e " .webhook_url == $(echo $webhook_url | jq -R .) and - .body.channel == null and .body.icon_url == null and .body.icon_emoji == null and .body.link_names == false and .body.username == $(echo $username | jq -R .) and .body.text == \"Inline static \`text\`\n\" and .body.attachments == null and - ( .body | keys | contains([\"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and - ( .body | keys | length == 7 )" + ( .body | keys | contains([\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and + ( .body | keys | length == 6 )" test text_file | jq -e " .webhook_url == $(echo $webhook_url | jq -R .) and - .body.channel == null and .body.icon_url == null and .body.icon_emoji == null and .body.link_names == false and .body.username == $(echo $username | jq -R .) and .body.text == \"${sample_text}\" and .body.attachments == null and - ( .body | keys | contains([\"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and - ( .body | keys | length == 7 )" + ( .body | keys | contains([\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and + ( .body | keys | length == 6 )" test text_file_empty | jq -e " .webhook_url == $(echo $webhook_url | jq -R .) and - .body.channel == null and .body.icon_url == null and .body.icon_emoji == null and .body.link_names == false and .body.username == $(echo $username | jq -R .) and .body.text == \"${missing_text}\n\" and .body.attachments == null and - ( .body | keys | contains([\"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and - ( .body | keys | length == 7 )" + ( .body | keys | contains([\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\",\"attachments\"]) ) and + ( .body | keys | length == 6 )" test text_file_empty_suppress | jq -e " ( . | keys | length == 1 ) and @@ -128,25 +124,25 @@ test text_file_empty_suppress | jq -e " ( .version | keys == [\"timestamp\"] )" test metadata | jq -e " - ( .version | keys == [\"timestamp\"] ) and - ( .metadata[0].name == \"url\" ) and ( .metadata[0].value == \"https://hooks.slack.com/services/TH…IS/DO…ES/WO…RK\" ) and - ( .metadata[1].name == \"channel\" ) and ( .metadata[1].value == \"#some_channel\" ) and - ( .metadata[2].name == \"username\" ) and ( .metadata[2].value == \"concourse\" ) and - ( .metadata[3].name == \"text\" ) and ( .metadata[3].value == \"Inline static text\n\" ) and - ( .metadata[4].name == \"text_file\" ) and ( .metadata[4].value == \"\" ) and - ( .metadata[5].name == \"text_file_exists\" ) and ( .metadata[5].value == \"No\" ) and - ( .metadata | length == 7 )" + ( .version | keys == [\"timestamp\"] ) and + ( .metadata[0].name == \"url\" ) and ( .metadata[0].value == \"https://hooks.slack.com/services/TH…IS/DO…ES/WO…RK\" ) and + ( .metadata[1].name == \"username\" ) and ( .metadata[1].value == \"concourse\" ) and + ( .metadata[2].name == \"text\" ) and ( .metadata[2].value == \"Inline static text\n\" ) and + ( .metadata[3].name == \"text_file\" ) and ( .metadata[3].value == \"\" ) and + ( .metadata[4].name == \"text_file_exists\" ) and ( .metadata[4].value == \"No\" ) and + ( .metadata[5].name == \"text_file_content\" ) and ( .metadata[5].value == \"_(no notification provided)_\\n\" ) and + ( .metadata | length == 6 )" test metadata_with_payload | jq -e " - ( .version | keys == [\"timestamp\"] ) and - ( .metadata[0].name == \"url\" ) and ( .metadata[0].value == \"https://hooks.slack.com/services/TH…IS/DO…ES/WO…RK\" ) and - ( .metadata[1].name == \"channel\" ) and ( .metadata[1].value == \"#some_channel\" ) and - ( .metadata[2].name == \"username\" ) and ( .metadata[2].value == \"concourse\" ) and - ( .metadata[3].name == \"text\" ) and ( .metadata[3].value == \"Inline static text\n\" ) and - ( .metadata[4].name == \"text_file\" ) and ( .metadata[4].value == \"\" ) and - ( .metadata[5].name == \"text_file_exists\" ) and ( .metadata[5].value == \"No\" ) and - ( .metadata[7].name == \"payload\" ) and ( .metadata[7].value | fromjson.source.url == \"***REDACTED***\" ) and - ( .metadata | length == 8 )" + ( .version | keys == [\"timestamp\"] ) and + ( .metadata[0].name == \"url\" ) and ( .metadata[0].value == \"https://hooks.slack.com/services/TH…IS/DO…ES/WO…RK\" ) and + ( .metadata[1].name == \"username\" ) and ( .metadata[1].value == \"concourse\" ) and + ( .metadata[2].name == \"text\" ) and ( .metadata[2].value == \"Inline static text\n\" ) and + ( .metadata[3].name == \"text_file\" ) and ( .metadata[3].value == \"\" ) and + ( .metadata[4].name == \"text_file_exists\" ) and ( .metadata[4].value == \"No\" ) and + ( .metadata[5].name == \"text_file_content\" ) and ( .metadata[5].value == \"_(no notification provided)_\\n\" ) and + ( .metadata[6].name == \"payload\" ) and ( .metadata[6].value | fromjson.source.url == \"***REDACTED***\" ) and + ( .metadata | length == 7 )" test attachments_no_text | jq -e " .body.text == null and @@ -184,18 +180,6 @@ test no_attachments_with_text_and_attachments_file | jq -e " .body.attachments[0].text == \"Build my-build passed!\" and ( .body.attachments | length == 1 )" -test multiple_channels | jq -e " - .webhook_url == $(echo $webhook_url | jq -R .) and - .body.channel == \"#another_channel\" and - .body.icon_url == null and - .body.icon_emoji == null and - .body.link_names == false and - .body.username == $(echo $username | jq -R .) and - .body.text == \"Inline static text\n\" and - ( .body | keys | contains([\"attachments\", \"channel\",\"icon_emoji\",\"icon_url\",\"username\",\"link_names\",\"text\"]) ) and - ( .body | keys | length == 7 ) and - .body.attachments == null" - test env_file | jq -e " .body.text == \"Inline static text\n\" and .body.attachments[0].color == \"danger\" and diff --git a/test/metadata.out b/test/metadata.out index f7d7a4a..049016e 100644 --- a/test/metadata.out +++ b/test/metadata.out @@ -2,7 +2,6 @@ "params": { "text": "Inline static text", "username": "concourse", - "channel": "#some_channel", "debug": "true", "metadata": "true" }, diff --git a/test/multiple_channels.out b/test/multiple_channels.out deleted file mode 100644 index 8182ca8..0000000 --- a/test/multiple_channels.out +++ /dev/null @@ -1,11 +0,0 @@ -{ - "params": { - "text": "Inline static text", - "username": "concourse", - "debug": "true", - "channel": "#some_channel #another_channel" - }, - "source": { - "url": "https://some.url" - } -}