~hrbrmstr/vershist

f55ab4f9a0f57f2a887de522047c2a1c4880ceff — hrbrmstr 2 years ago 5072676
improved exim
3 files changed, 63 insertions(+), 2 deletions(-)

M DESCRIPTION
M NEWS.md
M R/exim.R
M DESCRIPTION => DESCRIPTION +2 -2
@@ 1,8 1,8 @@
Package: vershist
Type: Package
Title: Collect Version Histories For Vendor Products
Version: 0.4.0
Date: 2019-06-08
Version: 0.4.1
Date: 2019-09-30
Authors@R: c(
    person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), 
           comment = c(ORCID = "0000-0001-5670-2640"))

M NEWS.md => NEWS.md +3 -0
@@ 1,3 1,6 @@
0.4.1
* Improved Exim version history retriever 

0.4.0
* Add Exim version history retriever
* Improved Apache & nginx version retriever functions

M R/exim.R => R/exim.R +58 -0
@@ 58,8 58,66 @@ exim_version_history <- function(refresh = FALSE) {
    dplyr::arrange(rls_date, major, minor, patch) %>%
    dplyr::mutate(vers = factor(vers, levels = vers)) -> out

  page <- gh::gh("/repos/Exim/exim/tags")

  purrr::map_df(
    page, ~{
      list(
        vers = .x$name,
        rls_date = gh::gh(.x$commit$url)$commit$author$date # kinda dangerous
      )
    }) -> xdf

  sgh_next <- purrr::safely(gh::gh_next) # to stop on gh_next() error

  while(TRUE) {
    page <- sgh_next(page)
    if (is.null(page$result)) break;
    page <- page$result
    dplyr::bind_rows(
      xdf,
      purrr::map_df(
        page, ~{
          list(
            vers = .x$name,
            rls_date = gh::gh(.x$commit$url)$commit$author$date # kinda dangerous
          )
        })
    ) -> xdf
  }

  dplyr::filter(xdf, stri_detect_regex(vers, "^exim-")) %>%
    dplyr::mutate(vers = stri_replace_first_regex(vers, "^exim-", "")) %>%
    dplyr::filter(!stri_detect_regex(vers, "[[:alpha:]]")) %>%
    dplyr::mutate(vers = stri_replace_all_regex(vers, "([[:digit:]]+)_", "$1.")) %>%
    dplyr::filter(stri_count_fixed(vers, ".") < 3) %>%
    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, fill = "right") %>%
    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::mutate_at(vars(major, minor, patch), ~ifelse(is.na(.), 0, .)) %>%
    dplyr::arrange(major, minor, patch) %>%
    dplyr::mutate(vers = sprintf("%s.%s.%s", major, minor, patch)) %>%
    dplyr::select(vers, rls_date, rls_year, major, minor, patch, prerelease, build) -> from_gh

  dplyr::bind_rows(
    mutate(out, vers = as.character(vers)),
    filter(from_gh, !(vers %in% out$vers))
  ) %>%
  dplyr::arrange(rls_date, major, minor, patch) %>%
    dplyr::mutate(vers = factor(vers, levels = vers)) -> out

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

  out

}