Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
floodam-data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
flood-appraisal
floodam
floodam-data
Commits
188b0722
Commit
188b0722
authored
1 year ago
by
Frédéric Grelot
Browse files
Options
Downloads
Patches
Plain Diff
ajout de alert_mattermost_lib (+doc) & ajustement de aloert_mattermost
parent
1597ae13
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/alert_mattermost.R
+59
-11
59 additions, 11 deletions
R/alert_mattermost.R
with
59 additions
and
11 deletions
R/alert_mattermost.R
+
59
−
11
View file @
188b0722
#' @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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment