Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove references to channels #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -168,8 +165,7 @@ body: {
"text": ":some_emoji:<https://my-ci.my-org.com//teams//main//pipelines//jobs//builds/|Alert!>\n",
"username": "concourse",
"icon_url": null,
"icon_emoji": null,
"channel": null
"icon_emoji": null
}

> cat test/combined_text_template_and_file_missing.out | ./out .
Expand All @@ -178,8 +174,7 @@ body: {
"text": ":some_emoji:<https://my-ci.my-org.com//teams//main//pipelines//jobs//builds/|Alert!>\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 .
Expand All @@ -188,8 +183,7 @@ body: {
"text": ":some_emoji:<https://my-ci.my-org.com//teams//main//pipelines//jobs//builds/|Alert!>\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 .
Expand All @@ -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 .
Expand All @@ -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 .
Expand All @@ -218,8 +210,7 @@ body: {
"text": "Inline static text\n",
"username": "concourse",
"icon_url": null,
"icon_emoji": null,
"channel": null
"icon_emoji": null
}

```
2 changes: 0 additions & 2 deletions ci/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 ))
Expand Down
1 change: 0 additions & 1 deletion ci/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ meta:

slack:
webhook: (( vault "secret/pipelines/slack-notification-resource/slack:webhook" ))
channel: '#botspam'
11 changes: 0 additions & 11 deletions out
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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=""
Expand Down Expand Up @@ -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 <<EOF
{
Expand All @@ -136,7 +128,6 @@ then
"link_names": ${link_names},
"icon_url": ${icon_url},
"icon_emoji": ${icon_emoji},
"channel": ${channel},
"attachments": ${attachments}
}
EOF
Expand Down Expand Up @@ -175,7 +166,6 @@ else
text_interplated="$(echo "" | jq -R -s .)"
fi

done

if [[ "$show_metadata" == "true" ]]
then
Expand All @@ -194,7 +184,6 @@ then
{
"metadata": [
{"name": "url", "value": ${redacted_webhook_url}},
{"name": "channel", "value": "${channels}" },
{"name": "username", "value": ${username} },
{"name": "text", "value": ${text_interpolated} },
{"name": "text_file", "value": $( echo "$text_file" | jq -R . ) },
Expand Down
86 changes: 35 additions & 51 deletions test/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ test() {
cmd="/opt/resource/out"
fi

cat <<EOM >&2
cat <<EOF >&2
------------------------------------------------------------------------------
TESTING: $1

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 <<EOF >&2

Result:
EOF
echo "$result" # to be passed into jq -e
}

Expand All @@ -50,103 +52,97 @@ 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
( . | keys | contains([\"version\"]) ) and
( .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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion test/metadata.out
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"params": {
"text": "Inline static text",
"username": "concourse",
"channel": "#some_channel",
"debug": "true",
"metadata": "true"
},
Expand Down
11 changes: 0 additions & 11 deletions test/multiple_channels.out

This file was deleted.