Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust to new RStudio version numbering #2410

Merged
merged 8 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
30 changes: 26 additions & 4 deletions R/sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,39 @@
#' @importFrom memoise memoise
NULL

check_for_rstudio_updates <- function(os = tolower(Sys.info()[["sysname"]]), version = rstudioapi::getVersion(), in_rstudio = rstudioapi::isAvailable()) {
rstudio_version_string <- function() {
if (!rstudioapi::isAvailable()) {
return(character())
}
rvi <- rstudioapi::versionInfo()
rvi$long_version %||% as.character(rvi$version)
}

check_for_rstudio_updates <- function(os = tolower(Sys.info()[["sysname"]]),
version = rstudio_version_string(),
in_rstudio = rstudioapi::isAvailable()) {
if (!in_rstudio) {
return()
}

url <- sprintf("https://www.rstudio.org/links/check_for_update?version=%s&os=%s&format=%s", version, os, "kvp")
url <- sprintf(
"https://www.rstudio.org/links/check_for_update?version=%s&os=%s&format=%s&manual=true",
utils::URLencode(version, reserved = TRUE), os, "kvp"
)

tmp <- file_temp()
on.exit(file_delete(tmp))
utils::download.file(url, tmp, quiet = TRUE)
withr::defer(file_exists(tmp) && nzchar(file_delete(tmp)))
suppressWarnings(
download_ok <- tryCatch({
utils::download.file(url, tmp, quiet = TRUE)
TRUE
}, error = function(e) FALSE)
)
if (!download_ok) {
# I'll take silent failure here over dev_sitrep() falling over completely
# if this download fails
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This captures why I've made this function a bit more robust. In general, I think "sitrep" functions should basically never throw an error, because you're often using them to bring clarity to weird, sub-optimal situations.

return()
}
result <- readLines(tmp, warn = FALSE)

result <- strsplit(result, "&")[[1]]
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ test_that("check_for_rstudio_updates", {
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))
# THIS NEEDS AN UPDATE
# expect_null(check_for_rstudio_updates("mac", "1000.0.0", TRUE))

# returns something if the version is behind of the current version
# returns something if the version is behind the current version
res <- check_for_rstudio_updates("mac", "0.0.1", TRUE)
expect_match(res, "RStudio .* is now available")
expect_match(res, "Download at")
Expand Down