Skip to content

Commit

Permalink
start making Travis stuff more automatic
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Nov 7, 2018
1 parent af91e17 commit d2a9631
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 21 deletions.
22 changes: 11 additions & 11 deletions R/createBasicProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ createBasicProject <- function(name,

usethis::use_description()

if (travis) {
usethis::use_template("travis.yml",
".travis.yml",
ignore = TRUE)
#travis::travis_enable() needs GH repo
#placeholder, BADGE stuff
}


desc::desc_set("Title", title,
file = usethis::proj_get())
Expand All @@ -67,12 +61,18 @@ createBasicProject <- function(name,

usethis::use_readme_md(open = FALSE)


if (git) usethis::use_git(message = cool_first_commit())

if (!is.null(github)) setup_repo(username = github,
private = private,
protocol = protocol,
title = title)
if (!is.null(github)){
setup_repo(username = github,
private = private,
protocol = protocol,
title = title)
if (travis) {
setup_travis(github, name)
}
}

}
,
Expand Down
13 changes: 9 additions & 4 deletions R/createPackageProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,15 @@ createPackageProject <- function(name, folder = getwd(),
usethis::use_testthat()
usethis::use_vignette(name)
usethis::use_git(message = cool_first_commit())
if (!is.null(github)) setup_repo(username = github,
private = private,
protocol = protocol,
title = title)
if (!is.null(github)){
setup_repo(username = github,
private = private,
protocol = protocol,
title = title)
if (travis) {
setup_travis(github, name)
}
}
}

}
Expand Down
25 changes: 25 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,28 @@ cool_stuff <- function(){
cool_first_commit <- function(){
praise::praise("First commit of this ${adjective} project, ${exclamation}!")
}

setup_travis <- function(github, name){
usethis::use_template("travis.yml",
".travis.yml",
ignore = TRUE)
if(fs::file_exists(file.path(usethis::proj_get(), "README.Rmd"))){
readme_path <- file.path(usethis::proj_get(), "README.Rmd")
}else{
readme_path <- file.path(usethis::proj_get(), "README.md")
}

readme <- readLines(file.path(usethis::proj_get(), "README.md"))
readme_title <- which(grepl("#", readme))[1]
if(readme_title > 1){
first <- 1:readme_title
}else{
first <- readme_title
}

readme <- c(readme[first], "",
glue::glue("[![Build
Status](https://travis-ci.org/{github}/{name}.svg?branch=master)](https://travis-ci.org/{github}/{name})"),
readme[(readme_title+1):length(readme)])
writeLines(readme, readme_path)
}
1 change: 0 additions & 1 deletion tests/testthat/test-AAA-createBasicProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ test_that("createBasicProject() creates as expected when using defaults", {
expect_true(dir.exists(file.path(tmp, project_name, "packrat")))
expect_true(file.exists(file.path(tmp, project_name, ".git")))
expect_true(file.exists(file.path(tmp, project_name, ".gitignore")))
expect_true(file.exists(file.path(tmp, project_name, ".travis.yml")))

})

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-createAnalysisProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ test_that("createAnalysisProject() creates as expected when using defaults",{
expect_true(file.exists(file.path(tmp, project_name, "README.md")))
expect_true(file.exists(file.path(tmp, project_name, ".git")))
expect_true(file.exists(file.path(tmp, project_name, ".gitignore")))
expect_true(file.exists(file.path(tmp, project_name, ".travis.yml")))
expect_true(file.exists(file.path(tmp, project_name, "data")))
expect_true(file.exists(file.path(tmp, project_name, "analysis")))
expect_true(file.exists(file.path(tmp, project_name, "outputs")))
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-createPackageProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ test_that("createPackageProject() creates as expected when using defaults",{
expect_true(file.exists(file.path(tmp, project_name, "vignettes")))
expect_true(file.exists(file.path(tmp, project_name, ".git")))
expect_true(file.exists(file.path(tmp, project_name, ".gitignore")))
expect_true(file.exists(file.path(tmp, project_name, ".travis.yml")))

})

Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-createTrainingProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ test_that("createTrainingProject() creates as expected when using defaults",{
expect_true(file.exists(file.path(tmp, project_name, "README.md")))
expect_true(file.exists(file.path(tmp, project_name, ".git")))
expect_true(file.exists(file.path(tmp, project_name, ".gitignore")))
expect_true(file.exists(file.path(tmp, project_name, ".travis.yml")))
expect_true(file.exists(file.path(tmp, project_name, "data")))
expect_true(file.exists(file.path(tmp, project_name, "handouts")))
expect_true(file.exists(file.path(tmp, project_name, "slides")))
Expand All @@ -38,7 +37,6 @@ test_that("createTrainingProject() creates as expected when using bookdown and r
expect_true(file.exists(file.path(tmp, project_name, "README.md")))
expect_true(file.exists(file.path(tmp, project_name, ".git")))
expect_true(file.exists(file.path(tmp, project_name, ".gitignore")))
expect_true(file.exists(file.path(tmp, project_name, ".travis.yml")))
expect_true(file.exists(file.path(tmp, project_name, "data")))
expect_true(file.exists(file.path(tmp, project_name, "handouts")))
expect_true(file.exists(file.path(tmp, project_name, "handouts", "index.Rmd")))
Expand All @@ -61,7 +59,6 @@ test_that("createTrainingProject() creates as expected when using tufte and xari
expect_true(file.exists(file.path(tmp, project_name, "README.md")))
expect_true(file.exists(file.path(tmp, project_name, ".git")))
expect_true(file.exists(file.path(tmp, project_name, ".gitignore")))
expect_true(file.exists(file.path(tmp, project_name, ".travis.yml")))
expect_true(file.exists(file.path(tmp, project_name, "data")))
expect_true(file.exists(file.path(tmp, project_name, "handouts")))
expect_true(file.exists(file.path(tmp, project_name, "handouts", "tufte_handout.Rmd")))
Expand Down

0 comments on commit d2a9631

Please sign in to comment.