~hrbrmstr/vershist

62fb8f955947d48b4be115a2b44f84afd66040c9 — boB Rudis 3 years ago 71a3c9f
caching for a few functions
M R/apache-httpd.R => R/apache-httpd.R +50 -36
@@ 7,8 7,14 @@
#' ordered factor.
#'
#' @md
#' @param refresh if `TRUE` and there `~/.vershist` cache dir exists, will
#'        cause the version history database for apache to be rebuilt. Defaults
#'        to `FALSE` and has no effect if `~/.vershist` cache dir does not exist.
#' @export
apache_httpd_version_history <- function() {
apache_httpd_version_history <- function(refresh = FALSE) {

  tech <- "apache-httpd"
  if (use_cache() && (!refresh) && is_cached(tech)) return(read_from_cache(tech))

  page <- gh::gh("/repos/apache/httpd/tags")



@@ 38,40 44,48 @@ apache_httpd_version_history <- function() {
    ) -> xdf
  }

  dplyr::mutate(xdf, vers = stri_replace_first_fixed(vers, "v", "")) %>%
    dplyr::mutate(rls_date = as.Date(stri_sub(rls_date, 1, 10))) %>%
    dplyr::mutate(rls_year = lubridate::year(rls_date)) %>%
    tidyr::separate(vers, c("major", "minor", "patch", "build"), remove=FALSE) %>%
    dplyr::mutate(prerelease = ifelse(
      stri_detect_regex(build, "[[:alpha:]]"),
      stri_extract_first_regex(build, "[[:alpha:]][[:alnum:]]+"),
      ""
    )) %>%
    dplyr::mutate(build = stri_replace_first_regex(build, "[[:alpha:]][[:alnum:]]+", "")) %>%
    dplyr::mutate_at(.vars=c("major", "minor", "patch", "build"), .funs=c(as.integer)) %>%
    dplyr::add_row(
      vers = "2.0.0",
      rls_date = as.Date("2001-02-09"),
      rls_year = 2001,
      major = 2L, minor = 0L, patch = 0L,
      prerelease = NA_character_, build = NA
    ) %>%
    dplyr::add_row(
      vers = "1.3.37",
      rls_date = as.Date("2006-07-27"),
      rls_year = 2006,
      major = 1L, minor = 3L, patch = 37L,
      prerelease = NA_character_, build = NA
    ) %>%
    dplyr::add_row(
      vers = "1.3.41",
      rls_date = as.Date("2009-10-03"),
      rls_year = 2009,
      major = 1L, minor = 3L, patch = 41L,
      prerelease = NA_character_, build = NA
    ) %>%
    dplyr::arrange(rls_date) %>%
    dplyr::mutate(vers = factor(vers, levels=vers)) %>%
    dplyr::select(vers, rls_date, rls_year, major, minor, patch, prerelease, build) -> out
  suppressWarnings(
    dplyr::mutate(xdf, vers = stri_replace_first_fixed(vers, "v", "")) %>%
      dplyr::mutate(rls_date = as.Date(stri_sub(rls_date, 1, 10))) %>%
      dplyr::mutate(rls_year = lubridate::year(rls_date)) %>%
      tidyr::separate(vers, c("major", "minor", "patch", "build"), remove=FALSE) %>%
      dplyr::mutate(prerelease = ifelse(
        stri_detect_regex(build, "[[:alpha:]]"),
        stri_extract_first_regex(build, "[[:alpha:]][[:alnum:]]+"),
        ""
      )) %>%
      dplyr::mutate(build = stri_replace_first_regex(build, "[[:alpha:]][[:alnum:]]+", "")) %>%
      dplyr::mutate_at(.vars=c("major", "minor", "patch", "build"), .funs=c(as.integer)) %>%
      dplyr::add_row(
        vers = "2.0.0",
        rls_date = as.Date("2001-02-09"),
        rls_year = 2001,
        major = 2L, minor = 0L, patch = 0L,
        prerelease = NA_character_, build = NA
      ) %>%
      dplyr::add_row(
        vers = "1.3.37",
        rls_date = as.Date("2006-07-27"),
        rls_year = 2006,
        major = 1L, minor = 3L, patch = 37L,
        prerelease = NA_character_, build = NA
      ) %>%
      dplyr::add_row(
        vers = "1.3.41",
        rls_date = as.Date("2009-10-03"),
        rls_year = 2009,
        major = 1L, minor = 3L, patch = 41L,
        prerelease = NA_character_, build = NA
      ) %>%
      dplyr::arrange(rls_date) %>%
      dplyr::mutate(vers = factor(vers, levels=vers)) %>%
      dplyr::select(
        vers, rls_date, rls_year, major, minor, patch, prerelease, build
      ) -> out
  )

  if (use_cache() && (refresh || (!is_cached(tech)))) write_to_cache(out, tech)

  out

}
\ No newline at end of file

