Skip to content

Commit

Permalink
Merge pull request #31 from JustArchi/master
Browse files Browse the repository at this point in the history
Add functionality to send event to multiple addresses at once
  • Loading branch information
iamtraction authored Oct 6, 2020
2 parents 5c63a3c + 922dd90 commit bb9c0af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ just follow the guide below and stay notified of your build status.

1. Go to your repository settings (for which you want status notifications)
in Travis CI and add an environment variable called `WEBHOOK_URL` and paste
the **Webhook URL** you got in the previous step.
the **Webhook URL** you got in the previous step. You can also specify
multiple webhook addresses at once, separating each with a whitespace
character, such as space.

![Add environment variable in Travis CI](https://i.imgur.com/UfXIoZn.png)

Expand Down
18 changes: 11 additions & 7 deletions send.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/bin/bash

if [ -z "$2" ]; then
echo -e "WARNING!!\nYou need to pass the WEBHOOK_URL environment variable as the second argument to this script.\nFor details & guide, visit: https://github.com/DiscordHooks/travis-ci-discord-webhook" && exit
fi

echo -e "[Webhook]: Sending webhook to Discord...\\n";

case $1 in
"success" )
EMBED_COLOR=3066993
Expand All @@ -26,6 +20,12 @@ case $1 in
;;
esac

shift

if [ $# -lt 1 ]; then
echo -e "WARNING!!\nYou need to pass the WEBHOOK_URL environment variable as the second argument to this script.\nFor details & guide, visit: https://github.com/DiscordHooks/travis-ci-discord-webhook" && exit
fi

AUTHOR_NAME="$(git log -1 "$TRAVIS_COMMIT" --pretty="%aN")"
COMMITTER_NAME="$(git log -1 "$TRAVIS_COMMIT" --pretty="%cN")"
COMMIT_SUBJECT="$(git log -1 "$TRAVIS_COMMIT" --pretty="%s")"
Expand Down Expand Up @@ -83,5 +83,9 @@ WEBHOOK_DATA='{
} ]
}'

(curl --fail --progress-bar -A "TravisCI-Webhook" -H Content-Type:application/json -H X-Author:k3rn31p4nic#8383 -d "${WEBHOOK_DATA// / }" "$2" \
for ARG in "$@"; do
echo -e "[Webhook]: Sending webhook to Discord...\\n";

(curl --fail --progress-bar -A "TravisCI-Webhook" -H Content-Type:application/json -H X-Author:k3rn31p4nic#8383 -d "${WEBHOOK_DATA// / }" "$ARG" \
&& echo -e "\\n[Webhook]: Successfully sent the webhook.") || echo -e "\\n[Webhook]: Unable to send webhook."
done

0 comments on commit bb9c0af

Please sign in to comment.