Skip to content

Commit

Permalink
chore: Move responsibility for writing fledgeling, memoise, add `repo…
Browse files Browse the repository at this point in the history
…` argument (#761)
  • Loading branch information
aviator-app[bot] authored Feb 18, 2024
2 parents 1f14197 + 792191a commit 707c8eb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Imports:
glue,
httr2,
lifecycle,
memoise,
pandoc,
parsedate,
purrr (>= 0.3.2),
Expand Down
3 changes: 2 additions & 1 deletion R/api-update-news.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ update_news <- function(
)
}

update_news_impl(
fledgeling <- update_news_impl(
commits = commits,
which = which
)
write_fledgling(fledgeling)

invisible(NULL)
}
Expand Down
22 changes: 12 additions & 10 deletions R/bump-version.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ bump_version_impl <- function(fledgeling,
)
#' 1. Depending on the `which` argument:
if (which == "dev") {
write_fledgling(out)
#' - If `"dev"`, [finalize_version()] with `push = FALSE`
finalize_version_impl(push = FALSE, suggest_finalize = edit)
} else {
write_fledgling(out)
#' - Otherwise, [commit_version()].
commit_version()

Expand Down Expand Up @@ -69,32 +71,32 @@ check_cran_branch <- function(reason) {
cli::cli_abort(
c(
x = "Must be on the a release branch that starts with {.val cran-} for running {.code {reason}}.",
i = "Currently on branch {.val {get_branch_name()}}.",
i = if (reason == "pre_release()") "Do you need to call {.code init_release()} first?"
i = "Currently on branch {.val {get_branch_name()}}."
)
)
}
}

get_main_branch <- function() {
get_main_branch <- function(repo = getwd()) {
remote <- "origin"
if (remote %in% gert::git_remote_list()$name) {
remote_main <- get_main_branch_remote(remote)
remote_list <- gert::git_remote_list(repo)
if (remote %in% remote_list$name) {
remote_main <- get_main_branch_remote(remote, repo)
if (length(remote_main)) {
return(remote_main)
}
}

get_main_branch_config()
get_main_branch_config(repo)
}

get_main_branch_remote <- function(remote) {
remotes <- gert::git_remote_ls(verbose = FALSE, remote = remote)
get_main_branch_remote <- function(remote, repo) {
remotes <- gert::git_remote_ls(repo = repo, verbose = FALSE, remote = remote)
basename(as.character(remotes$symref[remotes$ref == "HEAD"]))
}

get_main_branch_config <- function() {
config <- gert::git_config()
get_main_branch_config <- function(repo) {
config <- gert::git_config(repo)
init <- config[config$name == "init.defaultbranch", ]
local <- init[init$level == "local", ]

Expand Down
5 changes: 2 additions & 3 deletions R/update-news.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ update_news_impl <- function(commits,
fledgeling[["news"]]$news[[1]] <- regroup_news(combined)
fledgeling[["news"]][1, ]$section_state <- "new"
}
write_fledgling(fledgeling)

if (fledge_chatty()) {
cli_alert("Added items to {.file {news_path()}}.")
Expand Down Expand Up @@ -119,8 +118,6 @@ update_news_impl <- function(commits,
)
}

write_fledgling(fledgeling)

if (fledge_chatty()) {
cli_h2("Updating Version")

Expand All @@ -129,6 +126,8 @@ update_news_impl <- function(commits,
cli_alert("Added header to {.file {news_path()}}.")
}
}

fledgeling
}

news_path <- function() {
Expand Down
3 changes: 3 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.onLoad <- function(libname, pkgname) {
get_main_branch <<- memoise::memoise(get_main_branch)
}
1 change: 0 additions & 1 deletion tests/testthat/_snaps/auto.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
Error in `check_cran_branch()`:
x Must be on the a release branch that starts with "cran-" for running `pre_release()`.
i Currently on branch "main".
i Do you need to call `init_release()` first?

---

Expand Down

0 comments on commit 707c8eb

Please sign in to comment.