R/create_github_ex.R

Defines functions create_github_ex

#' Create an example repo on github.roch.com
#' 
#' This will create and open a github repo on github.roche.com (if the
#' user has valid credentials). The new repo will be called 'program'
#' and will be created from a temproary directory that does not persist
#' when the app is closed. This is for testing and using as an example
#'
#' @return creates repo and opens browser window as side-effect
#' @export
#'
create_github_ex <- function(){
  
  copy_from <- file.path(system.file(package="lopo3000"), "program")
  file.copy(copy_from, tempdir(), recursive=TRUE)
  repo_path <- file.path(tempdir(), "program")
  
  ## Initialize the repository
  repo <- git2r::init(repo_path)
  git2r::add(repo, "*")
  
  try(git2r::commit(repo, "initial commit", all=TRUE), silent = TRUE)
  
  Sys.setenv(GITHUB_API_URL="https://github.roche.com/api/v3")
  whoami <- gh::gh_whoami()$login
  
  old_wd <- getwd()
  setwd(file.path(tempdir(), "program"))
  try(usethis::use_github(host="https://github.roche.com/api/v3", protocol = "https"), silent=TRUE)
  setwd(old_wd)
  
  browseURL(glue::glue("https://github.roche.com/{whoami}/program"))
}
kismet303/lopo3000 documentation built on Dec. 15, 2019, 12:31 a.m.