# taken from devtools
github_pat = function(quiet = FALSE) {
pat <- Sys.getenv("GITHUB_PAT")
if (nzchar(pat)) {
if (!quiet) {
message("Using GitHub PAT from envvar GITHUB_PAT")
}
return(pat)
}
return(NULL)
}
#
#' Full workflow for John Muschelli Packages
#'
#' @param title Title of package
#' @param description Description of package. Should be able to work with the
#' start of the sentence "The goal is to provide".
#' @param fields Default fields of the DESCRIPTION file
#' @param coverage_type CI tool to use.
#' Currently supports codecov and coveralls.
#' @param protocol transfer protocol, either "ssh" (the default)
#' or "https", passed to \code{\link{use_github}}
#' @param auth_token personal access token (PAT)
#' passed to \code{\link{use_github}}
#' @param ... arguments to pass to \code{\link{use_github}}
#'
#' @return Invisible TRUE
#' @export
#'
#' @importFrom usethis use_git use_rstudio use_readme_rmd use_vignette
#' @importFrom usethis proj_set
#' @importFrom usethis use_testthat use_appveyor use_coverage use_github
#' @importFrom usethis use_news_md
#' @importFrom desc description
#' @importFrom git2r config
#' @importFrom utils person browseURL
#' @importFrom yaml yaml.load_file as.yaml
muschelli_workflow = function(
title = "",
description = "",
fields = muschelli_fields(title = title, description = description),
coverage_type = "codecov",
protocol = "https",
auth_token = NULL,
...) {
usethis::proj_set()
repo = git2r::repository(usethis::proj_get())
r_folder = "R"
dir.create(r_folder, showWarnings = FALSE, recursive = TRUE)
man_folder = "man"
dir.create(man_folder, showWarnings = FALSE, recursive = TRUE)
usethis::use_rstudio()
muschelli_description(fields = fields)
ns = paste0("#", " Generated by roxygen2: do not edit by hand\n")
writeLines(text = ns, con = "NAMESPACE", sep = "")
# desc = desc::description$new()
# out = as.list(desc$get(desc$fields()))
# pack_name = out$Package
muschelli_rproj()
# ".Rproj.user/385142C8/build_options"
# auto_roxygenize_for_build_and_reload
desc = desc::desc()
desc$del("VignetteBuilder")
desc$write(file = "DESCRIPTION")
usethis::use_vignette("bad-vignette")
usethis::use_testthat()
protocol = match.arg(protocol, choices = c("https", "ssh"))
if (is.null(auth_token)) {
auth_token = github_pat()
}
if (is.null(auth_token)) {
if (protocol == "https") {
stop(paste0(
"If using GitHub, you need to provide auth_token",
" or set GITHUB_PAT environment variable")
)
}
}
usethis::use_git()
try({
usethis::use_github(
protocol = protocol,
auth_token = auth_token,
...)
})
coverage_type = match.arg(
coverage_type,
choices = c("codecov", "coveralls"))
usethis::use_appveyor()
usethis::use_travis(browse = FALSE)
if (interactive()) {
utils::browseURL("https://ci.appveyor.com/projects/new")
}
usethis::use_coverage(type = coverage_type)
if (interactive()) {
res = git2r::config()
gh_username = res$global$user.name
coverage_url = switch(
coverage_type,
coveralls = "https://coveralls.io/repos/new",
codecov = paste0("https://codecov.io/gh/", gh_username, "/+")
)
utils::browseURL(coverage_url)
}
# Want to remove bug fields for Url (not URL)
desc = desc::description$new()
desc$del("Url")
desc$write()
git2r::commit(repo, message = "Muschelli workflow changes", all = TRUE)
use_news_md(open = FALSE)
# res = git2r::config()
# gh_username = res$global$user.name
# repo = paste0(gh_username, "/", pack_name)
travis_cli = Sys.which("travis")
if (is.null(travis_cli)) {
have_travis_cli = FALSE
message("You must")
head_msg = c("When you do, y")
} else {
have_travis_cli = file.exists(travis_cli)
head_msg = c("Y")
}
message(paste0(head_msg,
"ou must run travis setup releases",
" to setup deployment keys for Travis")
)
use_muschelli_travis(
coverage_type = coverage_type)
use_muschelli_appveyor()
git2r::commit(repo, message = "Muschelli CI changes", all = TRUE)
usethis::use_readme_rmd(open = FALSE)
rmarkdown::render("README.RMd")
use_muschelli_readme_rmd(
coverage_type = coverage_type)
git2r::commit(repo, message = "Muschelli README changes", all = TRUE)
invisible(TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.