Skip to content

Commit

Permalink
alternative to cloning repo
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Sep 29, 2024
1 parent 46f0eab commit e37dd6e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Authors@R: c(
Depends:
R (>= 3.6)
Imports:
gert,
gh,
igraph,
jsonlite,
Expand All @@ -39,6 +38,7 @@ Imports:
vctrs,
yaml
Suggests:
gert,
testthat (>= 3.0.0)
Encoding: UTF-8
Language: en-US
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
33 changes: 21 additions & 12 deletions R/issues_descriptions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions R/package.R
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e37dd6e

Please sign in to comment.