forked from mspanc/dokku-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands
executable file
·78 lines (62 loc) · 1.42 KB
/
commands
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(dirname $0)/../common/functions"
main() {
case "$1" in
slack:set)
slack_set "$2" "$3"
;;
slack:clear)
slack_clear "$2"
;;
slack:get)
slack_get "$2"
;;
help)
slack_usage
;;
esac
}
slack_usage() {
cat >&2 <<USAGE
slack:set <app> <webhook>, Enable Slack notifications for app.
slack:clear <app>, Disable Slack notifications for app.
slack:get <app>, Print Slack notification settings for app.
USAGE
}
slack_set() {
local app="$1"
local webhook="$2"
if [[ -z "${app}" ]] || [[ -z "${webhook}" ]]; then
slack_usage
exit 1
fi
verify_app_name "${app}"
dokku_log_info1 "Enabling Slack notifications for ${app}"
echo "${webhook}" > "${DOKKU_ROOT}/${app}/SLACK_WEBHOOK"
}
slack_clear() {
local app="$1"
if [[ -z "${app}" ]]; then
slack_usage
exit 1
fi
verify_app_name "${app}"
dokku_log_info1 "Disabling Slack notifications for ${app}"
rm -f "${DOKKU_ROOT}/${app}/SLACK_WEBHOOK"
}
slack_get() {
local app="$1"
if [[ -z "${app}" ]]; then
slack_usage
exit 1
fi
verify_app_name "${app}"
local file="${DOKKU_ROOT}/${app}/SLACK_WEBHOOK"
if [[ -s "${file}" ]]; then
dokku_log_info1 "Slack notifications set for ${app} (webhook: $(cat "${file}"))"
else
dokku_log_info1 "Slack notifications cleared for ${app}"
fi
}
main $@