forked from glenAshley/dokku-slack
-
Notifications
You must be signed in to change notification settings - Fork 2
/
receive-app
executable file
·52 lines (43 loc) · 991 Bytes
/
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
52
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"
main() {
local app="$1"
local rev="$2"
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)
local commit=$(git log --format=%B -n 1 ${rev})
cat <<JSON
{
"username": "Deploy: ${app}@${hostname}",
"icon_emoji": ":building_construction:",
"text": "Building revision ${rev} (${commit})"
}
JSON
}
main $@