R/get_jr_packages.R

Defines functions get_jr_packages git_clone

Documented in get_jr_packages

git_clone = function(repo, path) {
  dir_name = stringr::str_match(repo, "/(.*)\\.git$")[1, 2] #nolint
  path = file.path(path, dir_name)

  system2("git", c("clone", repo, path))
  return(TRUE)
}

#' Download R packages from jr-packages
#'
#' A convience function for downloading all jr-packages.
#' @param path Default \code{.}
#' @export
get_jr_packages = function(path = ".") {
  repos = system2("curl",
                  "https://api.github.com/orgs/jr-packages/repos?per_page=100",
                  stdout = TRUE)
  git_repos = stringr::str_extract(repos, "git@.*\\.git")
  git_repos = git_repos[!is.na(git_repos)]
  if (length(git_repos) > 99) {
    stop("This function has been designed for up to 100 packages. Fixme!")
  }

  if (!file.exists(path)) dir.create(path)
  if (length(list.files(path)) != 0) stop("Directory not empty.")

  vapply(git_repos, git_clone, path = path, FUN.VALUE = logical(1))
}
jr-packages/jrNotes documentation built on Dec. 18, 2020, 11:07 p.m.