Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions R/check-win.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ check_win <- function(
))

email <- maintainer(pkg)$email
if (interactive() && yesno("Email results to {.strong {email}}?")) {
return(invisible())
}
confirm_maintainer_email(email)
}

built_path <- pkgbuild::build(
Expand Down Expand Up @@ -154,6 +152,24 @@ check_win <- function(
invisible()
}

confirm_maintainer_email <- function(email, call = parent.frame()) {
if (!rlang::is_interactive()) {
return(FALSE)
}

if (!yesno("Email results to {.strong {email}}?")) {
return()
}

cli::cli_abort(
c(
"User declined upload.",
i = "Use `email = {.str your email}` to override."
),
call = call
)
}

change_maintainer_email <- function(path, email, call = parent.frame()) {
desc <- desc::desc(file = path)

Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/_snaps/check-win.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@
Error:
! DESCRIPTION can't use Maintainer field when changing `email`

# email confirmation gives useful advice

Code
confirm_maintainer_email("hadley@posit.co")
Message
Email results to hadley@posit.co?
Condition
Error:
! User declined upload.
i Use `email = "your email"` to override.

10 changes: 10 additions & 0 deletions tests/testthat/test-check-win.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ test_that("change_maintainer_email checks fields", {
desc$write(path)
expect_snapshot(change_maintainer_email(path, "x@example.com"), error = TRUE)
})

test_that("email confirmation gives useful advice", {
withr::local_options(rlang_interactive = TRUE)
local_mocked_bindings(yesno = function(msg) {
cli::cli_inform(msg, .envir = parent.frame())
TRUE
})

expect_snapshot(confirm_maintainer_email("hadley@posit.co"), error = TRUE)
})