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

Move from ui_* to {cli} #54

Merged
merged 3 commits into from Aug 27, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Expand Up @@ -20,6 +20,7 @@ URL: http://krlmlr.github.io/fledge,
https://github.com/krlmlr/fledge
BugReports: https://github.com/krlmlr/fledge/issues
Imports:
cli,
desc (>= 1.2.0),
enc,
git2r (>= 0.26.0),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -9,6 +9,7 @@ export(tag_version)
export(unbump_version)
export(update_news)
export(update_version)
import(cli)
import(rlang)
import(usethis)
importFrom(purrr,discard)
Expand Down
7 changes: 4 additions & 3 deletions R/bump-version.R
Expand Up @@ -13,9 +13,10 @@ bump_version_impl <- function(which) {
} else {
#' - Otherwise, [commit_version()].
commit_version()
ui_info("Preparing package for release (CRAN or otherwise)")
cli_alert_info("Preparing package for release (CRAN or otherwise).")
edit_news()
ui_todo("Convert the change log in {ui_path(news_path)} to release notes")
ui_todo("After CRAN release, call {ui_code('fledge::tag_version()')} and {ui_code('fledge::bump_version()')} to re-enter development mode")
cli_alert_warning("Convert the change log in {.file {news_path}} to release notes.")
cli_alert_warning("After CRAN release, call {.fun fledge::tag_version} and
{.fun fledge::bump_version} to re-enter development mode")
}
}
4 changes: 2 additions & 2 deletions R/commit-version.R
Expand Up @@ -2,7 +2,7 @@ commit_version_impl <- function() {
check_only_staged(c("DESCRIPTION", news_path))

if (is_last_commit_bump()) {
ui_done("Resetting to previous commit")
cli_alert("Resetting to previous commit.")
git2r::reset(git2r::revparse_single(revision = "HEAD^"))
amending <- TRUE
} else {
Expand All @@ -11,7 +11,7 @@ commit_version_impl <- function() {

git2r::add(".", c("DESCRIPTION", news_path))
if (length(git2r::status(".", unstaged = FALSE, untracked = FALSE)$staged) > 0) {
ui_done("Committing changes")
cli_alert("Committing changes.")
git2r::commit(".", get_commit_message())
}

Expand Down
6 changes: 3 additions & 3 deletions R/finalize-version.R
Expand Up @@ -15,7 +15,7 @@ finalize_version_impl <- function(push) {
push_head(head)
} else {
edit_news()
ui_todo("Call {ui_code('fledge::finalize_version(push = TRUE)')}")
cli_alert_warning("Call {.code fledge::finalize_version(push = TRUE)}.")
send_to_console("fledge::finalize_version(push = TRUE)")
}
}
Expand All @@ -27,12 +27,12 @@ get_head_branch <- function() {
}

push_tag <- function(tag) {
ui_done("Force-pushing tag {ui_value(tag)}")
cli_alert("Force-pushing tag {.field {tag}}.")
git2r::push(name = "origin", refspec = paste0("refs/tags/", tag), force = TRUE)
}

push_head <- function(head) {
ui_done('Pushing {ui_value(head$name)}')
cli_alert('Pushing {.field {head$name}}.')
git2r::push(head)
}

Expand Down
2 changes: 2 additions & 0 deletions R/import.R
@@ -1,4 +1,6 @@
#' @import rlang
#' @import cli
#' @import usethis
#' @importFrom purrr map map_chr map_int discard keep some
#' @importFrom tibble add_column
NULL
2 changes: 0 additions & 2 deletions R/package.R

This file was deleted.

9 changes: 6 additions & 3 deletions R/tag-version.R
Expand Up @@ -5,21 +5,24 @@ tag_version_impl <- function(force) {
desc <- desc::desc(file = "DESCRIPTION")
version <- desc$get_version()

cli_h2("Tagging Version")

tag <- paste0("v", version)
if (tag %in% names(git2r::tags())) {
if (!force) {
if (git2r::sha(get_repo_head(tag)) == git2r::sha(get_repo_head())) {
ui_info("Tag {ui_value(tag)} exists and points to the current commit.")
cli_alert_info("Tag {.field {tag}} exists and points to the current commit.")
} else {
abort(paste0("Tag ", tag, " exists, use `force = TRUE` to overwrite."))
}
} else {
ui_done("Deleting tag {ui_value(tag)}")
cli_alert("Deleting tag {.field {tag}}.")
git2r::tag_delete(".", tag)
}
}

ui_done("Creating tag {ui_value(tag)} with tag message derived from {ui_path('NEWS.md')}")
cli_alert("Creating tag {.field {tag}} with tag message derived from
{.file NEWS.md}.", wrap = TRUE)
msg_header <- paste0(desc$get("Package"), " ", version)
git2r::tag(".", tag, message = paste0(msg_header, "\n\n", current_news))

Expand Down
12 changes: 6 additions & 6 deletions R/unbump-version.R
Expand Up @@ -4,19 +4,19 @@ unbump_version_impl <- function() {
tag <- get_last_tag()
last_commit <- git2r::last_commit()

ui_info("Checking if working copy is clean")
cli_alert_info("Checking if working copy is clean.")
stopifnot(sum(map_int(git2r::status(), length)) == 0)
ui_info("Checking if last tag points to last commit")
cli_alert_info("Checking if last tag points to last commit.")
stopifnot(tag$target == last_commit$sha)
ui_info("Checking if commit messages match")
cli_alert_info("Checking if commit messages match.")
stopifnot(is_last_commit_bump())

ui_done("Safety checks complete")
cli_alert_success("Safety checks complete.")

ui_done("Deleting tag {ui_value(tag$name)}")
cli_alert("Deleting tag {.field {tag$name}}.")
git2r::tag_delete(tag)

parent_commit <- git2r::parents(last_commit)[[1]]
ui_done("Resetting to parent commit {ui_value(parent_commit$sha)}")
cli_alert_success("Resetting to parent commit {.field {parent_commit$sha}}.")
git2r::reset(parent_commit, "hard")
}
7 changes: 4 additions & 3 deletions R/update-news.R
@@ -1,12 +1,13 @@
update_news_impl <- function(range) {
news <- collect_news(range)

ui_done("Adding new entries to {ui_path(news_path)}")
cli_h2("Updating NEWS")
cli_alert("Adding new entries to {.file {news_path}}.")
add_to_news(news)
}

collect_news <- function(range) {
ui_done("Scraping {ui_value(length(range))} commit messages")
cli_alert("Scraping {.field {length(range)}} commit messages.")

messages <- gsub("\r\n", "\n", map_chr(range, "message"))
messages_before_triple_dash <- map_chr(strsplit(messages, "\n---", fixed = TRUE), 1)
Expand All @@ -22,7 +23,7 @@ collect_news <- function(range) {
}
}

ui_done("Found {ui_value(length(message_items))} NEWS-worthy entries.")
cli_alert_success("Found {.field {length(message_items)}} NEWS-worthy entries.")
paste0(paste(message_items, collapse = "\n"), "\n\n")
}

Expand Down
6 changes: 4 additions & 2 deletions R/update-version.R
Expand Up @@ -10,9 +10,11 @@ update_version_impl <- function(which) {

new_version <- desc$get_version()

ui_done("Package version bumped to {ui_value(new_version)}")
cli_h2("Update Version")

ui_done("Adding header to {ui_path(news_path)}")
cli_alert_success("Package version bumped to {.field {new_version}}.")

cli_alert("Adding header to {.file {news_path}}.")

header <- paste0(
"# ", desc$get("Package"), " ", new_version,
Expand Down