M R/chrome.R => R/chrome.R +12 -2
@@ 7,10 7,16 @@
#' ordered factor.
#'
#' @md
#' @param refresh if `TRUE` and there `~/.vershist` cache dir exists, will
#'        cause the version history database for apache to be rebuilt. Defaults
#'        to `FALSE` and has no effect if `~/.vershist` cache dir does not exist.
#' @note This _only_ pulls the first release date and does not distinguish by OS.
#'       If more granular data is needed, file an issue or PR.
#' @export
google_chrome_version_history <- function() {
google_chrome_version_history <- function(refresh = FALSE) {

  tech <- "google-chrome"
  if (use_cache() && (!refresh) && is_cached(tech)) return(read_from_cache(tech))

  pg <- xml2::read_html("https://en.wikipedia.org/wiki/Google_Chrome_version_history")



@@ 32,6 38,10 @@ google_chrome_version_history <- function() {
        dplyr::as_tibble()
    ) %>%
    dplyr::arrange(major, minor, patch) %>%
    dplyr::mutate(vers = factor(vers, levels = vers))
    dplyr::mutate(vers = factor(vers, levels = vers)) -> out

  if (use_cache() && (refresh || (!is_cached(tech)))) write_to_cache(out, tech)

  out

}
\ No newline at end of file

M R/nginx.R => R/nginx.R +39 -24
@@ 7,8 7,14 @@
#' ordered factor.
#'
#' @md
#' @param refresh if `TRUE` and there `~/.vershist` cache dir exists, will
#'        cause the version history database for apache to be rebuilt. Defaults
#'        to `FALSE` and has no effect if `~/.vershist` cache dir does not exist.
#' @export
nginx_version_history <- function() {
nginx_version_history <- function(refresh = FALSE) {

  tech <- "nginx"
  if (use_cache() && (!refresh) && is_cached(tech)) return(read_from_cache(tech))

  page <- gh::gh("/repos/nginx/nginx/tags")



@@ 38,27 44,36 @@ nginx_version_history <- function() {
    ) -> xdf
  }

  dplyr::mutate(xdf, vers = stri_replace_first_fixed(vers, "v", "")) %>%
    dplyr::mutate(rls_date = as.Date(stri_sub(rls_date, 1, 10))) %>%
    dplyr::mutate(rls_year = lubridate::year(rls_date)) %>%
    tidyr::separate(vers, c("major", "minor", "patch", "build"), remove=FALSE) %>%
    dplyr::mutate(prerelease = ifelse(
      stri_detect_regex(build, "[[:alpha:]]"),
      stri_extract_first_regex(build, "[[:alpha:]][[:alnum:]]+"),
      ""
    )) %>%
    dplyr::mutate(build = stri_replace_first_regex(build, "[[:alpha:]][[:alnum:]]+", "")) %>%
    dplyr::mutate_at(.vars=c("major", "minor", "patch", "build"), .funs=c(as.integer)) %>%
    dplyr::bind_rows(
      tibble(
        vers = c("1.2.1"),
        rls_date = as.Date(c("2012-06-07")),
        rls_year = lubridate::year(rls_date),
        major = 1L, minor = 2L, patch = 1L,
        prerelease = NA, build = NA
      )
    ) %>%
    dplyr::arrange(major, minor, patch) %>%
    dplyr::mutate(vers = factor(vers, levels=vers)) %>%
    dplyr::select(vers, rls_date, rls_year, major, minor, patch, prerelease, build) -> out
  suppressWarnings(
    dplyr::mutate(xdf, vers = stri_replace_first_fixed(vers, "v", "")) %>%
      dplyr::mutate(rls_date = as.Date(stri_sub(rls_date, 1, 10))) %>%
      dplyr::mutate(rls_year = lubridate::year(rls_date)) %>%
      tidyr::separate(vers, c("major", "minor", "patch", "build"), remove=FALSE) %>%
      dplyr::mutate(prerelease = ifelse(
        stri_detect_regex(build, "[[:alpha:]]"),
        stri_extract_first_regex(build, "[[:alpha:]][[:alnum:]]+"),
        ""
      )) %>%
      dplyr::mutate(build = stri_replace_first_regex(build, "[[:alpha:]][[:alnum:]]+", "")) %>%
      dplyr::mutate_at(.vars=c("major", "minor", "patch", "build"), .funs=c(as.integer)) %>%
      dplyr::bind_rows(
        dplyr::tibble(
          vers = c("1.2.1"),
          rls_date = as.Date(c("2012-06-07")),
          rls_year = lubridate::year(rls_date),
          major = 1L, minor = 2L, patch = 1L,
          prerelease = NA, build = NA
        )
      ) %>%
      dplyr::arrange(major, minor, patch) %>%
      dplyr::mutate(vers = factor(vers, levels=vers)) %>%
      dplyr::select(
        vers, rls_date, rls_year, major, minor, patch, prerelease, build
      ) -> out
  )

  if (use_cache() && (refresh || (!is_cached(tech)))) write_to_cache(out, tech)

  out

}
\ No newline at end of file

M R/utils.R => R/utils.R +17 -0
@@ 32,3 32,20 @@ complete_semver <- function(x, quad = FALSE) {
  })

}

