forked from glenAshley/dokku-slack
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpre-receive-app
executable file
·51 lines (42 loc) · 915 Bytes
/
pre-receive-app
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"
main() {
local app="$1"
local rev="$4"
slack_notify "${app}" "${rev}"
}
slack_notify() {
local app="$1"
local rev="$2"
local file="${DOKKU_ROOT}/${app}/SLACK_WEBHOOK"
if [[ ! -s "${file}" ]]; then
return 0
fi
local webhook="$(cat "${file}")"
local payload="$(slack_payload "${app}" "${rev}")"
dokku_log_info1 "Notifying Slack ..."
curl \
--request "POST" \
--silent \
--fail \
--show-error \
--location \
--output "/dev/null" \
--header "Content-Type: application/json" \
--data "${payload}" \
"${webhook}"
}
slack_payload() {
local app="$1"
local rev="$2"
local hostname=$(hostname)
cat <<JSON
{
"username": "Deploy: ${app}@${hostname}",
"icon_emoji": ":rocket:",
"text": "Deploying revision ${rev}"
}
JSON
}
main $@