-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Automatically extract Posit versions (#31)
- Loading branch information
1 parent
9b0478f
commit 84e23b5
Showing
16 changed files
with
359 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Type: Package | ||
Package: audit.base | ||
Title: Base package for Posit Checks | ||
Version: 0.6.16 | ||
Version: 0.6.17 | ||
Authors@R: | ||
person("Jumping", "Rivers", , "[email protected]", role = c("aut", "cre")) | ||
Description: Base package for sharing classes between posit audit | ||
|
@@ -25,6 +25,7 @@ Imports: | |
yaml | ||
Suggests: | ||
jsonlite, | ||
rvest, | ||
testthat (>= 3.0.0) | ||
Remotes: | ||
jumpingrivers/serverHeaders | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
get_posit_remote_versions = function(type = c("connect", "workbench")) { | ||
type = match.arg(type) | ||
url = if (type == "connect") "https://docs.posit.co/connect/news/" | ||
else "https://docs.posit.co/ide/news/" | ||
page = rvest::read_html(url) | ||
sections = rvest::html_elements(page, "section") | ||
v_tibbles = purrr::map_df(sections, extract_posit_cves) | ||
all_v = get_all_remote_versions(page) |> | ||
dplyr::filter(!.data$version %in% v_tibbles$version) %>% | ||
dplyr::bind_rows(v_tibbles) %>% | ||
dplyr::arrange(dplyr::desc(.data$version)) | ||
all_v | ||
} | ||
|
||
extract_posit_cves = function(section) { | ||
posit_name = rvest::html_attrs(section) | ||
posit_name = as.vector(posit_name["id"]) | ||
posit_version = stringr::str_extract(posit_name, "[0-9]{4}\\.[0-9]{1,2}\\.[0-9]{1,2}") | ||
|
||
li = section %>% | ||
rvest::html_elements("li") %>% | ||
rvest::html_text2() | ||
|
||
cves = stringr::str_extract(li, "^CVE-[0-9]{4}-[0-9]*") | ||
cves = cves[!is.na(cves)] | ||
|
||
if (length(cves) == 0L || is.na(posit_version)) { | ||
tibble::tibble(version = character(0), cve = character(0)) | ||
} else { | ||
tibble::tibble(version = posit_version, cve = cves) | ||
} | ||
} | ||
|
||
get_all_remote_versions = function(page) { | ||
versions = page %>% | ||
rvest::html_nodes("h2") %>% | ||
rvest::html_text() | ||
v = stringr::str_extract(versions, "202[0-9]\\.[0-9]{2}\\.[0-9]{1,2}") | ||
tibble::tibble(version = v[!is.na(v)], cve = "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#' Helper functions for updating R/Py/Quarto/Posit versions | ||
#' | ||
#' Currently this function would only be called by the package author, as it | ||
#' updates inst/extdata/versions/*.csv | ||
#' @export | ||
update_all_versions = function() { | ||
readr::write_csv( | ||
get_posit_remote_versions(type = "connect"), | ||
file = "inst/extdata/versions/connect.csv" | ||
) | ||
|
||
readr::write_csv( | ||
get_posit_remote_versions(type = "workbench"), | ||
file = "inst/extdata/versions/workbench.csv" | ||
) | ||
|
||
software = create_software_tibble() | ||
readr::write_csv(software, file = "inst/extdata/versions/software.csv") | ||
return(invisible(NULL)) | ||
} |
Oops, something went wrong.