Skip to content

Commit

Permalink
Rest of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Apr 10, 2024
1 parent c827e3a commit 1e2d1ef
Show file tree
Hide file tree
Showing 8 changed files with 687 additions and 18 deletions.
47 changes: 29 additions & 18 deletions R/rc.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ rc_new_token <- function(email = NULL, token = NULL) {
}

email_add_token(email, token)
cli::cli_alert_success("Added token for {.val email}.", wrap = TRUE)
cli::cli_alert_success("Added token for {.val {email}}.", wrap = TRUE)
cli::cli_alert_info("R-hub tokens are stored at {.path {email_file()}}.")
invisible()
}
Expand Down Expand Up @@ -117,27 +117,29 @@ rc_list_repos <- function(email = NULL) {
rc_submit <- function(path = ".", platforms = NULL, email = NULL,
confirmation = NULL) {

if (isTRUE(confirmation) && !is_interactive()) {
if (!isTRUE(confirmation) && !is_interactive()) {
throw(pkg_error(
"You need to set {.arg confirmation} to {.val TRUE}
to submit packages to R-hub from non-interactive R sessions."
))
}

pkg_name <- desc::desc_get("Package", file = path)[[1]]
if (is.na(pkg_name)) {
tryCatch({
pkg_name <- suppressWarnings(desc::desc_get("Package", file = path)[[1]])
if (is.na(pkg_name)) stop()
}, error = function(e) {
throw(pkg_error(
"Could not query R package name at {.path {path}}.",
i = paste(
"Make sure that {.arg path} is an R package or a directory",
"contaiing an R package."
"containing an R package."
)
))
}
})

email <- email %||% get_maintainer_email(path = path)

platforms <- select_platforms()
platforms <- select_platforms(platforms)

if (is_dir(path)) {
path <- pkgbuild::build(path = path)
Expand Down Expand Up @@ -201,7 +203,6 @@ rc_submit <- function(path = ".", platforms = NULL, email = NULL,
# =========================================================================

guess_email <- function(path = ".", message = TRUE) {
valid <- list_validated_emails2(message = FALSE)
maint <- tryCatch(get_maintainer_email(path), error = function(e) NULL)
if (!is.null(maint)) {
if (message) {
Expand Down Expand Up @@ -246,7 +247,7 @@ get_email_to_validate <- function(path) {
## maintainer address, if any.

valid <- list_validated_emails2(msg_if_empty = FALSE)
guess <- email_address()
guess <- tryCatch(email_address(), error = function(e) NULL)
maint <- tryCatch(get_maintainer_email(path), error = function(e) NULL)

choices <- rbind(
Expand Down Expand Up @@ -292,6 +293,8 @@ get_email_to_validate <- function(path) {
} else {
email <- choices$email[ch]
}

email
}

list_validated_emails2 <- function(message = is_interactive(),
Expand All @@ -303,11 +306,8 @@ list_validated_emails2 <- function(message = is_interactive(),
"R-hub tokens are stored at {.path {email_file()}}."
)
}
read_token_file(file)

structure(
read.csv(file, stringsAsFactors = FALSE, header = FALSE),
names = c("email", "token")
)
} else {
data.frame(
email = character(),
Expand All @@ -332,7 +332,7 @@ email_file <- function() {
file.path(rhub_data_dir, "validated_emails.csv")
}

rc_new_token_interactive <- function(email, token, path = ".") {
rc_new_token_interactive <- function(email = NULL, token = NULL, path = ".") {

if (is.null(email)) email <- get_email_to_validate(path)

Expand Down Expand Up @@ -379,13 +379,24 @@ email_add_token <- function(email, token) {
tokens[match(email, tokens[,1]), 2] <- token
}

write_token_file(tokens, file)

invisible()
}

read_token_file <- function(path) {
structure(
read.csv(path, stringsAsFactors = FALSE, header = FALSE),
names = c("email", "token")
)
}

write_token_file <- function(tokens, path) {
write.table(
tokens,
file = file,
file = path,
sep = ",",
col.names = FALSE,
row.names = FALSE
)

invisible()
}
}
Loading

0 comments on commit 1e2d1ef

Please sign in to comment.