use_cache <- function() {
  dir.exists("~/.vershist")
}

is_cached <- function(tech) {
  dir.exists("~/.vershist") &&
    file.exists(file.path("~/.vershist", sprintf("%s.rds", tech)))
}

read_from_cache <- function(tech) {
  readRDS(file.path("~/.vershist", sprintf("%s.rds", tech)))
}

write_to_cache <- function(vers_dat, tech) {
  saveRDS(vers_dat, file.path("~/.vershist", sprintf("%s.rds", tech)))
}
\ No newline at end of file

M man/apache_httpd_version_history.Rd => man/apache_httpd_version_history.Rd +6 -1
@@ 4,7 4,12 @@
\alias{apache_httpd_version_history}
\title{Retrieve Apache httpd Version Release History}
\usage{
apache_httpd_version_history()
apache_httpd_version_history(refresh = FALSE)
}
\arguments{
\item{refresh}{if \code{TRUE} and there \code{~/.vershist} cache dir exists, will
cause the version history database for apache to be rebuilt. Defaults
to \code{FALSE} and has no effect if \code{~/.vershist} cache dir does not exist.}
}
\description{
Reads \url{https://github.com/apache/httpd} releases to build a data frame of

M man/google_chrome_version_history.Rd => man/google_chrome_version_history.Rd +6 -1
@@ 4,7 4,12 @@
\alias{google_chrome_version_history}
\title{Retrieve Google Chrome Version Release History}
\usage{
google_chrome_version_history()
google_chrome_version_history(refresh = FALSE)
}
\arguments{
\item{refresh}{if \code{TRUE} and there \code{~/.vershist} cache dir exists, will
cause the version history database for apache to be rebuilt. Defaults
to \code{FALSE} and has no effect if \code{~/.vershist} cache dir does not exist.}
}
\description{
Reads \url{https://en.wikipedia.org/wiki/Google_Chrome_version_history"} to build a data

M man/nginx_version_history.Rd => man/nginx_version_history.Rd +6 -1
@@ 4,7 4,12 @@
\alias{nginx_version_history}
\title{Retrieve nginx Version Release History}
\usage{
nginx_version_history()
nginx_version_history(refresh = FALSE)
}
\arguments{
\item{refresh}{if \code{TRUE} and there \code{~/.vershist} cache dir exists, will
cause the version history database for apache to be rebuilt. Defaults
to \code{FALSE} and has no effect if \code{~/.vershist} cache dir does not exist.}
}
\description{
Reads \url{https://raw.githubusercontent.com/nginx/nginx/master/docs/xml/nginx/changes.xml}