diff --git a/NEWS.md b/NEWS.md index a85b0ff5f..d56571420 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # devtools (development version) +* `dr_devtools()` now uses the same endpoint to detect the current RStudio + version as the IDE (#2050). + * `release()` now works again when `pkg` is not the current working directory (#1974). diff --git a/R/doctor.R b/R/doctor.R index bcb7fddd5..de65004e6 100644 --- a/R/doctor.R +++ b/R/doctor.R @@ -2,16 +2,39 @@ #' @importFrom memoise memoise NULL -.rstudio_release <- function() { - url <- "http://s3.amazonaws.com/rstudio-desktop/current.ver" - res <- readLines(url, warn = FALSE) - if (length(res) != 1) { - return(0) +check_for_rstudio_updates <- function(os = tolower(Sys.info()[["sysname"]]), version = rstudioapi::getVersion(), in_rstudio = rstudioapi::isAvailable()) { + + if (!in_rstudio) { + return() } - numeric_version(res) -} -rstudio_release <- memoise::memoise(.rstudio_release) + url <- sprintf("https://www.rstudio.org/links/check_for_update?version=%s&os=%s&format=kvp", version, os, "kvp") + + tmp <- tempfile() + on.exit(unlink(tmp)) + utils::download.file(url, tmp, quiet = TRUE) + result <- readLines(tmp, warn = FALSE) + + result <- strsplit(result, "&")[[1]] + + result <- strsplit(result, "=") + + # If no values then we are current + if (length(result[[1]]) == 1) { + return() + } + + nms <- vcapply(result, `[[`, 1) + values <- vcapply(result, function(x) URLdecode(x[[2]])) + + result <- stats::setNames(values, nms) + + if (!nzchar(result[["update-version"]])) { + return() + } + + sprintf("* RStudio is out of date, %s. Download at: %s", result[["update-message"]], result[["update-url"]]) +} .r_release <- function() { check_suggested("rversions") @@ -51,16 +74,7 @@ dr_devtools <- function() { ) } - if (rstudioapi::isAvailable()) { - rel <- rstudio_release() - cur <- rstudioapi::getVersion() - - if (cur < rel) { - msg[["rstudio"]] <- paste0( - "* RStudio is out of date (", cur, " vs ", rel, ")" - ) - } - } + msg[["rstudio"]] <- check_for_rstudio_updates("mac", "1.0.0", TRUE) doctor("devtools", msg) } diff --git a/R/utils.R b/R/utils.R index c280478ff..05b91774a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -174,3 +174,7 @@ escape_special_regex <- function(x) { has_dev_remotes <- function(pkg) { !is.null(pkg[["remotes"]]) } + +vcapply <- function(x, FUN, ...) { + vapply(x, FUN, FUN.VALUE = character(1), ...) +} diff --git a/tests/testthat/test-doctor.R b/tests/testthat/test-doctor.R new file mode 100644 index 000000000..06caf8201 --- /dev/null +++ b/tests/testthat/test-doctor.R @@ -0,0 +1,12 @@ +test_that("check_for_rstudio_updates", { + # returns nothing rstudio not available + expect_null(check_for_rstudio_updates("mac", "1.0.0", FALSE)) + + # returns nothing if the version is ahead of the current version + expect_null(check_for_rstudio_updates("mac", "1000.0.0", TRUE)) + + # returns something if the version is behind of the current version + res <- check_for_rstudio_updates("mac", "0.0.1", TRUE) + expect_match(res, "RStudio is out of date") + expect_match(res, "Download at") +})