-
Notifications
You must be signed in to change notification settings - Fork 11
/
finalize-version.R
44 lines (38 loc) · 1.14 KB
/
finalize-version.R
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
#' @rdname finalize_version
#' @usage NULL
finalize_version_impl <- function(push) {
head <- get_head_branch()
#' @description
#' 1. [commit_version()]
force <- commit_version()
#' 1. [tag_version()], setting `force = TRUE` if and only if `commit_version()`
#' amended a commit.
tag <- tag_version(force)
#' 1. Force-pushes the created tag to the `"origin"` remote, if `push = TRUE`.
if (push) {
push_tag(tag)
push_head(head)
} else {
edit_news()
cli_alert_warning("Call {.code fledge::finalize_version(push = TRUE)}.")
send_to_console("fledge::finalize_version(push = TRUE)")
}
}
get_head_branch <- function() {
head <- git2r::repository_head()
stopifnot(git2r::is_branch(head))
head
}
push_tag <- function(tag) {
cli_alert("Force-pushing tag {.field {tag}}.")
git2r::push(name = "origin", refspec = paste0("refs/tags/", tag), force = TRUE)
}
push_head <- function(head) {
cli_alert('Pushing {.field {head$name}}.')
git2r::push(head)
}
send_to_console <- function(code) {
if (!is_installed("rstudioapi")) return()
if (!is_interactive()) return()
rstudioapi::sendToConsole(code, execute = FALSE)
}