diff --git a/DESCRIPTION b/DESCRIPTION index 0da0763..256f94b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -28,7 +28,6 @@ Authors@R: c( Depends: R (>= 3.6) Imports: - gert, gh, igraph, jsonlite, @@ -39,6 +38,7 @@ Imports: vctrs, yaml Suggests: + gert, testthat (>= 3.0.0) Encoding: UTF-8 Language: en-US diff --git a/NAMESPACE b/NAMESPACE index 6a10a10..7be3fcd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,7 +19,6 @@ export(review_pull_requests) export(staging_is_active) export(try_message) export(update_staging) -importFrom(gert,git_clone) importFrom(gh,gh) importFrom(igraph,V) importFrom(igraph,graph) @@ -36,6 +35,7 @@ importFrom(pkgsearch,cran_package) importFrom(stats,aggregate) importFrom(utils,available.packages) importFrom(utils,compareVersion) +importFrom(utils,unzip) importFrom(vctrs,vec_rbind) importFrom(vctrs,vec_slice) importFrom(yaml,read_yaml) diff --git a/R/issues_descriptions.R b/R/issues_descriptions.R index 2b2de78..e00641a 100644 --- a/R/issues_descriptions.R +++ b/R/issues_descriptions.R @@ -29,7 +29,7 @@ issues_descriptions <- function(meta = meta_packages()) { } issues_descriptions_advisories <- function(meta) { - advisories <- read_advisories() + advisories <- read_advisories(timeout = 60000L, retries = 3L) meta <- merge( x = meta, y = advisories, @@ -48,19 +48,28 @@ issues_descriptions_remotes <- function(meta) { meta } -read_advisories <- function() { +read_advisories <- function(timeout, retries) { path <- tempfile() + dir.create(path) on.exit(unlink(path, recursive = TRUE, force = TRUE)) - gert::git_clone( - url = "https://github.com/RConsortium/r-advisory-database", - path = path, - verbose = FALSE - ) - advisories <- list.files( - file.path(path, "vulns"), - recursive = TRUE, - full.names = TRUE - ) + zipfile <- file.path(path, "file.zip") + for (i in seq_len(retries)) { + res <- nanonext::ncurl( + "https://github.com/RConsortium/r-advisory-database/zipball/main", + convert = FALSE, + follow = TRUE, + timeout = timeout + ) + res[["status"]] == 200L && break + i == retries && stop( + "Obtaining advisories from R Consortium database failed with status: ", + status_code(res[["status"]]), + call. = FALSE + ) + } + writeBin(res[["data"]], zipfile) + unzip(zipfile, exdir = path, junkpaths = TRUE) + advisories <- Sys.glob(file.path(path, "RSEC*.yaml")) out <- do.call(vctrs::vec_rbind, lapply(advisories, read_advisory)) stats::aggregate(x = advisories ~ package + version, data = out, FUN = list) } diff --git a/R/package.R b/R/package.R index c17fbfa..a100aea 100644 --- a/R/package.R +++ b/R/package.R @@ -1,11 +1,10 @@ -#' @importFrom gert git_clone #' @importFrom gh gh #' @importFrom igraph graph neighbors subcomponent V #' @importFrom jsonlite parse_json read_json stream_in write_json #' @importFrom nanonext ncurl parse_url status_code #' @importFrom pkgsearch cran_package #' @importFrom stats aggregate -#' @importFrom utils available.packages compareVersion +#' @importFrom utils available.packages compareVersion unzip #' @importFrom vctrs vec_rbind vec_slice #' @importFrom yaml read_yaml NULL