This repository has been archived by the owner on Sep 9, 2022. It is now read-only.
/
rule-add.R
62 lines (60 loc) · 2.22 KB
/
rule-add.R
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
#' @export
#' @rdname cchn_rules
cchn_rules_add <- function(rules, email, quiet = FALSE, ...) {
if (!is.null(email)) valid_email(email)
if (is.null(email)) email <- get_email(quiet = quiet)
email_token_check(email)
assert(rules, "list")
# check each rule
rule_names <- c("package", "status", "time", "platforms", "regex")
for (i in seq_along(rules)) {
if (!inherits(rules[[i]], "list"))
stop("each element of `rules` must be a list", call. = FALSE)
if (!all(names(rules[[i]]) %in% rule_names)) {
stop("one or more names in the list not in acceptable set: ",
paste0(rule_names, collapse = ", "),
call. = FALSE)
}
}
out <- ccc_POST("notifications/rules", body = rules, email = email, ...)
if (!quiet) {
for (i in seq_along(rules)) {
mssg2(rules[[i]]$package, rule = jsonlite::toJSON(rules[[i]],
auto_unbox = TRUE))
cat("\n")
}
mssg_get_rules()
}
return(cch_parse(out, TRUE))
}
#' @export
#' @rdname cchn_rules
cchn_pkg_rule_add <- function(status = NULL, platform = NULL,
time = NULL, regex = NULL, package = NULL, email = NULL,
path = ".", quiet = FALSE, ...) {
if (is.null(email)) email <- get_maintainer_email(path)
package <- package_name(package, path = path)
rule_add(package, status, platform, time, regex, email, quiet, ...)
}
#' @export
#' @rdname cchn_rules
cchn_rule_add <- function(package, status = NULL, platform = NULL,
time = NULL, regex = NULL, email = NULL, quiet = FALSE, ...) {
if (is.null(email)) email <- get_email(quiet = quiet)
rule_add(package, status, platform, time, regex, email, quiet, ...)
}
rule_add <- function(package, status, platform, time, regex, email, quiet, ...) {
valid_email(email)
email_token_check(email)
assert(package, "character")
assert(status, "character")
assert(platform, c("numeric", "integer", "character"))
assert(time, c("numeric", "integer"))
assert(regex, "character")
assert(quiet, "logical")
body <- ct(list(package = package, status = status, platforms = platform,
time = time, regex = regex))
out <- ccc_POST("notifications/rules", body = list(body), email = email, ...)
if (!quiet) mssg(package, rule = jsonlite::toJSON(body, auto_unbox = TRUE))
return(cch_parse(out, TRUE))
}