Skip to content

Commit

Permalink
Add an email argument to check_win
Browse files Browse the repository at this point in the history
This adds a desc dependency, but we already have it implicitly via
usethis.

Fixes #1723
  • Loading branch information
jimhester committed Sep 3, 2019
1 parent dd2b777 commit bb06d97
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Depends:
Imports:
callr,
cli,
desc,
digest,
DT,
ellipsis,
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# devtools (development version)

* `check_win_*()` functions gain a `email` argument, so temporarily change the
email the check results will be sent to (#1723).

* `release()` now works without error when `options("repos")` is unnamed (#1956).

* `document()` gains a `quiet` parameter, to silence output and `check()` now
Expand Down
46 changes: 39 additions & 7 deletions R/check-win.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#' @param pkg package description, can be path or package name. See
#' [as.package()] for more information
#' @inheritParams pkgbuild::build
#' @param email An alternative email to use, default `NULL` uses the package
#' Maintainer's email.
#' @param quiet If `TRUE`, suppresses output.
#' @param ... Additional arguments passed to [pkgbuild::build()].
#' @family build functions
Expand All @@ -18,40 +20,52 @@ NULL

#' @describeIn check_win Check package on the development version of R.
#' @export
check_win_devel <- function(pkg = ".", args = NULL, manual = TRUE, quiet = FALSE, ...) {
check_win_devel <- function(pkg = ".", args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
check_dots_used()

check_win(
pkg = pkg, version = "R-devel", args = args, manual = manual,
quiet = quiet, ...
email = email, quiet = quiet, ...
)
}

#' @describeIn check_win Check package on the release version of R.
#' @export
check_win_release <- function(pkg = ".", args = NULL, manual = TRUE, quiet = FALSE, ...) {
check_win_release <- function(pkg = ".", args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
check_dots_used()

check_win(
pkg = pkg, version = "R-release", args = args, manual = manual,
quiet = quiet, ...
email = email, quiet = quiet, ...
)
}

#' @describeIn check_win Check package on the previous major release version of R.
#' @export
check_win_oldrelease <- function(pkg = ".", args = NULL, manual = TRUE, quiet = FALSE, ...) {
check_win_oldrelease <- function(pkg = ".", args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
check_dots_used()

check_win(
pkg = pkg, version = "R-oldrelease", args = args, manual = manual,
quiet = quiet, ...
email = email, quiet = quiet, ...
)
}

check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelease"),
args = NULL, manual = TRUE, quiet = FALSE, ...) {
args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
pkg <- as.package(pkg)

if (!is.null(email)) {
desc_file <- file.path(pkg$path, "DESCRIPTION")
backup <- tempfile()
file.copy(desc_file, backup)
on.exit(file.rename(backup, desc_file), add = TRUE)

change_maintainer_email(desc_file, email)

pkg <- as.package(pkg$path)
}

version <- match.arg(version, several.ok = TRUE)

if (!quiet) {
Expand Down Expand Up @@ -88,3 +102,21 @@ check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelea

invisible()
}

change_maintainer_email <- function(desc, email) {
desc <- desc::desc(file = desc)

if (!desc$has_fields("Authors@R")) {
stop("DESCRIPTION must use `Authors@R` field to change the maintainer email", call. = FALSE)
}
aut <- desc$get_authors()
roles <- aut$role
## Broken person() API, vector for 1 author, list otherwise...
if (!is.list(roles)) roles <- list(roles)
is_maintainer <- vapply(roles, function(r) all("cre" %in% r), logical(1))
aut[is_maintainer]$email <- email

desc$set_authors(aut)

desc$write()
}
9 changes: 6 additions & 3 deletions man/check_win.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb06d97

Please sign in to comment.