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

tolerate empty lines at start of news file #1977

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
usethis no longer uses the `ui_*()` functions internally, in favor of new
cli-based helpers that are not exported.

* `usethis::use_version()` now tolerates empty / blank lines preceding the
first section title in the package NEWS file. (#1976)

# usethis 2.2.3

* Patch release with changes to `.Rd` files requested by CRAN.
Expand Down
13 changes: 9 additions & 4 deletions R/news.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ use_news_heading <- function(version) {
}

news <- read_utf8(news_path)
title <- glue("# {project_name()} {version}")
idx <- match(TRUE, grepl("[^[:space:]]", news))

if (is.na(idx)) {
return(news)
}

if (title == news[[1]]) {
title <- glue("# {project_name()} {version}")
if (title == news[[idx]]) {
return(invisible())
}

development_title <- glue("# {project_name()} (development version)")
if (development_title == news[[1]]) {
news[[1]] <- title
if (development_title == news[[idx]]) {
news[[idx]] <- title

ui_bullets(c("v" = "Replacing development heading in {.path NEWS.md}."))
return(write_utf8(news_path, news))
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-news.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ test_that("use_news_md() sets version number when 'production version'", {
expect_snapshot(writeLines(read_utf8(proj_path("NEWS.md"))),
transform = scrub_testpkg)
})

test_that("use_news_heading() tolerates blank lines at start", {
create_local_package()

header <- sprintf("# %s (development version)", project_name())
writeLines(c("", header, "", "* Fixed the bugs."), con = "NEWS.md")

use_news_heading(version = "1.0.0")
contents <- read_utf8("NEWS.md")

expected <- sprintf("# %s 1.0.0", project_name())
expect_equal(contents[[2L]], expected)
})
Loading