diff --git a/DESCRIPTION b/DESCRIPTION index 456f553..90fb41e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,6 +23,7 @@ Imports: stringr, tidyr, gitcreds, + gh, knitr, purrr, rmarkdown, @@ -32,7 +33,7 @@ Imports: spelling, xml2, R.utils, - googledrive, + googledrive, jsonlite, yaml Suggests: diff --git a/NAMESPACE b/NAMESPACE index d1c2ff3..243d49b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -60,6 +60,7 @@ export(unzip_pptx) export(website_to_embed_leanpub) export(xml_notes) import(dplyr) +import(gh) import(rvest) import(stringr) importFrom(dplyr,"%>%") @@ -78,6 +79,7 @@ importFrom(knitr,opts_knit) importFrom(readr,write_tsv) importFrom(rprojroot,find_root) importFrom(rprojroot,has_dir) +importFrom(rprojroot,has_file) importFrom(rvest,html_attr) importFrom(rvest,html_nodes) importFrom(rvest,read_html) diff --git a/R/borrow_chapter.R b/R/borrow_chapter.R index 1e8a4d5..94faef8 100644 --- a/R/borrow_chapter.R +++ b/R/borrow_chapter.R @@ -4,7 +4,7 @@ #' you may want to share written material between the two. #' But, if you copy and paste to share material this would create a maintenance #' problem because if you update one you will need to remember to copy over the -#' other! +#' other! #' To borrow a chapter from another course, create an .Rmd as you normally would, #' with an [`H1` title](https://www.markdownguide.org/basic-syntax/) if you wish. #' Then in a code chunk, use cow::borrow_chapter() to have the content from an @@ -113,6 +113,8 @@ borrow_chapter <- function(doc_path, } } + message("Got to here") + # Piece together URL full_url <- file.path(base_url, repo_name, branch, doc_path) @@ -156,8 +158,13 @@ borrow_chapter <- function(doc_path, ) } } + + message("Also got to here") + writeLines(file_contents, dest_file) + message("and wrote lines") + # Get parent directory parent_dir <- knitr::opts_knit$get("output.dir") diff --git a/R/github_handling.R b/R/github_handling.R index c6a6810..96f0a35 100644 --- a/R/github_handling.R +++ b/R/github_handling.R @@ -198,6 +198,8 @@ get_repo_info <- function(repo_name, #' @return A TRUE/FALSE whether or not the repository exists. Optionally the #' output from git ls-remote if return_repo = TRUE. #' +#' @import gh +#' #' @export #' #' @examples \dontrun{ @@ -216,14 +218,20 @@ check_git_repo <- function(repo_name, # If silent = TRUE don't print out the warning message from the 'try' report <- ifelse(silent, suppressWarnings, message) + repo_info <- try(gh::gh(paste0("/repos/", repo_name)), silent=TRUE) + if (length(repo_info) == 1){ + if (class(repo_info) == "try-error"){ + stop("Can't validate if the repo is private or not") + }} + # Try to get credentials other way - if (is.null(token)) { + if (is.null(token) & repo_info$private) { # Get auth token token <- get_token(app_name = "github") } # Run git ls-remote - if (!grepl("Error", token[1])) { + if (isTRUE(!grepl("Error", token[1]))) { # If token is supplied, use it test_repo <- report( try(system(paste0("git ls-remote https://", token, "@github.com/", repo_name),