diff --git a/DESCRIPTION b/DESCRIPTION index c30c58d..553b14c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rang Title: Reconstructing Reproducible R Computational Environments -Version: 0.2.0 +Version: 0.2.1 Authors@R: c(person("Chung-hong", "Chan", , "chainsawtiney@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6232-7530")), diff --git a/R/memo_misc.R b/R/memo_misc.R index c8b3262..9a2da1f 100644 --- a/R/memo_misc.R +++ b/R/memo_misc.R @@ -5,7 +5,25 @@ NULL ## one hr -.memo_search <- memoise::memoise(pkgsearch::cran_package_history, cache = cachem::cache_mem(max_age = 60 * 60)) +.cran_package_history <- function(package, max_retries = 5) { + n_retries <- 0 + while(n_retries < max_retries) { + tryCatch({ + return(pkgsearch::cran_package_history(package)) + }, error = function(e) { + if (grepl("parse error: premature EOF", e$message)) { + n_retries <<- n_retries + 1 + ##message("retrying in 2s...") + Sys.sleep(2) + } else { + stop(e) + } + }) + } + stop("Can't query this package: ", package, call. = FALSE) +} + +.memo_search <- memoise::memoise(.cran_package_history, cache = cachem::cache_mem(max_age = 60 * 60)) .rver <- function() { suppressWarnings(jsonlite::fromJSON(readLines("https://api.r-hub.io/rversions/r-versions"), simplifyVector = TRUE)) diff --git a/R/resolve.R b/R/resolve.R index 3bc7937..a5af2cc 100644 --- a/R/resolve.R +++ b/R/resolve.R @@ -456,17 +456,17 @@ print.rang <- function(x, all_pkgs = FALSE, ...) { return(res) } -.gh <- function(path,ref = NULL,...){ +.gh <- function(path,ref = NULL,...) { url <- httr::parse_url("https://api.github.com/") url <- httr::modify_url(url, path = path) token <- Sys.getenv("GITHUB_PAT", NA_character_) - if(is.na(token)){ + if(is.na(token)) { token <- Sys.getenv("GITHUB_TOKEN", NA_character_) } - if(is.na(token)){ + if(is.na(token)) { token <- "" } - config <- httr::add_headers(Accept = "application/vnd.github.v3+json",Authorization=token) + config <- httr::add_headers(Accept = "application/vnd.github.v3+json", Authorization = paste0("token ", token)) params <- list(ref = ref,...) request_results <- httr::GET(httr::modify_url(url, path = path), config, query = params) status_code <- httr::status_code(request_results) diff --git a/tests/testthat/test_resolve.R b/tests/testthat/test_resolve.R index 99bfc3b..44f23a6 100644 --- a/tests/testthat/test_resolve.R +++ b/tests/testthat/test_resolve.R @@ -146,6 +146,8 @@ test_that("Non-cran must enforce caching ref #22", { ## }) test_that("Integration of as_pkgrefs() in resolve() for sessionInfo()", { + skip_if_offline() + skip_on_cran() x <- resolve(c("cran::sna"), snapshot_date = "2020-05-01", query_sysreqs = FALSE) si <- readRDS("../testdata/sessionInfo2.RDS") expect_error(graph <- resolve(si, snapshot_date = "2020-05-01", query_sysreqs = FALSE), NA)