Skip to content

Commit

Permalink
Merge branch 'main' into olivroy-quarto-articles
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Nov 21, 2024
2 parents 08b0a84 + 487688b commit 3b9670c
Show file tree
Hide file tree
Showing 32 changed files with 225 additions and 154 deletions.
8 changes: 6 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

* `use_vignette()` and `use_article()` gain `type` to allow creating Quarto vignettes and articles (@olivroy, #1997).

* `use_tidy_upkeep_issue()` now records the year it is being run in the
`Config/usethis/upkeep` field in DESCRIPTION. If this value exists it is
furthermore used to filter the checklist when making the issue.

* `use_package()` now decreases a package minimum version required when
`min_version` is lower than what is currently specified in the DESCRIPTION
file (@jplecavalier, #1957).

* `use_data()` now uses serialization version 3 by default. (@laurabrianna, #2044)

* Reverse dependency checks are only suggested if they exist
* Reverse dependency checks are only suggested if they exist
(#1817, @seankross).

# usethis 3.0.0
Expand Down
3 changes: 1 addition & 2 deletions R/author.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
#' DESCRIPTION file and the user hasn't given any author information via the
#' `fields` argument or the global option `"usethis.description"`. The
#' placeholder looks something like `First Last <[email protected]> [aut,
#' cre] (YOUR-ORCID-ID)` and `use_author()` offers to remove it in interactive
#' sessions.
#' cre]` and `use_author()` offers to remove it in interactive sessions.
#'
#' @inheritParams utils::person
#' @inheritDotParams utils::person
Expand Down
12 changes: 7 additions & 5 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ use_data <- function(...,

objs <- get_objs_from_dots(dots(...))

if (version < 3) {
use_dependency("R", "depends", "2.10")
} else {
use_dependency("R", "depends", "3.5")
original_minimum_r_version <- pkg_minimum_r_version()
serialization_minimum_r_version <- if (version < 3) "2.10" else "3.5"
if (is.na(original_minimum_r_version) ||
original_minimum_r_version < serialization_minimum_r_version) {
use_dependency("R", "depends", serialization_minimum_r_version)
}

if (internal) {
use_directory("R")
paths <- path("R", "sysdata.rda")
Expand Down Expand Up @@ -92,7 +94,7 @@ get_objs_from_dots <- function(.dots) {
}

is_name <- vapply(.dots, is.symbol, logical(1))
if (any(!is_name)) {
if (!all(is_name)) {
ui_abort("Can only save existing named objects.")
}

Expand Down
2 changes: 1 addition & 1 deletion R/description.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ usethis_description_defaults <- function(package = NULL) {
Version = "0.0.0.9000",
Title = "What the Package Does (One Line, Title Case)",
Description = "What the package does (one paragraph).",
"Authors@R" = 'person("First", "Last", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "YOUR-ORCID-ID"))',
"Authors@R" = 'person("First", "Last", email = "[email protected]", role = c("aut", "cre"))',
License = "`use_mit_license()`, `use_gpl3_license()` or friends to pick a license",
Encoding = "UTF-8"
)
Expand Down
60 changes: 18 additions & 42 deletions R/git-default-branch.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,39 +93,18 @@ NULL
#' git_default_branch()
#' }
git_default_branch <- function() {
repo <- git_repo()
git_default_branch_(github_remote_config())
}

# TODO: often when we call git_default_branch(), we already have a GitHub
# configuration or target repo, as produced by github_remote_config() or
# target_repo(). In that case, we don't need to start from scratch as we do
# here. But I'm not sure it's worth adding complexity to allow passing this
# data in.

# TODO: this critique feels somewhat mis-placed, i.e. it brings up a general
# concern about a repo's config (or the user's permissions and creds)
# related to whether github_remotes() should be as silent as it is about
# 404s
critique_remote <- function(remote) {
if (remote$is_configured && is.na(remote$default_branch)) {
ui_bullets(c(
"x" = "The {.val {remote$name}} remote is configured, but we can't
determine its default branch.",
" " = "Possible reasons:",
"*" = "The remote repo no longer exists, suggesting the local remote
should be deleted.",
"*" = "We are offline or that specific Git server is down.",
"*" = "You don't have the necessary permission or something is wrong
with your credentials."
))
}
}
# If config is available, we can use it to avoid an additional lookup
# on the GitHub API
git_default_branch_ <- function(cfg) {
repo <- git_repo()

upstream <- git_default_branch_remote("upstream")
upstream <- git_default_branch_remote(cfg, "upstream")
if (is.na(upstream$default_branch)) {
critique_remote(upstream)
origin <- git_default_branch_remote("origin")
origin <- git_default_branch_remote(cfg, "origin")
if (is.na(origin$default_branch)) {
critique_remote(origin)
db_source <- list()
} else {
db_source <- origin
Expand Down Expand Up @@ -186,7 +165,7 @@ git_default_branch <- function() {

# returns a whole data structure, because the caller needs the surrounding
# context to produce a helpful error message
git_default_branch_remote <- function(remote = "origin") {
git_default_branch_remote <- function(cfg, remote = "origin") {
repo <- git_repo()
out <- list(
name = remote,
Expand All @@ -196,25 +175,22 @@ git_default_branch_remote <- function(remote = "origin") {
default_branch = NA_character_
)

url <- git_remotes()[[remote]]
if (length(url) == 0) {
cfg_remote <- cfg[[remote]]
if (!cfg_remote$is_configured) {
out$is_configured <- FALSE
return(out)
}

out$is_configured <- TRUE
out$url <- url

# TODO: generalize here for GHE hosts that don't include 'github'
parsed <- parse_github_remotes(url)
# if the protocol is ssh, I suppose we can't assume a PAT, i.e. it's better
# to use the Git approach vs. the GitHub API approach
if (grepl("github", parsed$host) && parsed$protocol == "https") {
remote_dat <- github_remotes(remote, github_get = NA)
out$repo_spec <- remote_dat$repo_spec
out$default_branch <- remote_dat$default_branch
out$url <- cfg_remote$url

if (!is.na(cfg_remote$default_branch)) {
out$repo_spec <- cfg_remote$repo_spec
out$default_branch <- cfg_remote$default_branch
return(out)
}

# Fall back to pure git based approach
out$default_branch <- tryCatch(
{
gert::git_fetch(remote = remote, repo = repo, verbose = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/github.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use_github <- function(organisation = NULL,
visibility <- match.arg(visibility)
check_protocol(protocol)
check_uses_git()
default_branch <- git_default_branch()
default_branch <- guess_local_default_branch()
check_current_branch(
is = default_branch,
# glue-ing happens inside check_current_branch(), where `gb` gives the
Expand Down
68 changes: 37 additions & 31 deletions R/pr.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,30 +167,41 @@ pr_init <- function(branch) {
cfg <- github_remote_config(github_get = NA)
check_for_bad_config(cfg)
tr <- target_repo(cfg, ask = FALSE)
online <- is_online(tr$host)

maybe_good_configs <- c("maybe_ours_or_theirs", "maybe_fork")
if (cfg$type %in% maybe_good_configs) {
if (!online) {
ui_bullets(c(
"x" = 'Unable to confirm the GitHub remote configuration is
"pull request ready".',
"i" = "You probably need to configure a personal access token for
{.val {tr$host}}.",
"i" = "See {.run usethis::gh_token_help()} for help with that.",
"i" = "(Or maybe we're just offline?)"
"x" = "You are not currently online.",
"i" = "You can still create a local branch, but we can't check that your
current branch is up-to-date or setup the remote branch."
))
if (ui_github_remote_config_wat(cfg)) {
if (ui_nah("Do you want to continue?")) {
ui_bullets(c("x" = "Cancelling."))
return(invisible())
}
} else {
maybe_good_configs <- c("maybe_ours_or_theirs", "maybe_fork")
if (cfg$type %in% maybe_good_configs) {
ui_bullets(c(
"x" = 'Unable to confirm the GitHub remote configuration is
"pull request ready".',
"i" = "You probably need to configure a personal access token for
{.val {tr$host}}.",
"i" = "See {.run usethis::gh_token_help()} for help with that."
))
if (ui_github_remote_config_wat(cfg)) {
ui_bullets(c("x" = "Cancelling."))
return(invisible())
}
}
}

default_branch <- git_default_branch()
default_branch <- if (online) git_default_branch_(cfg) else guess_local_default_branch()
challenge_non_default_branch(
"Are you sure you want to create a PR branch based on a non-default branch?",
default_branch = default_branch
)

online <- is_online(tr$host)
if (online) {
# this is not pr_pull_source_override() because:
# a) we may NOT be on default branch (although we probably are)
Expand All @@ -213,10 +224,6 @@ pr_init <- function(branch) {
ui_bullets(c("v" = "Pulling changes from {.val {remref}}."))
git_pull(remref = remref, verbose = FALSE)
}
} else {
ui_bullets(c(
"!" = "Unable to pull changes for current branch, since we are offline."
))
}

ui_bullets(c("v" = "Creating and switching to local branch {.val {branch}}."))
Expand All @@ -237,7 +244,7 @@ pr_resume <- function(branch = NULL) {
ui_bullets(c(
"i" = "No branch specified ... looking up local branches and associated PRs."
))
default_branch <- git_default_branch()
default_branch <- guess_local_default_branch()
branch <- choose_branch(exclude = default_branch)
if (is.null(branch)) {
ui_bullets(c("x" = "Repo doesn't seem to have any non-default branches."))
Expand Down Expand Up @@ -375,7 +382,7 @@ pr_push <- function() {
repo <- git_repo()
cfg <- github_remote_config(github_get = TRUE)
check_for_config(cfg, ok_configs = c("ours", "fork"))
default_branch <- git_default_branch()
default_branch <- git_default_branch_(cfg)
check_pr_branch(default_branch)
challenge_uncommitted_changes()

Expand Down Expand Up @@ -423,7 +430,7 @@ pr_push <- function() {
pr_pull <- function() {
cfg <- github_remote_config(github_get = TRUE)
check_for_config(cfg)
default_branch <- git_default_branch()
default_branch <- git_default_branch_(cfg)
check_pr_branch(default_branch)
challenge_uncommitted_changes()

Expand All @@ -449,11 +456,12 @@ pr_merge_main <- function() {
#' @export
#' @rdname pull-requests
pr_view <- function(number = NULL, target = c("source", "primary")) {
tr <- target_repo(github_get = NA, role = target, ask = FALSE)
cfg <- github_remote_config(github_get = NA)
tr <- target_repo(cfg, github_get = NA, role = target, ask = FALSE)
url <- NULL
if (is.null(number)) {
branch <- git_branch()
default_branch <- git_default_branch()
default_branch <- git_default_branch_(cfg)
if (branch != default_branch) {
url <- pr_url(branch = branch, tr = tr)
if (is.null(url)) {
Expand Down Expand Up @@ -491,11 +499,11 @@ pr_view <- function(number = NULL, target = c("source", "primary")) {
#' @export
#' @rdname pull-requests
pr_pause <- function() {
# intentionally naive selection of target repo
tr <- target_repo(github_get = FALSE, ask = FALSE)
cfg <- github_remote_config(github_get = NA)
tr <- target_repo(cfg, github_get = NA, ask = FALSE)

ui_bullets(c("v" = "Switching back to the default branch."))
default_branch <- git_default_branch()
default_branch <- git_default_branch_(cfg)
if (git_branch() == default_branch) {
ui_bullets(c(
"!" = "Already on this repo's default branch ({.val {default_branch}}),
Expand Down Expand Up @@ -535,8 +543,10 @@ pr_clean <- function(number = NULL,
withr::defer(rstudio_git_tickle())
mode <- match.arg(mode)
repo <- git_repo()
tr <- target_repo(github_get = NA, role = target, ask = FALSE)
default_branch <- git_default_branch()

cfg <- github_remote_config(github_get = NA)
tr <- target_repo(cfg, github_get = NA, role = target, ask = FALSE)
default_branch <- git_default_branch_(cfg)

if (is.null(number)) {
check_pr_branch(default_branch)
Expand Down Expand Up @@ -629,14 +639,10 @@ pr_clean <- function(number = NULL,
# we're in DEFAULT branch of a fork. I wish everyone set up DEFAULT to track the
# DEFAULT branch in the source repo, but this protects us against sub-optimal
# setup.
pr_pull_source_override <- function(tr = NULL, default_branch = NULL) {
# naive selection of target repo; calling function should analyse the config
tr <- tr %||% target_repo(github_get = FALSE, ask = FALSE)

pr_pull_source_override <- function(tr, default_branch) {
# TODO: why does this not use a check_*() function, i.e. shared helper?
# I guess to issue a specific error message?
current_branch <- git_branch()
default_branch <- default_branch %||% git_default_branch()
if (current_branch != default_branch) {
ui_abort("
Internal error: {.fun pr_pull_source_override} should only be used when on
Expand Down Expand Up @@ -994,7 +1000,7 @@ pr_branch_delete <- function(pr) {
invisible(TRUE)
}

check_pr_branch <- function(default_branch = git_default_branch()) {
check_pr_branch <- function(default_branch) {
# the glue-ing happens inside check_current_branch(), where `gb` gives the
# current git branch
check_current_branch(
Expand Down
2 changes: 1 addition & 1 deletion R/proj-desc.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ proj_desc_field_update <- function(key, value, overwrite = TRUE, append = FALSE)
return(invisible())
}

if (!overwrite && length(old > 0) && any(old != "")) {
if (!overwrite && length(old) > 0 && any(old != "")) {
ui_abort("
{.field {key}} has a different value in DESCRIPTION.
Use {.code overwrite = TRUE} to overwrite.")
Expand Down
7 changes: 4 additions & 3 deletions R/release.R
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,11 @@ author_has_rstudio_email <- function() {
pkg_minimum_r_version <- function() {
deps <- proj_desc()$get_deps()
r_dep <- deps[deps$package == "R" & deps$type == "Depends", "version"]
if (length(r_dep) == 0) {
return(numeric_version("0"))
if (length(r_dep) > 0) {
numeric_version(gsub("[^0-9.]", "", r_dep))
} else {
NA_character_
}
numeric_version(gsub("[^0-9.]", "", r_dep))
}

# Borrowed from pak, but modified also retain user's non-cran repos:
Expand Down
4 changes: 3 additions & 1 deletion R/tidyverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
#' tidyverse conventions around GitHub issue label names and colours.
#'
#' * `use_tidy_upkeep_issue()` creates an issue containing a checklist of
#' actions to bring your package up to current tidyverse standards.
#' actions to bring your package up to current tidyverse standards. Also
#' records the current date in the `Config/usethis/last-upkeep` field in
#' `DESCRIPTION`.
#'
#' * `use_tidy_logo()` calls `use_logo()` on the appropriate hex sticker PNG
#' file at <https://github.com/rstudio/hex-stickers>.
Expand Down
4 changes: 2 additions & 2 deletions R/ui-legacy.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#'
#' usethis itself now uses cli internally for its UI, but these new functions
#' are not exported and presumably never will be. There is a developer-focused
#' article on the process of transitioning usethis's own UI to use cli (LINK
#' TO COME).
#' article on the process of transitioning usethis's own UI to use cli:
#' [Converting usethis's UI to use cli](https://usethis.r-lib.org/articles/ui-cli-conversion.html).

#' @details
#'
Expand Down
Loading

0 comments on commit 3b9670c

Please sign in to comment.