Skip to content

Commit 2e59179

Browse files
committed
Merged upstream/main into olivroy-challenge-uncommited-tweaks
2 parents 5958d4a + 2248463 commit 2e59179

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+389
-821
lines changed

.covrignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
R/deprec-*.R
22
R/compat-*.R
3-
R/usethis-defunct.R
3+
R/usethis-deprecated.R

NAMESPACE

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export(browse_github_issues)
1414
export(browse_github_pulls)
1515
export(browse_package)
1616
export(browse_project)
17-
export(browse_travis)
1817
export(create_download_url)
1918
export(create_from_github)
2019
export(create_github_token)
@@ -34,7 +33,6 @@ export(edit_rstudio_snippets)
3433
export(edit_template)
3534
export(gh_token_help)
3635
export(git_branch_default)
37-
export(git_credentials)
3836
export(git_default_branch)
3937
export(git_default_branch_configure)
4038
export(git_default_branch_rediscover)
@@ -87,8 +85,6 @@ export(use_agpl3_license)
8785
export(use_agpl_license)
8886
export(use_apache_license)
8987
export(use_apl2_license)
90-
export(use_appveyor)
91-
export(use_appveyor_badge)
9288
export(use_article)
9389
export(use_author)
9490
export(use_badge)
@@ -121,7 +117,6 @@ export(use_devtools)
121117
export(use_directory)
122118
export(use_git)
123119
export(use_git_config)
124-
export(use_git_credentials)
125120
export(use_git_hook)
126121
export(use_git_ignore)
127122
export(use_git_protocol)
@@ -159,7 +154,6 @@ export(use_partial_warnings)
159154
export(use_pipe)
160155
export(use_pkgdown)
161156
export(use_pkgdown_github_pages)
162-
export(use_pkgdown_travis)
163157
export(use_posit_cloud_badge)
164158
export(use_proprietary_license)
165159
export(use_r)
@@ -180,9 +174,9 @@ export(use_spell_check)
180174
export(use_standalone)
181175
export(use_template)
182176
export(use_test)
177+
export(use_test_helper)
183178
export(use_testthat)
184179
export(use_tibble)
185-
export(use_tidy_ci)
186180
export(use_tidy_coc)
187181
export(use_tidy_contributing)
188182
export(use_tidy_dependencies)
@@ -192,14 +186,11 @@ export(use_tidy_github)
192186
export(use_tidy_github_actions)
193187
export(use_tidy_github_labels)
194188
export(use_tidy_issue_template)
195-
export(use_tidy_labels)
196189
export(use_tidy_logo)
197190
export(use_tidy_style)
198191
export(use_tidy_support)
199192
export(use_tidy_thanks)
200193
export(use_tidy_upkeep_issue)
201-
export(use_travis)
202-
export(use_travis_badge)
203194
export(use_tutorial)
204195
export(use_upkeep_issue)
205196
export(use_usethis)

NEWS.md

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# usethis (development version)
22

