Skip to content

Commit dbcaf1e

Browse files
committed
fix message structure devCheckout
1 parent 123d549 commit dbcaf1e

3 files changed

Lines changed: 66 additions & 40 deletions

File tree

‎R/versionControl.R‎

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,31 @@ issueOpen <- function(
6060
"gh_response"
6161
)
6262
if (isTRUE(issue_created)) {
63-
cli::cli_alert_success(
64-
"Issue created at:"
65-
)
66-
cat(issue_data$html_url, "\n")
67-
invisible(issue_data$html_url)
68-
}
69-
if (isTRUE(issue_created) & isTRUE(newBranch)) {
70-
branch_title <- stringr::word(title, 1, 2) |>
71-
tolower() |>
72-
stringr::str_replace_all(
73-
pattern = " ",
74-
replacement = "_"
63+
issue_url <- issue_data$html_url
64+
if (isTRUE(newBranch)) {
65+
branch_title <- stringr::word(title, 1, 2) |>
66+
tolower() |>
67+
stringr::str_replace_all(
68+
pattern = " ",
69+
replacement = "_"
70+
)
71+
branch_name <- glue::glue(
72+
"{issue_data$number}_{branch_title}"
7573
)
76-
branch_name <- glue::glue(
77-
"{issue_data$number}_{branch_title}"
78-
)
79-
gert::git_branch_create(
80-
branch = branch_name,
81-
ref = gert::git_branch(),
82-
checkout = TRUE,
83-
force = FALSE,
84-
repo = "."
85-
)
86-
gert::git_push(
87-
remote = "origin",
88-
set_upstream = TRUE
89-
)
74+
gert::git_branch_create(
75+
branch = branch_name,
76+
ref = gert::git_branch(),
77+
checkout = TRUE,
78+
force = FALSE,
79+
repo = "."
80+
)
81+
gert::git_push(
82+
remote = "origin",
83+
set_upstream = TRUE
84+
)
85+
}
86+
message("Issue created: ", issue_url)
87+
return(invisible(issue_url))
9088
}
9189
}
9290

@@ -151,11 +149,9 @@ pullRequest <- function(
151149
"gh_response"
152150
)
153151
if (isTRUE(pr_created)) {
154-
cli::cli_alert_success(
155-
"Pull request created at:"
156-
)
157-
cat(prData$html_url, "\n")
158-
invisible(prData$html_url)
152+
pr_url <- prData$html_url
153+
message("Pull request created: ", pr_url)
154+
return(invisible(pr_url))
159155
}
160156
}
161157

@@ -164,17 +160,20 @@ pullRequest <- function(
164160
#' @description
165161
#' Checks out the `develop` branch and pulls changes from its remote.
166162
#'
167-
#' @returns Git log messages after checking out and pulling 'develop'
163+
#' @param verbose Logical. Whether to report successful checkout and update of
164+
#' `develop`. Defaults to `FALSE`.
165+
#'
166+
#' @returns Invisibly, the result of pulling `develop`.
168167
#' @export
169168
#'
170169
#' @examples
171170
#' \dontrun{
172171
#' # Requires access to the configured Git remote
173-
#' devCheckout(
174-
#' )
172+
#' devCheckout(verbose = TRUE)
175173
#' }
176-
devCheckout <- function() {
174+
devCheckout <- function(verbose = FALSE) {
177175
requireInstall("gert")
176+
checkmate::assertLogical(verbose, len = 1, any.missing = FALSE)
178177
branch <- "develop"
179178
if (gert::git_branch_exists(branch)) {
180179
gert::git_branch_checkout(
@@ -183,6 +182,11 @@ devCheckout <- function() {
183182
orphan = FALSE,
184183
repo = "."
185184
)
186-
gert::git_pull()
185+
pull_result <- gert::git_pull()
186+
if (isTRUE(verbose)) {
187+
message("Checked out and updated develop.")
188+
}
189+
return(invisible(pull_result))
187190
}
191+
invisible(NULL)
188192
}

‎man/devCheckout.Rd‎

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
test_that("devCheckout reports completion only when verbose", {
2+
testthat::local_mocked_bindings(
3+
git_branch_exists = function(...) TRUE,
4+
git_branch_checkout = function(...) "/tmp/repo",
5+
git_pull = function(...) "/tmp/repo",
6+
.package = "gert"
7+
)
8+
9+
quiet_result <- expect_silent(withVisible(devCheckout()))
10+
expect_false(quiet_result$visible)
11+
expect_identical(quiet_result$value, "/tmp/repo")
12+
13+
expect_message(
14+
verbose_result <- withVisible(devCheckout(verbose = TRUE)),
15+
"Checked out and updated develop."
16+
)
17+
expect_false(verbose_result$visible)
18+
expect_identical(verbose_result$value, "/tmp/repo")
19+
})

0 commit comments

Comments
 (0)