Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
73bbe25d
Unverified
Commit
73bbe25d
authored
May 13, 2019
by
Honza Hommer
Browse files
add slack notify
parent
7625d662
Changes
1
Show whitespace changes
Inline
Side-by-side
notify/slack.sh
View file @
73bbe25d
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#Support Slack webhooks
#Support Slack webhooks
#SLACK_WEBHOOK_URL=""
#SLACK_WEBHOOK_URL=""
#SLACK_CHANNEL=""
#SLACK_USERNAME=""
slack_send
()
{
slack_send
()
{
_subject
=
"
$1
"
_subject
=
"
$1
"
...
@@ -18,23 +20,36 @@ slack_send() {
...
@@ -18,23 +20,36 @@ slack_send() {
fi
fi
_saveaccountconf_mutable SLACK_WEBHOOK_URL
"
$SLACK_WEBHOOK_URL
"
_saveaccountconf_mutable SLACK_WEBHOOK_URL
"
$SLACK_WEBHOOK_URL
"
export
_H1
=
"Content-Type: application/json"
SLACK_CHANNEL
=
"
${
SLACK_CHANNEL
:-
$(
_readaccountconf_mutable SLACK_CHANNEL
)
}
"
if
[
-n
"
$SLACK_CHANNEL
"
]
;
then
_saveaccountconf_mutable SLACK_CHANNEL
"
$SLACK_CHANNEL
"
fi
SLACK_USERNAME
=
"
${
SLACK_USERNAME
:-
$(
_readaccountconf_mutable SLACK_USERNAME
)
}
"
if
[
-n
"
$SLACK_USERNAME
"
]
;
then
_saveaccountconf_mutable SLACK_USERNAME
"
$SLACK_USERNAME
"
fi
_content
=
"
$(
echo
"
$_subject
:
$_content
"
| _json_encode
)
"
export
_H1
=
"Content-Type: application/json"
_data
=
"{
\"
text
\"
:
\"
$_content
\"
}"
echo
"
$_content
"
_content
=
"
$(
printf
"*%s*
\n
%s"
"
$_subject
"
"
$_content
"
| _json_encode
)
"
echo
"
$_data
"
_data
=
"{
\"
text
\"
:
\"
$_content
\"
, "
if
[
-n
"
$SLACK_CHANNEL
"
]
;
then
_data
=
"
$_data
\"
channel
\"
:
\"
$SLACK_CHANNEL
\"
, "
fi
if
[
-n
"
$SLACK_USERNAME
"
]
;
then
_data
=
"
$_data
\"
username
\"
:
\"
$SLACK_USERNAME
\"
, "
fi
_data
=
"
$_data
\"
mrkdwn
\"
:
\"
true
\"
}"
if
_post
"
$_data
"
"
$SLACK_WEBHOOK_URL
"
;
then
if
_post
"
$_data
"
"
$SLACK_WEBHOOK_URL
"
;
then
# shellcheck disable=SC2154
# shellcheck disable=SC2154
if
[
-z
"
$response
"
]
;
then
if
[
"
$response
"
=
"ok"
]
;
then
_info
"slack send sccess."
_info
"slack send s
u
ccess."
return
0
return
0
fi
fi
fi
fi
_err
"slack send error."
_err
"slack send error."
_err
"
$response
"
_err
"
$response
"
return
1
return
1
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment