Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Imports:
stringr,
tidyr,
gitcreds,
gh,
knitr,
purrr,
rmarkdown,
Expand All @@ -32,7 +33,7 @@ Imports:
spelling,
xml2,
R.utils,
googledrive,
googledrive,
jsonlite,
yaml
Suggests:
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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,"%>%")
Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion R/borrow_chapter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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")

Expand Down
12 changes: 10 additions & 2 deletions R/github_handling.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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),
Expand Down