-
Notifications
You must be signed in to change notification settings - Fork 307
Expand file tree
/
Copy pathnews.R
More file actions
64 lines (52 loc) 路 1.58 KB
/
Copy pathnews.R
File metadata and controls
64 lines (52 loc) 路 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#' Create a simple `NEWS.md`
#'
#' This creates a basic `NEWS.md` in the root directory.
#'
#' @inheritParams use_template
#' @seealso The [other markdown files
#' section](https://r-pkgs.org/other-markdown.html) of [R
#' Packages](https://r-pkgs.org).
#' @export
use_news_md <- function(open = rlang::is_interactive()) {
check_is_package("use_news_md()")
version <- if (is_dev_version()) "(development version)" else proj_version()
on_cran <- !is.null(cran_version())
if (on_cran) {
init_bullet <- "Added a `NEWS.md` file to track changes to the package."
} else {
init_bullet <- "Initial CRAN submission."
}
use_template(
"NEWS.md",
data = list(
Package = project_name(),
Version = version,
InitialBullet = init_bullet
),
open = open
)
git_ask_commit("Add NEWS.md", untracked = TRUE, paths = "NEWS.md")
}
use_news_heading <- function(version) {
news_path <- proj_path("NEWS.md")
if (!file_exists(news_path)) {
return(invisible())
}
news <- read_utf8(news_path)
idx <- match(TRUE, grepl("[^[:space:]]", news))
if (is.na(idx)) {
return(news)
}
title <- glue("# {project_name()} {version}")
if (title == news[[idx]]) {
return(invisible())
}
development_title <- glue("# {project_name()} (development version)")
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))
}
ui_bullets(c("v" = "Adding new heading to {.path NEWS.md}."))
write_utf8(news_path, c(title, "", news))
}