3-
* `browse_github_token()`, `browse_github_pat()`, and `github_token()` have been removed after being deprecated in usethis 2.0.0. `create_github_token()`, `gh::gh_token()`, and `gh_token_help()` should be used instead.
3+
* `use_test_helper()` is a new function to create a test helper file (@olivroy, #1822).
44

5-
* `pr_pull_upstream()` and `pr_sync()` have been removed after being deprecated in usethis 2.0.0. `pr_merge_main()` and `pr_push()` should be used instead.
5+
* `use_cpp11()` makes it easier to update `NAMESPACE` (@pachadotdev, #1921).
66

77
* `pr_merge_main()` now offers the choice to not open the files with merge conflicts (@olivroy, #1720).
88

@@ -44,6 +44,43 @@
4444
* `usethis::use_version()` now tolerates empty / blank lines preceding the
4545
first section title in the package NEWS file. (#1976)
4646

47+
## Deprecated function and argument removal
48+
49+
We are removing functions and arguments that were deprecated as of usethis
50+
v2.0.0, which was released in December 2020.
51+
52+
These changes have been in place for a long time now:
53+
54+
* Switch from git2r to gert (+ credentials).
55+
* Use of git config and the gh package to infer, e.g., the target repo spec.
56+
* Pivot towards GitHub Actions and away from Travis and AppVeyor.
57+
58+
Functions that are removed and, where applicable, what to use instead:
59+
60+
* `git_credentials()`
61+
* `use_git_credentials()`
62+
* `browse_github_token()` (do `create_github_token()`)
63+
* `browse_github_pat()` (do `create_github_token()`)
64+
* `github_token()` (do `gh_token_help()` or `gh::gh_token()`)
65+
* `pr_pull_upstream()` (do `pr_merge_main()`)
66+
* `pr_sync()` (do `pr_merge_main(); pr_push()`)
67+
* `use_appveyor()`
68+
* `use_appveyor_badge()`
69+
* `use_travis()`
70+
* `use_travis_badge()`
71+
* `browse_travis()`
72+
* `use_pkgdown_travis()`
73+
* `use_tidy_ci()` *deprecated in v2.1.0* (do `use_tidy_github_actions()`)
74+
* `use_tidy_labels()` *deprecated in v2.1.0* (do `use_tidy_github_labels()`)
75+
76+
Function arguments that are removed:
77+
78+
* `create_from_github(auth_token =, credentials =)`
79+
* `use_github(auth_token =, credentials =)`
80+
* `use_github_labels(repo_spec =, host =, auth_token =)`
81+
* `use_github_links(auth_token =, host =)`
82+
* `use_github_release(host =, auth_token =)`
83+
4784
# usethis 2.2.3
4885

4986
* Patch release with changes to `.Rd` files requested by CRAN.
@@ -206,14 +243,14 @@
206243
* `use_tidy_logo()` is a new function that calls `use_logo()` on the appropriate
207244
hex sticker PNG file at <https://github.com/rstudio/hex-stickers> (#1871).
208245

209-
## Defunct functions
246+
## Deprecated functions
210247

211-
* `use_tidy_eval()` is now defunct because it imports and re-exports a large
248+
* `use_tidy_eval()` is now deprecated because it imports and re-exports a large
212249
number of functions that are no longer needed in order to do tidy
213250
evaluation (#1656).
214251

215252
* `use_travis()`, `use_pkgdown_travis()`, `browse_travis()`, and `use_appveyor()`
216-
are now defunct because we no longer recommend Travis or Appveyor. We
253+
are now deprecated because we no longer recommend Travis or Appveyor. We
217254
recommend GitHub actions instead (#1517).
218255

219256
# usethis 2.1.6
@@ -531,7 +568,7 @@ GitHub Actions is the preferred platform for continuous integration, because tha
531568

532569
`use_tidy_pkgdown()` implements the complete pkgdown configuration used by the tidyverse team (#224).
533570

534-
`pr_sync()` is defunct and can be replicated by calling `pr_pull()`, `pr_merge_main()`, then `pr_push()`.
571+
`pr_sync()` is deprecated and can be replicated by calling `pr_pull()`, `pr_merge_main()`, then `pr_push()`.
535572

536573
## Licensing improvements
537574

@@ -1183,7 +1220,7 @@ build paths within it (#415, #425).
11831220
11841221
* `create_from_github()`: the `repo` argument is renamed to `repo_spec`, since it takes input of the form "OWNER/REPO" (#376).
11851222
1186-
* `use_depsy_badge()` is defunct. The Depsy project has officially concluded and is no longer being maintained (#354).
1223+
* `use_depsy_badge()` is deprecated. The Depsy project has officially concluded and is no longer being maintained (#354).
11871224
11881225
* `use_github()` fails earlier, with a more informative message, in the absence of a GitHub personal access token (PAT). Also looks for the PAT more proactively in the usual environment variables (i.e., GITHUB_PAT, GITHUB_TOKEN) (#320, #340, @cderv).
11891226

R/cpp11.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use_cpp11 <- function() {
1212
check_is_package("use_cpp11()")
1313
check_installed("cpp11")
1414
check_uses_roxygen("use_cpp11()")
15+
check_has_package_doc("use_cpp11()")
1516
use_src()
1617

1718
use_dependency("cpp11", "LinkingTo")

R/create.R

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,7 @@ create_from_github <- function(repo_spec,
188188
rstudio = NULL,
189189
open = rlang::is_interactive(),
190190
protocol = git_protocol(),
191-
host = NULL,
192-
auth_token = deprecated(),
193-
credentials = deprecated()) {
194-
if (lifecycle::is_present(auth_token)) {
195-
deprecate_warn_auth_token("create_from_github")
196-
}
197-
if (lifecycle::is_present(credentials)) {
198-
deprecate_warn_credentials("create_from_github")
199-
}
191+
host = NULL) {
200192
check_protocol(protocol)
201193

202194
parsed_repo_spec <- parse_repo_url(repo_spec)

R/github-labels.R

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
#' This keeps the issue page visually harmonious while still giving enough
4444
#' variation to easily distinguish different types of label.
4545
#'
46-
#' @param repo_spec,host,auth_token `r lifecycle::badge("deprecated")`: These
47-
#' arguments are now deprecated and will be removed in the future. Any input
48-
#' provided via these arguments is not used. The target repo, host, and auth
49-
#' token are all now determined from the current project's Git remotes.
5046
#' @param labels A character vector giving labels to add.
5147
#' @param rename A named vector with names giving old names and values giving
5248
#' new names.
@@ -77,24 +73,11 @@
7773
#' descriptions = c("foofiest" = "the foofiest issue you ever saw")
7874
#' )
7975
#' }
80-
use_github_labels <- function(repo_spec = deprecated(),
81-
labels = character(),
76+
use_github_labels <- function(labels = character(),
8277
rename = character(),
8378
colours = character(),
8479
descriptions = character(),
85-
delete_default = FALSE,
86-
host = deprecated(),
87-
auth_token = deprecated()) {
88-
if (lifecycle::is_present(repo_spec)) {
89-
deprecate_warn_repo_spec("use_github_labels")
90-
}
91-
if (lifecycle::is_present(host)) {
92-
deprecate_warn_host("use_github_labels")
93-
}
94-
if (lifecycle::is_present(auth_token)) {
95-
deprecate_warn_auth_token("use_github_labels")
96-
}
97-
80+
delete_default = FALSE) {
9881
tr <- target_repo(github_get = TRUE, ok_configs = c("ours", "fork"))
9982
check_can_push(tr = tr, "to modify labels")
10083

R/github.R

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@
3939
#' For a hypothetical GitHub Enterprise instance, either
4040
#' "https://github.acme.com/api/v3" or "https://github.acme.com" is
4141
#' acceptable.
42-
#' @param auth_token,credentials `r lifecycle::badge("deprecated")`: No longer
43-
#' consulted now that usethis uses the gert package for Git operations,
44-
#' instead of git2r; gert relies on the credentials package for auth. The API
45-
#' requests are now authorized with the token associated with the `host`, as
46-
#' retrieved by [gh::gh_token()].
4742
#'
4843
#' @export
4944
#' @examples
@@ -61,16 +56,7 @@ use_github <- function(organisation = NULL,
6156
private = FALSE,
6257
visibility = c("public", "private", "internal"),
6358
protocol = git_protocol(),
64-
host = NULL,
65-
auth_token = deprecated(),
66-
credentials = deprecated()) {
67-
if (lifecycle::is_present(auth_token)) {
68-
deprecate_warn_auth_token("use_github")
69-
}
70-
if (lifecycle::is_present(credentials)) {
71-
deprecate_warn_credentials("use_github")
72-
}
73-
59+
host = NULL) {
7460
visibility_specified <- !missing(visibility)
7561
visibility <- match.arg(visibility)
7662
check_protocol(protocol)
@@ -197,9 +183,6 @@ use_github <- function(organisation = NULL,
197183
#' an interactive session, the user can confirm which repo to use for the
198184
#' links. In a noninteractive session, links are formed using `upstream`.
199185
#'
200-
#' @param host,auth_token `r lifecycle::badge("deprecated")`: No longer consulted
201-
#' now that usethis consults the current project's GitHub remotes to get the
202-
#' `host` and then relies on gh to discover an appropriate token.
203186
#' @param overwrite By default, `use_github_links()` will not overwrite existing
204187
#' fields. Set to `TRUE` to overwrite existing links.
205188
#' @export
@@ -208,16 +191,7 @@ use_github <- function(organisation = NULL,
208191
#' use_github_links()
209192
#' }
210193
#'
211-
use_github_links <- function(auth_token = deprecated(),
212-
host = deprecated(),
213-
overwrite = FALSE) {
214-
if (lifecycle::is_present(auth_token)) {
215-
deprecate_warn_auth_token("use_github_links")
216-
}
217-
if (lifecycle::is_present(host)) {
218-
deprecate_warn_host("use_github_links")
219-
}
220-
194+
use_github_links <- function(overwrite = FALSE) {
221195
check_is_package("use_github_links()")
222196

223197
gh_url <- github_url_from_git_remotes()

R/pr.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,22 +967,22 @@ pr_branch_delete <- function(pr) {
967967

968968
if (is.null(pr_ref)) {
969969
ui_bullets(c(
970-
"i" = "PR {.val {pr$pr_string}} originated from branch {.val {pr_remref}},
970+
"i" = "PR {.href [{pr$pr_string}]({pr$pr_html_url})} originated from branch {.val {pr_remref}},
971971
which no longer exists."
972972
))
973973
return(invisible(FALSE))
974974
}
975975

976976
if (is.na(pr$pr_merged_at)) {
977977
ui_bullets(c(
978-
"i" = "PR {.val {pr$pr_string}} is unmerged, we will not delete the
978+
"i" = "PR {.href [{pr$pr_string}]({pr$pr_html_url})} is unmerged, we will not delete the
979979
remote branch {.val {pr_remref}}."
980980
))
981981
return(invisible(FALSE))
982982
}
983983

984984
ui_bullets(c(
985-
"v" = "PR {.val {pr$pr_string}} has been merged, deleting remote branch
985+
"v" = "PR {.href [{pr$pr_string}]({pr$pr_html_url})} has been merged, deleting remote branch
986986
{.val {pr_remref}}."
987987
))
988988
# TODO: tryCatch here?

R/r.R

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,12 @@
4343
#' @param name Either a string giving a file name (without directory) or
4444
#' `NULL` to take the name from the currently open file in RStudio.
4545
#' @inheritParams edit_file
46-
#' @seealso The [testing](https://r-pkgs.org/testing-basics.html) and
46+
#' @seealso
47+
#' * The [testing](https://r-pkgs.org/testing-basics.html) and
4748
#' [R code](https://r-pkgs.org/code.html) chapters of
4849
#' [R Packages](https://r-pkgs.org).
50+
#' * [use_test_helper()] to create a testthat helper file.
51+
#'
4952
#' @export
5053
#'
5154
#' @examples
@@ -85,6 +88,55 @@ use_test <- function(name = NULL, open = rlang::is_interactive()) {
8588
invisible(TRUE)
8689
}
8790

91+
#' Create or edit a test helper file
92+
#'
93+
#' This function creates (or opens) a test helper file, typically
94+
#' `tests/testthat/helper.R`. Test helper files are executed at the
95+
#' beginning of every automated test run and are also executed by
96+
#' [`load_all()`][pkgload::load_all]. A helper file is a great place to
97+
#' define test helper functions for use throughout your test suite, such as
98+
#' a custom expectation.
99+
#'
100+
#' @param name Can be used to specify the optional "SLUG" in
101+
#' `tests/testthat/helper-SLUG.R`.
102+
#' @inheritParams edit_file
103+
#' @seealso
104+
#' * [use_test()] to create a test file.
105+
#' * The testthat vignette on special files
106+
#' `vignette("special-files", package = "testthat")`.
107+
#' @export
108+
#'
109+
#' @examples
110+
#' \dontrun{
111+
#' use_test_helper()
112+
#' use_test_helper("mocks")
113+
#' }
114+
use_test_helper <- function(name = NULL, open = rlang::is_interactive()) {
115+
maybe_name(name)
116+
117+
if (!uses_testthat()) {
118+
ui_abort(c(
119+
"x" = "Your package must use {.pkg testthat} to use a helper file.",
120+
"_" = "Call {.run usethis::use_testthat()} to set up {.pkg testthat}."
121+
))
122+
}
123+
124+
target_path <- proj_path(
125+
path("tests", "testthat", as_test_helper_file(name))
126+
)
127+
128+
if (!file_exists(target_path)) {
129+
ui_bullets(c(
130+
"i" = "Test helper files are executed at the start of all automated
131+
test runs.",
132+
"i" = "{.run devtools::load_all()} also sources test helper files."
133+
))
134+
}
135+
edit_file(target_path, open = open)
136+
137+
invisible(TRUE)
138+
}
139+
88140
# helpers -----------------------------------------------------------------
89141

90142
compute_name <- function(name = NULL, ext = "R", error_call = caller_env()) {
@@ -172,3 +224,14 @@ check_file_name <- function(name, call = caller_env()) {
172224
valid_file_name <- function(x) {
173225
grepl("^[a-zA-Z0-9._-]+$", x)
174226
}
227+
228+
as_test_helper_file <- function(name = NULL) {
229+
file <- name %||% "helper.R"
230+
if (!grepl("^helper", file)) {
231+
file <- glue("helper-{file}")
232+
}
233+
if (path_ext(file) == "") {
234+
file <- path_ext_set(file, "R")
235+
}
236+
unclass(file)
237+
}

0 commit comments

Comments
 (0)