Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tic #111

Merged
merged 61 commits into from
Feb 5, 2019
Merged

tic #111

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
fa01d57
start again
maelle Jan 16, 2019
576727b
add infrastructure to know what type of project is being set up
maelle Jan 16, 2019
ad7c801
a bit better
maelle Jan 16, 2019
658ca06
less mistakes
maelle Jan 16, 2019
68dafc6
make travis available
maelle Jan 16, 2019
0a062e1
Deploy from Travis build 329 [ci skip]
maelle Jan 16, 2019
bd49c4a
make sure travis uses the current project
maelle Jan 17, 2019
05e8285
git tweaks
maelle Jan 17, 2019
28d9dbf
Deploy from Travis build 333 [ci skip]
maelle Jan 17, 2019
68e504a
coverage
maelle Jan 17, 2019
ef9c402
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Jan 17, 2019
b678a16
Deploy from Travis build 335 [ci skip]
maelle Jan 17, 2019
1c2ec58
update template
maelle Jan 17, 2019
cd2505e
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Jan 17, 2019
657f8ea
tweak template
maelle Jan 17, 2019
c248799
Deploy from Travis build 339 [ci skip]
maelle Jan 17, 2019
1944cc7
:cry:
maelle Jan 17, 2019
a5065dc
coverage not null
maelle Jan 17, 2019
614a554
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Jan 24, 2019
0ac52e3
Deploy from Travis build 344 [ci skip]
maelle Jan 24, 2019
e111db2
less stuff in tic
maelle Jan 24, 2019
d8c70f2
add dummy test
maelle Jan 24, 2019
c17de5b
Rbuildignore
maelle Jan 24, 2019
0e12105
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Jan 24, 2019
1703600
Deploy from Travis build 345 [ci skip]
maelle Jan 24, 2019
7c1595f
fix template
maelle Jan 24, 2019
001a935
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Jan 24, 2019
b84ddf2
Deploy from Travis build 346 [ci skip]
maelle Jan 24, 2019
a2a11b5
Update R/createPackageProject.R
stephlocke Feb 4, 2019
e980053
Deploy from Travis build 358 [ci skip]
web-flow Feb 4, 2019
766185b
make myself an author
maelle Feb 4, 2019
f724d96
Deploy from Travis build 359 [ci skip]
maelle Feb 4, 2019
1b81cdd
add two tics drafts
maelle Feb 4, 2019
accfd0b
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Feb 4, 2019
d7af7b6
Deploy from Travis build 360 [ci skip]
maelle Feb 4, 2019
11abcbd
git add
maelle Feb 4, 2019
a43c326
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Feb 4, 2019
89b3284
Deploy from Travis build 361 [ci skip]
maelle Feb 4, 2019
8b1811e
add infrastructure
maelle Feb 4, 2019
7c07fc2
Rbuildignore tic
maelle Feb 4, 2019
a1d5cf8
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Feb 4, 2019
1947a8c
Deploy from Travis build 362 [ci skip]
maelle Feb 4, 2019
a1feb1c
fix analysis tic
maelle Feb 4, 2019
3802e1a
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Feb 4, 2019
e386394
add comments in tic.R
maelle Feb 4, 2019
4f8223d
Deploy from Travis build 363 [ci skip]
maelle Feb 4, 2019
e7cb69a
Merge branch 'master' into tic2
maelle Feb 4, 2019
38106cd
Deploy from Travis build 364 [ci skip]
maelle Feb 4, 2019
9e344e4
fix horror
maelle Feb 4, 2019
0e51f61
Deploy from Travis build 367 [ci skip]
web-flow Feb 4, 2019
12a99d7
add tic for training projects
maelle Feb 5, 2019
83ea862
Deploy from Travis build 369 [ci skip]
maelle Feb 5, 2019
e1ff98e
fixes
maelle Feb 5, 2019
e92a1e5
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Feb 5, 2019
5d031e8
Deploy from Travis build 371 [ci skip]
maelle Feb 5, 2019
389ad5a
oops
maelle Feb 5, 2019
a12a87a
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Feb 5, 2019
1c4f076
Deploy from Travis build 373 [ci skip]
maelle Feb 5, 2019
9b3b1ad
tweaks
maelle Feb 5, 2019
3aa835b
Merge branch 'tic2' of github.com:lockedata/starters into tic2
maelle Feb 5, 2019
191e910
Deploy from Travis build 375 [ci skip]
maelle Feb 5, 2019
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
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Authors@R:
email = "[email protected]"),
person(given = "Maëlle",
family = "Salmon",
role = "ctb",
role = "aut",
email = "[email protected]",
comment = c(ORCID = "0000-0002-2815-0399")))
Description: Setting up R project directories for teaching, presenting, analysis,
Expand Down Expand Up @@ -56,10 +56,12 @@ Imports:
gh,
git2r,
glue,
praise
praise,
travis
Remotes:
r-lib/usethis,
metrumresearchgroup/covrpage
metrumresearchgroup/covrpage,
ropenscilabs/travis
Roxygen: list(markdown = TRUE)
RoxygenNote: 6.1.1
URL: https://github.com/lockedata/starters, https://itsalocke.com/starters/
Expand Down
6 changes: 5 additions & 1 deletion R/createAnalysisProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ createAnalysisProject <- function(name, title = NULL,

current_proj <- get_current_proj()
tryCatch({
createBasicProject(
if(!is.null(external_setup)){
external_setup$project_type <- "analysis"
}
.createBasicProject(
name = name,
title = title,
folder = folder,
Expand All @@ -52,6 +55,7 @@ createAnalysisProject <- function(name, title = NULL,
reset = FALSE
)
createdirs(dirs)
git_add_infrastructure()
},
error = function(e) {
message(paste("Error:", e$message))
Expand Down
112 changes: 70 additions & 42 deletions R/createBasicProject.R
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
#' Create a very basic project directory
#'
#' @param name Project
#' @param title "What the Project Does (One Line, Title Case)"
#' If NULL, a random one will be generated.
#' @param folder Folder under which to create the project
#' @param initial_status initial repostatus.org status for the project,
#' whose badge will be added to the README.
#' @param packagedeps Set a tool for package reproducibility
#' @param git Configure Git
#' @param external_setup How to do the partly interactive setup
#' of online git, CI and coverage platforms. If NULL, no setup.
#' \itemize{
#' \item \code{git_service} Only "GitHub" is supported at the moment.
#' \item \code{login} username or organization name to use for the git service.
#' If NULL, no GitHub repo is created.
#' \item \code{private} whether to make the created repo private
#' \item \code{protocol} "ssh" or "https", protocol to use for GitHub
#' \item \code{ci_activation} Only NULL, and "travis" are supported at the moment.
#' "travis" means calling \code{usethis::use_travis()} and adding the Travis
#' badge to the README.
#' }
#' @param reset Whether to reset the project to current project
#'
#' @export
#'
#' @examples
#' \dontrun{
#' folder <- tempdir()
#' createBasicProject(
#' name = "doggos", title = "Counting cute dogs",
#' folder = folder,
#' packagedeps = "none",
#' git = TRUE, external_setup = NULL,
#' reset = TRUE
#' )
#' list.files(file.path(folder, "doggos"))
#' unlink(file.path(folder, "doggos"))
#' }
createBasicProject <- function(name, title = NULL,
.createBasicProject <- function(name, title = NULL,
folder = getwd(),
initial_status = "wip",
packagedeps = "checkpoint",
Expand All @@ -47,7 +8,8 @@ createBasicProject <- function(name, title = NULL,
login = gh::gh_whoami()$login,
private = FALSE,
protocol = "ssh",
ci_activation = "travis"
ci_activation = "travis",
project_type = "basic",
),
reset = TRUE) {
if (missing(name)) stop("name is required")
Expand Down Expand Up @@ -112,7 +74,8 @@ createBasicProject <- function(name, title = NULL,
login = external_setup$login,
private = external_setup$private,
protocol = external_setup$protocol,
ci_activation = external_setup$ci_activation
ci_activation = external_setup$ci_activation,
project_type = external_setup$project_type
)
}

Expand All @@ -135,6 +98,71 @@ createBasicProject <- function(name, title = NULL,
invisible(TRUE)
}


#' Create a very basic project directory
#'
#' @param name Project
#' @param title "What the Project Does (One Line, Title Case)"
#' If NULL, a random one will be generated.
#' @param folder Folder under which to create the project
#' @param initial_status initial repostatus.org status for the project,
#' whose badge will be added to the README.
#' @param packagedeps Set a tool for package reproducibility
#' @param git Configure Git
#' @param external_setup How to do the partly interactive setup
#' of online git, CI and coverage platforms. If NULL, no setup.
#' \itemize{
#' \item \code{git_service} Only "GitHub" is supported at the moment.
#' \item \code{login} username or organization name to use for the git service.
#' If NULL, no GitHub repo is created.
#' \item \code{private} whether to make the created repo private
#' \item \code{protocol} "ssh" or "https", protocol to use for GitHub
#' \item \code{ci_activation} Only NULL, and "travis" are supported at the moment.
#' "travis" means calling \code{usethis::use_travis()} and adding the Travis
#' badge to the README.
#' }
#' @param reset Whether to reset the project to current project
#'
#' @export
#'
#' @examples
#' \dontrun{
#' folder <- tempdir()
#' createBasicProject(
#' name = "doggos", title = "Counting cute dogs",
#' folder = folder,
#' packagedeps = "none",
#' git = TRUE, external_setup = NULL,
#' reset = TRUE
#' )
#' list.files(file.path(folder, "doggos"))
#' unlink(file.path(folder, "doggos"))
#' }
createBasicProject <- function(name, title = NULL,
folder = getwd(),
initial_status = "wip",
packagedeps = "checkpoint",
git = TRUE,
external_setup = list(
git_service = "GitHub",
login = gh::gh_whoami()$login,
private = FALSE,
protocol = "ssh",
ci_activation = "travis"
),
reset = TRUE) {
if(!is.null(external_setup)){
external_setup$project_type <- "basic"
}
.createBasicProject(name = name, title = title,
folder = folder,
initial_status = initial_status,
packagedeps = packagedeps,
git = git,
external_setup = external_setup,
reset = reset)
}

#' @export

#' @describeIn createBasicProject aesthetic addition for continuity purposes
Expand Down
13 changes: 9 additions & 4 deletions R/createPackageProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ createPackageProject <- function(name, title = NULL,
if (pkgdown) {
file.create(file.path(usethis::proj_get(),
"_pkgdown.yml"))
usethis::use_build_ignore("_pkgdown.yml")
}

if (!is.null(external_setup)) {
Expand All @@ -142,17 +143,21 @@ createPackageProject <- function(name, title = NULL,
login = external_setup$login,
private = external_setup$private,
protocol = external_setup$protocol,
ci_activation = external_setup$ci_activation
ci_activation = external_setup$ci_activation,
project_type = "package",
coverage = coverage
)
}

# README
knit_readme()

# dummy test
usethis::use_testthat()
usethis::use_test(name = "sample", open = FALSE)

# add everything
repo <- git2r::init(usethis::proj_get())
git2r::add(repo, path = dir(usethis::proj_get()))
git2r::commit(repo, message = "add infrastructure")
git_add_infrastructure()
}
},
error = function(e) {
Expand Down
6 changes: 5 additions & 1 deletion R/createTrainingProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ createTrainingProject <- function(name, title = NULL,
message("Creating skeleton")
current_proj <- get_current_proj()
tryCatch({
createBasicProject(
if(!is.null(external_setup)){
external_setup$project_type <- "training"
}
.createBasicProject(
name = name,
title = title,
folder = folder,
Expand All @@ -77,6 +80,7 @@ createTrainingProject <- function(name, title = NULL,
reset = FALSE
)
createdirs(dirs)
git_add_infrastructure()


# Handouts prep
Expand Down
77 changes: 75 additions & 2 deletions R/external_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
#' @param ci_activation how to activate CI stuff
#' @param project project name (repo name)
#' @param title project title (repo description)
#' @param project_type what kind of project it is
#' @param coverage coverage service
#' @noRd

setup_repo <- function(git_service, login,
private, protocol,
ci_activation,
name, title) {
name, title,
project_type,
coverage = NULL) {

if (tolower(git_service) != "github") {
stop(glue::glue(
"Only GitHub is supported at the moment, not {git_service}."
Expand All @@ -25,6 +30,11 @@ setup_repo <- function(git_service, login,
name = name, title = title
)

# coverage
if(!is.null(coverage)){
add_coverage_badge(login, name, coverage)
}

if (!is.null(ci_activation)) {
if (ci_activation != "travis") {
stop(glue::glue(
Expand All @@ -35,8 +45,71 @@ setup_repo <- function(git_service, login,
}

if (ci_activation == "travis") {
usethis::use_travis()
usethis::use_template("dot-travis.yml",
save_as = ".travis.yml",
package = "travis")
usethis::use_build_ignore(".travis.yml")
travis::travis_enable(repo = travis::github_repo(path = usethis::proj_get()))
# copy custom tic depending on proj
usethis::use_template(file.path("tic", project_type,
"tic.R"),
save_as = "tic.R",
package = "starters",
data = list(coverage_service = coverage))
usethis::use_build_ignore("tic.R")


if (project_type != "basic"){
travis::use_travis_deploy(path = usethis::proj_get())
}

# in all cases
travis::travis_set_pat(repo = travis::github_repo(path = usethis::proj_get()))

add_travis_badge(login, name)
repo <- git2r::init(usethis::proj_get())
git2r::add(repo, path = ".travis.yml")
}
}
}

#' Add Travis badge to the README
#' @param login login (assumed to be the same for the git
#' platform and Travis)
#' @param name project name (repo name)
#' @noRd
add_travis_badge <- function(login, name) {
# from https://github.com/r-lib/usethis/blob/02fc4b20f022b0b98afcb323ef770fd78c00ae5a/R/ci.R#L39
url <- glue::glue("https://travis-ci.org/{login}/{name}")
img <- glue::glue("{url}.svg?branch=master")
usethis::use_badge("Travis build status", url, img)
}

#' Add coverage badge to the README
#' @param login login (assumed to be the same as for the git
#' platform)
#' @param name project name (repo name)
#' @param coverage coverage service
#' @noRd
add_coverage_badge <- function(login, name, coverage) {
github_repo_spec <- paste(login, name, sep ="/")
if(coverage == "codecov"){
# from https://github.com/r-lib/usethis/blob/85bf30af12dc5a99faf20115a0396add72aa6d12/R/coverage.R#L47
url <- glue::glue("https://codecov.io/gh/{github_repo_spec}?branch=master")
img <- glue::glue(
"https://codecov.io/gh/{github_repo_spec}/branch/master/graph/badge.svg"
)
usethis::use_badge("Codecov test coverage", url, img)

}else{

if(coverage == "coveralls"){
# from https://github.com/r-lib/usethis/blob/85bf30af12dc5a99faf20115a0396add72aa6d12/R/coverage.R#L56
url <- glue::glue("https://coveralls.io/r/{github_repo_spec}?branch=master")
img <- glue::glue(
"https://coveralls.io/repos/github/{github_repo_spec}/badge.svg"
)
usethis::use_badge("Coveralls test coverage", url, img)
}
}
}
26 changes: 14 additions & 12 deletions R/github.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,32 @@ setup_gh_repo <- function(username, private, protocol,
endpoint <- "POST /user/repos"
}

quoted_expression <- quote(gh::gh(endpoint,
org = username,
name = name,
description = title,
private = private
))
quoted_expression <- call("gh",
endpoint = endpoint,
org = username,
name = name,
description = title,
private = private
)
ok <- gh_retry(quoted_expression)
if (!ok){
stop("GitHub repo creation failed.")
}

r <- git2r::repository(usethis::proj_get())
origin_url <- switch(protocol, https = create$clone_url,
ssh = create$ssh_url
origin_url <- switch(protocol,
https = glue::glue("https://github.com/{username}/{name}.git"),
ssh = glue::glue("[email protected]:{username}/{name}.git")
)
git2r::remote_add(r, "origin", origin_url)
git2r::checkout(r, "master")
# git2r::branch_set_upstream(git2r::repository_head(r),
# "origin/master")
desc::desc_set("URL", create$html_url,
# not possible cf https://github.com/ropensci/git2r/issues/133
#git2r::branch_set_upstream(git2r::repository_head(r), "origin/master")
desc::desc_set("URL", glue::glue("https://github.com/{username}/{name}"),
file = usethis::proj_get()
)
desc::desc_set("BugReports",
paste0(create$html_url, "/issues"),
glue::glue("https://github.com/{username}/{name}/issues"),
file = usethis::proj_get()
)
}
1 change: 1 addition & 0 deletions R/use_readme.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use_readme <- function(name){
usethis::use_template("README.Rmd",
data = list(Package = name),
package = "starters")
usethis::use_build_ignore("README.Rmd")
stephlocke marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down
Loading