Skip to content
Snippets Groups Projects
Commit 188b0722 authored by Frédéric Grelot's avatar Frédéric Grelot
Browse files

ajout de alert_mattermost_lib (+doc) & ajustement de aloert_mattermost

parent 1597ae13
Branches
Tags
No related merge requests found
#' @title Alert a mattermost server of something
#'
#' @description
#' Function used to send information on something to a mattermost server
#' Function used to send information on something to a mattermost server.
#'
#' @param msg character, the message to be sent.
#' @param server character, the address of the mattermost server
#' @param hook character, the hook to send message
#' @param user character, the username to be used
#' @param alert logical, should the message be sent
#' @param hook character, the hook to send message.
#' @param user character, the username to be used.
#' @param alert logical, should the message be sent.
#'
#' @return nothing
#' @return nothing if alert is `TRUE`, the character command if not.
#'
#' @export
#'
#' @examples
#'
#' \dontrun{
#' alert_mattermost("Sorry for disturbance, this is a test.")
#' }
alert_mattermost = function(
msg,
server = "https://mattermost.g-eau.fr",
hook = "t431oh78k3fcmjtoukr1myy16o",
server,
hook,
user = "floodam.data",
alert = TRUE
) {
if (alert == TRUE) {
command = sprintf(
'curl -i -X POST -H \'Content-Type: application/json\' -d "{\\"username\\":\\"%s\\", \\"text\\":\\"%s\\"}" %s/hooks/%s',
user, paste(msg, collapse = "\n"), server, hook
)
if (alert == TRUE) {
invisible(system(command, ignore.stdout = TRUE, ignore.stderr = TRUE))
} else {
command
}
}
#' @title Alert a mattermost server when a library has been updated
#'
#' @description
#' Function used to send information that a library has been updated to a
#' mattermost server.
#'
#' @param lib character, the library name.
#' @param ver character, the new version of the library.
#' @param url_address character, where to find some more information on the
#' library.
#' @param server character, the address of the mattermost server.
#' @param hook character, the hook to send message.
#'
#' @return nothing
#'
#' @export
#'
#' @examples
#'
#' \dontrun{
#' alert_mattermost_lib("lib", "new")
#' }
alert_mattermost_lib = function(
lib,
ver,
server,
hook,
url_address = "http://www.floodam.org"
) {
msg = c(
"Hello @all!",
sprintf("**#%s** has been updated to version **%s**.", lib, ver),
sprintf(
"More information in [%s/%s](%s/%s/news)",
gsub(".*//", "", url_address),
lib,
url_address,
lib
)
)
alert_mattermost(msg, server = server, hook = hook)
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment