Skip to content

Commit

Permalink
simplify code thanks to usethis new badge functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Dec 17, 2018
1 parent 9c0bb41 commit 47902cb
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 54 deletions.
2 changes: 0 additions & 2 deletions R/createBasicProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ createBasicProject <- function(name,
# add README
usethis::use_readme_md(open = FALSE)
readme_path <- find_readme()
# add badges sign
add_badges_sign(readme_path)

# status
add_repo_status(initial_status)
Expand Down
2 changes: 0 additions & 2 deletions R/createPackageProject.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ createPackageProject <- function(name, title = NULL,
# README stuff
usethis::use_readme_rmd(open = FALSE)
readme_path <- find_readme()
# add badges sign
add_badges_sign(readme_path)
# status
add_repo_status(initial_status)

Expand Down
16 changes: 0 additions & 16 deletions R/external_setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,7 @@ setup_repo <- function(git_service, login,

if (ci_activation == "travis") {
usethis::use_travis()
add_travis_badge(login, name)
}
}
}

#' 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) {
readme_path <- find_readme()
readme <- readLines(readme_path)
readme[grepl("<!-- badges -->", readme)] <-
paste(
readme[grepl("<!-- badges -->", readme)],
glue::glue("[![Build Status](https://travis-ci.org/{login}/{name}.svg?branch=master)](https://travis-ci.org/{login}/{name})") # nolint
)
writeLines(readme, readme_path)
}
13 changes: 4 additions & 9 deletions R/repo_status.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,8 @@ add_repo_status <- function(status) {
)
}

badge <- statuses$md_code[statuses$status == status]
readme_path <- find_readme()
readme <- readLines(readme_path)
readme[grepl("<!-- badges -->", readme)] <-
paste(
readme[grepl("<!-- badges -->", readme)],
badge
)
writeLines(readme, readme_path)
badge <- statuses[statuses$status == status,]
usethis::use_badge(badge_name = badge$name,
href = badge$href,
src = badge$src)
}
19 changes: 0 additions & 19 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,3 @@ find_readme <- function() {
}
return(readme_path)
}

#' Add a badge place-holder in the readme
#' @noRd
add_badges_sign <- function(readme_path) {
readme <- readLines(readme_path)
readme_title <- which(grepl("#", readme))[1]
if (readme_title > 1) {
first <- 1:readme_title
} else {
first <- readme_title
}

readme <- c(
readme[first], "",
glue::glue("<!-- badges -->"),
readme[(readme_title + 1):length(readme)]
)
writeLines(readme, readme_path)
}
4 changes: 3 additions & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ knitr::opts_chunk$set(
fig.path = "README-"
)
```
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
<!-- badges: start -->
[![Build Status](https://travis-ci.org/lockedata/pRojects.svg?branch=master)](https://travis-ci.org/lockedata/pRojects) [![Coverage Status](https://img.shields.io/coveralls/lockedata/pRojects.svg)](https://coveralls.io/r/lockedata/pRojects?branch=master) [![Locke Data Slack](https://img.shields.io/badge/Slack-discuss-blue.svg?logo=slack&longCache=true&style=flat)](https://join.slack.com/t/lockedata/shared_invite/enQtMjkwNjY3ODkwMzg2LTI1OGU1NTM3ZGIyZGFiNTdlODI3MzU2N2ZlNDczMjM4M2U2OWVmNDMzZTQ1ZGNlZDQ3MGM2MGVjMjI2MWIyMjI)
[![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
<!-- badges: end -->

This package is designed to take away some grunt work around setting up new projects.

Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

[![Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
<!-- badges: start -->

[![Build
Status](https://travis-ci.org/lockedata/pRojects.svg?branch=master)](https://travis-ci.org/lockedata/pRojects)
[![Coverage
Status](https://img.shields.io/coveralls/lockedata/pRojects.svg)](https://coveralls.io/r/lockedata/pRojects?branch=master) [![Locke Data Slack](https://img.shields.io/badge/Slack-discuss-blue.svg?logo=slack&longCache=true&style=flat)](https://join.slack.com/t/lockedata/shared_invite/enQtMjkwNjY3ODkwMzg2LTI1OGU1NTM3ZGIyZGFiNTdlODI3MzU2N2ZlNDczMjM4M2U2OWVmNDMzZTQ1ZGNlZDQ3MGM2MGVjMjI2MWIyMjI)
Status](https://img.shields.io/coveralls/lockedata/pRojects.svg)](https://coveralls.io/r/lockedata/pRojects?branch=master)
[![Locke Data
Slack](https://img.shields.io/badge/Slack-discuss-blue.svg?logo=slack&longCache=true&style=flat)](https://join.slack.com/t/lockedata/shared_invite/enQtMjkwNjY3ODkwMzg2LTI1OGU1NTM3ZGIyZGFiNTdlODI3MzU2N2ZlNDczMjM4M2U2OWVmNDMzZTQ1ZGNlZDQ3MGM2MGVjMjI2MWIyMjI)
[![Project Status: Active - The project has reached a stable, usable
state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
<!-- badges: end -->

This package is designed to take away some grunt work around setting up
new projects.
Expand All @@ -26,7 +31,7 @@ All projects get setup with Git and Travis by default.

## Install `pRojects`

remotes::install_github("lockedata/pRojects")
devtools::install_github("stephlocke/pRojects")

## RStudio gadget

Expand Down

0 comments on commit 47902cb

Please sign in to comment.