From bb06d97977cea8dcc0182b0d682d2c4e6eac5adb Mon Sep 17 00:00:00 2001 From: Jim Hester Date: Tue, 3 Sep 2019 14:16:01 -0400 Subject: [PATCH] Add an email argument to check_win This adds a desc dependency, but we already have it implicitly via usethis. Fixes #1723 --- DESCRIPTION | 1 + NEWS.md | 3 +++ R/check-win.R | 46 +++++++++++++++++++++++++++++++++++++++------- man/check_win.Rd | 9 ++++++--- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index aa724825b..a2c18a1ad 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,6 +19,7 @@ Depends: Imports: callr, cli, + desc, digest, DT, ellipsis, diff --git a/NEWS.md b/NEWS.md index f24597f2e..e727e3da2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/check-win.R b/R/check-win.R index 4ababc301..a538251ee 100644 --- a/R/check-win.R +++ b/R/check-win.R @@ -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 @@ -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) { @@ -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() +} diff --git a/man/check_win.Rd b/man/check_win.Rd index 61302ed11..ae57e4b31 100644 --- a/man/check_win.Rd +++ b/man/check_win.Rd @@ -8,13 +8,13 @@ \title{Build windows binary package.} \usage{ check_win_devel(pkg = ".", args = NULL, manual = TRUE, - quiet = FALSE, ...) + email = NULL, quiet = FALSE, ...) check_win_release(pkg = ".", args = NULL, manual = TRUE, - quiet = FALSE, ...) + email = NULL, quiet = FALSE, ...) check_win_oldrelease(pkg = ".", args = NULL, manual = TRUE, - quiet = FALSE, ...) + email = NULL, quiet = FALSE, ...) } \arguments{ \item{pkg}{package description, can be path or package name. See @@ -27,6 +27,9 @@ or \code{R CMD install} if \code{binary = TRUE}.} \item{manual}{For source packages: if \code{FALSE}, don't build PDF vignettes (\code{--no-build-vignettes}) or manual (\code{--no-manual}).} +\item{email}{An alternative email to use, default \code{NULL} uses the package +Maintainer's email.} + \item{quiet}{If \code{TRUE}, suppresses output.} \item{...}{Additional arguments passed to \code{\link[pkgbuild:build]{pkgbuild::build()}}.}