Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
17 changes: 12 additions & 5 deletions R/z_pages.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#' viz,
#' github_repo = "my_animint2_plots",
#' commit_message = "New animint",
#' private = TRUE)
#' private = FALSE)
#' }
#'
#' @export
Expand Down Expand Up @@ -89,7 +89,7 @@ animint2pages <- function(plot.list, github_repo, commit_message = "Commit from
initial_commit(local_clone, repo, viz_url)
}
# Handle gh-pages branch
manage_gh_pages(repo, to_post, local_clone, commit_message)
manage_gh_pages(repo, owner, to_post, local_clone, commit_message, github_repo)
message(sprintf(
"Visualization will be available at %s\nDeployment via GitHub Pages may take a few minutes...", viz_url))
viz_owner_repo
Expand Down Expand Up @@ -119,7 +119,7 @@ initial_commit <- function(local_clone, repo, viz_url) {
gert::git_push(repo = repo, remote = "origin", set_upstream = TRUE)
}

manage_gh_pages <- function(repo, to_post, local_clone, commit_message) {
manage_gh_pages <- function(repo, owner, to_post, local_clone, commit_message, gh_repo_name) {
branches <- gert::git_branch_list(local = TRUE, repo = repo)
if (!"gh-pages" %in% branches$name) {
gert::git_branch_create(repo = repo, branch = "gh-pages")
Expand All @@ -129,12 +129,19 @@ manage_gh_pages <- function(repo, to_post, local_clone, commit_message) {
gert::git_add(files = ".", repo = repo)
gert::git_commit(message = commit_message, repo = repo)
gert::git_push(remote = "origin", set_upstream = TRUE, repo = repo, force = TRUE)
# Set 'gh-pages' as the default branch on GitHub using GitHub API
gh::gh(
"PATCH /repos/{owner}/{repo}",
owner = owner,
repo = gh_repo_name,
default_branch = "gh-pages"
)
}

check_no_github_repo <- function(owner, repo) {
check_no_github_repo <- function(owner, gh_repo) {
tryCatch(
{
gh::gh("/repos/{owner}/{repo}", owner = owner, repo = repo)
gh::gh("/repos/{owner}/{repo}", owner = owner, repo = gh_repo)
TRUE
},
"http_error_404" = function(err) FALSE
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-compiler-ghpages.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,17 @@ test_that("animint2pages raises an error if no GitHub token is present", {
do.call(Sys.setenv, as.list(env.old))
file.copy(config.old, config.file, overwrite = TRUE)
})

test_that("animint2pages() default branch is gh-pages", {
whoami <- suppressMessages(gh::gh_whoami())
owner <- whoami[["login"]]
test_default_branch <- function(owner, repo_name) {
repo_info <- gh::gh(
"GET /repos/:owner/:repo",
owner = owner,
repo = repo_name
)
repo_info$default_branch == "gh-pages"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a good start. Thanks.
however, I think a better test would be if you clone the repo and test if branch name of the clone is gh-pages ... That test would more directly address the usability concern (user would not have to switch branches) can you please change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! I will do that.

}
expect_true(test_default_branch(owner, "animint2pages_test_repo"))
})