Skip to content

Commit

Permalink
Merged upstream/main into olivroy-challenge-uncommited-tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Jul 25, 2024
2 parents b9794fa + 46e3fef commit af2f01b
Show file tree
Hide file tree
Showing 51 changed files with 652 additions and 463 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ Config/testthat/start-first: github-actions, release
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
5 changes: 0 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export(browse_cran)
export(browse_github)
export(browse_github_actions)
export(browse_github_issues)
export(browse_github_pat)
export(browse_github_pulls)
export(browse_github_token)
export(browse_package)
export(browse_project)
export(browse_travis)
Expand Down Expand Up @@ -45,7 +43,6 @@ export(git_protocol)
export(git_remotes)
export(git_sitrep)
export(git_vaccinate)
export(github_token)
export(issue_close_community)
export(issue_reprex_needed)
export(local_project)
Expand All @@ -56,10 +53,8 @@ export(pr_init)
export(pr_merge_main)
export(pr_pause)
export(pr_pull)
export(pr_pull_upstream)
export(pr_push)
export(pr_resume)
export(pr_sync)
export(pr_view)
export(proj_activate)
export(proj_get)
Expand Down
397 changes: 214 additions & 183 deletions NEWS.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions R/badge.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use_badge <- function(badge_name, href, src) {
if (is.null(path)) {
ui_bullets(c(
"!" = "Can't find a README for the current project.",
"i" = "See {.help usethis::use_readme_rmd} for help creating this file.",
"i" = "See {.fun usethis::use_readme_rmd} for help creating this file.",
"i" = "Badge link will only be printed to screen."
))
path <- "README"
Expand All @@ -60,7 +60,7 @@ use_badge <- function(badge_name, href, src) {

if (changed && path_ext(path) == "Rmd") {
ui_bullets(c(
"_" = "Re-knit {.path {pth(path)}} with {.fun devtools::build_readme}."
"_" = "Re-knit {.path {pth(path)}} with {.run devtools::build_readme()}."
))
}
invisible(changed)
Expand Down
5 changes: 2 additions & 3 deletions R/coverage.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ use_covr_ignore <- function(files) {
}

use_codecov_badge <- function(repo_spec) {
default_branch <- git_default_branch()
url <- glue("https://app.codecov.io/gh/{repo_spec}?branch={default_branch}")
img <- glue("https://codecov.io/gh/{repo_spec}/branch/{default_branch}/graph/badge.svg")
url <- glue("https://codecov.io/gh/{repo_spec}")
img <- glue("https://codecov.io/gh/{repo_spec}/graph/badge.svg")
use_badge("Codecov test coverage", url, img)
}

Expand Down
3 changes: 3 additions & 0 deletions R/create.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#' any existing files are changed.
#'
#' @inheritParams use_description
#' @param fields A named list of fields to add to `DESCRIPTION`, potentially
#' overriding default values. See [use_description()] for how you can set
#' personalized defaults using package options.
#' @param path A path. If it exists, it is used. If it does not exist, it is
#' created, provided that the parent path exists.
#' @param roxygen Do you plan to use roxygen2 to document your package?
Expand Down
7 changes: 4 additions & 3 deletions R/description.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#' usethis consults the following sources, in this order, to set `DESCRIPTION`
#' fields:
#' * `fields` argument of [create_package()] or [use_description()]
#' * `fields` argument of [create_package()] or `use_description()`
#' * `getOption("usethis.description")`
#' * Defaults built into usethis
#'
Expand Down Expand Up @@ -44,8 +44,9 @@
#' supported.
#'
#' @param fields A named list of fields to add to `DESCRIPTION`, potentially
#' overriding default values. See [use_description()] for how you can set
#' personalized defaults using package options.
#' overriding default values. Default values are taken from the
#' `"usethis.description"` option or the usethis package (in that order), and
#' can be viewed with `use_description_defaults()`.
#' @param check_name Whether to check if the name is valid for CRAN and throw an
#' error if not.
#' @param roxygen If `TRUE`, sets `RoxygenNote` to current roxygen2 version
Expand Down
4 changes: 2 additions & 2 deletions R/edit.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ choose_template <- function() {
#' * `edit_pkgdown_config` opens the pkgdown YAML configuration file for the
#' current Project.
#' * `edit_rstudio_snippets()` opens RStudio's snippet config for the given type.
#' * `edit_rstudio_prefs()` opens RStudio's preference file.
#' * `edit_rstudio_prefs()` opens [RStudio's preference file][use_rstudio_preferences()].
#'
#' The `edit_r_*()` functions consult R's notion of user's home directory.
#' The `edit_git_*()` functions (and \pkg{usethis} in general) inherit home
Expand Down Expand Up @@ -144,7 +144,7 @@ edit_r_makevars <- function(scope = c("user", "project")) {
#' @param type Snippet type (case insensitive text).
edit_rstudio_snippets <- function(type = c(
"r", "markdown", "c_cpp", "css",
"html", "java", "javascript", "python", "sql", "stan", "tex"
"html", "java", "javascript", "python", "sql", "stan", "tex", "yaml"
)) {

type <- tolower(type)
Expand Down
9 changes: 8 additions & 1 deletion R/git.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ use_git <- function(message = "Initial commit") {
if (needs_init) {
ui_bullets(c("v" = "Initialising Git repo."))
git_init()
# hacky but helps prevent a pop-up in Positron, where early attempts to
# interact with a newly created repo lead to:
# Git: There are no available repositories
# https://github.com/r-lib/usethis/pull/2011#issue-2380380721
if (is_positron()) {
Sys.sleep(1)
}
}

use_git_ignore(git_ignore_lines)
if (git_uncommitted(untracked = TRUE)) {
git_ask_commit(message, untracked = TRUE)
}

if (needs_init) {
if (needs_init && !is_positron()) {
restart_rstudio("A restart of RStudio is required to activate the Git pane.")
}

Expand Down
21 changes: 12 additions & 9 deletions R/github.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ use_github_links <- function(auth_token = deprecated(),
invisible()
}

has_github_links <- function() {
github_url <- github_url_from_git_remotes()
has_github_links <- function(target_repo = NULL) {
url <- if (is.null(target_repo)) NULL else target_repo$url
github_url <- github_url_from_git_remotes(url)
if (is.null(github_url)) {
return(FALSE)
}
Expand Down Expand Up @@ -269,21 +270,23 @@ check_no_origin <- function() {
}

check_no_github_repo <- function(owner, repo, host) {
spec <- glue("{owner}/{repo}")
repo_found <- tryCatch(
{
repo_info <- gh::gh(
"/repos/{owner}/{repo}",
owner = owner, repo = repo,
.api_url = host
)
TRUE
repo_info <- gh::gh("/repos/{spec}", spec = spec, .api_url = host)
# when does repo_info$full_name != the spec we sent?
# this happens if you reuse the original name of a repo that has since
# been renamed
# there's no 404, because of the automatic redirect, but you CAN create
# a new repo with this name
# https://github.com/r-lib/usethis/issues/1893
repo_info$full_name == spec
},
"http_error_404" = function(err) FALSE
)
if (!repo_found) {
return(invisible())
}
spec <- glue("{owner}/{repo}")
empirical_host <- parse_github_remotes(repo_info$html_url)$host
ui_abort("Repo {.val {spec}} already exists on {.val {empirical_host}}.")
}
27 changes: 19 additions & 8 deletions R/github_token.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,23 @@ create_github_token <- function(scopes = c("repo", "user", "gist", "workflow"),
withr::defer(view_url(url))

hint <- code_hint_with_host("gitcreds::gitcreds_set", host)
ui_bullets(c(
"_" = "Call {.code {hint}} to register this token in the local Git
credential store.",
message <- c(
"_" = "Call {.run {hint}} to register this token in the local Git
credential store."
)
if (is_linux()) {
message <- c(
message,
"!" = "On Linux, it can be tricky to store credentials persistently.",
"i" = "Read more in the {.href ['Managing Git(Hub) Credentials' article](https://usethis.r-lib.org/articles/articles/git-credentials.html)}."
)
}
message <- c(
message,
"i" = "It is also a great idea to store this token in any
password-management software that you use."
))
)
ui_bullets(message)
invisible()
}

Expand Down Expand Up @@ -130,14 +141,14 @@ pat_sitrep <- function(host = "https://github.com",

if (!have_pat) {
kv_line("Personal access token for {.val {host}}", NULL)
hint <- code_hint_with_host("create_github_token", host, "host")
hint <- code_hint_with_host("usethis::create_github_token", host, "host")
ui_bullets(c(
"_" = "To create a personal access token, call {.code {hint}}."
"_" = "To create a personal access token, call {.run {hint}}."
))
hint <- code_hint_with_host("gitcreds::gitcreds_set", host)
url <- "https://usethis.r-lib.org/articles/articles/git-credentials.html"
ui_bullets(c(
"_" = "To store a token for current and future use, call {.code {hint}}.",
"_" = "To store a token for current and future use, call {.run {hint}}.",
"i" = "Read more in the {.href [Managing Git(Hub) Credentials]({url})} article."
))
return(invisible(FALSE))
Expand Down Expand Up @@ -166,7 +177,7 @@ pat_sitrep <- function(host = "https://github.com",
}
message <- c(
message,
"i" = maybe_who$error
"i" = maybe_who$error$message
)
ui_bullets(message)
return(invisible(FALSE))
Expand Down
29 changes: 22 additions & 7 deletions R/import-standalone-obj-type.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
# Standalone file: do not edit by hand
# Source: <https://github.com/r-lib/rlang/blob/main/R/standalone-obj-type.R>
# Source: https://github.com/r-lib/rlang/blob/HEAD/R/standalone-obj-type.R
# Generated by: usethis::use_standalone("r-lib/rlang", "obj-type")
# ----------------------------------------------------------------------
#
# ---
# repo: r-lib/rlang
# file: standalone-obj-type.R
# last-updated: 2022-10-04
# last-updated: 2024-02-14
# license: https://unlicense.org
# imports: rlang (>= 1.1.0)
# ---
#
# ## Changelog
#
# 2024-02-14:
# - `obj_type_friendly()` now works for S7 objects.
#
# 2023-05-01:
# - `obj_type_friendly()` now only displays the first class of S3 objects.
#
# 2023-03-30:
# - `stop_input_type()` now handles `I()` input literally in `arg`.
#
# 2022-10-04:
# - `obj_type_friendly(value = TRUE)` now shows numeric scalars
# literally.
Expand Down Expand Up @@ -65,7 +75,7 @@ obj_type_friendly <- function(x, value = TRUE) {
if (inherits(x, "quosure")) {
type <- "quosure"
} else {
type <- paste(class(x), collapse = "/")
type <- class(x)[[1L]]
}
return(sprintf("a <%s> object", type))
}
Expand Down Expand Up @@ -261,19 +271,19 @@ vec_type_friendly <- function(x, length = FALSE) {
#' Return OO type
#' @param x Any R object.
#' @return One of `"bare"` (for non-OO objects), `"S3"`, `"S4"`,
#' `"R6"`, or `"R7"`.
#' `"R6"`, or `"S7"`.
#' @noRd
obj_type_oo <- function(x) {
if (!is.object(x)) {
return("bare")
}

class <- inherits(x, c("R6", "R7_object"), which = TRUE)
class <- inherits(x, c("R6", "S7_object"), which = TRUE)

if (class[[1]]) {
"R6"
} else if (class[[2]]) {
"R7"
"S7"
} else if (isS4(x)) {
"S4"
} else {
Expand Down Expand Up @@ -315,10 +325,15 @@ stop_input_type <- function(x,
if (length(what)) {
what <- oxford_comma(what)
}
if (inherits(arg, "AsIs")) {
format_arg <- identity
} else {
format_arg <- cli$format_arg
}

message <- sprintf(
"%s must be %s, not %s.",
cli$format_arg(arg),
format_arg(arg),
what,
obj_type_friendly(x, value = show_value)
)
Expand Down
3 changes: 2 additions & 1 deletion R/import-standalone-types-check.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Standalone file: do not edit by hand
# Source: <https://github.com/r-lib/rlang/blob/main/R/standalone-types-check.R>
# Source: https://github.com/r-lib/rlang/blob/HEAD/R/standalone-types-check.R
# Generated by: usethis::use_standalone("r-lib/rlang", "types-check")
# ----------------------------------------------------------------------
#
# ---
Expand Down
13 changes: 9 additions & 4 deletions R/news.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,20 @@ use_news_heading <- function(version) {
}

news <- read_utf8(news_path)
title <- glue("# {project_name()} {version}")
idx <- match(TRUE, grepl("[^[:space:]]", news))

if (is.na(idx)) {
return(news)
}

if (title == news[[1]]) {
title <- glue("# {project_name()} {version}")
if (title == news[[idx]]) {
return(invisible())
}

development_title <- glue("# {project_name()} (development version)")
if (development_title == news[[1]]) {
news[[1]] <- title
if (development_title == news[[idx]]) {
news[[idx]] <- title

ui_bullets(c("v" = "Replacing development heading in {.path NEWS.md}."))
return(write_utf8(news_path, news))
Expand Down
3 changes: 2 additions & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
#' "Suggests", "Enhances", or "LinkingTo" (or unique abbreviation). Matching
#' is case insensitive.
#' @param min_version Optionally, supply a minimum version for the package. Set
#' to `TRUE` to use the currently installed version.
#' to `TRUE` to use the currently installed version or use a version string
#' suitable for [numeric_version()], such as "2.5.0".
#' @param remote By default, an `OWNER/REPO` GitHub remote is inserted.
#' Optionally, you can supply a character string to specify the remote, e.g.
#' `"gitlab::jimhester/covr"`, using any syntax supported by the [remotes
Expand Down
3 changes: 3 additions & 0 deletions R/positron.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
is_positron <- function() {
Sys.getenv("POSITRON") == "1"
}
4 changes: 2 additions & 2 deletions R/proj.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ proj_set <- function(path = ".", force = FALSE) {
if (is.null(new_project)) {
ui_abort(c(
"Path {.path {pth(path)}} does not appear to be inside a project or package.",
"Read more in the help for {.help usethis::proj_get}."
"Read more in the help for {.fun usethis::proj_get}."
))
}
proj_set(path = new_project, force = TRUE)
Expand Down Expand Up @@ -227,7 +227,7 @@ check_is_project <- function() {
if (!possibly_in_proj()) {
ui_abort(c(
"We do not appear to be inside a valid project or package.",
"Read more in the help for {.help usethis::proj_get}."
"Read more in the help for {.fun usethis::proj_get}."
))
}
}
Expand Down
Loading

0 comments on commit af2f01b

Please sign in to comment.