Skip to content

Commit 43f6d2d

Browse files
authored
Learn host from Git remotes (when possible), get PAT from host (#1229)
* TODO comment re: gert verbosity * Bump min version of gh, list in Remotes * Depend on (dev) gitcreds * Getting things rolling * Don't accomodate weird configs * Switch over release-related functions * Switch label-editing functions over * Switch over use_pkgdown_travis() and its helper * Switch over use_tidy_thanks() and do some general fixup * Switch over the issue functions * Switch over use_github() and use_github_links() * Crude switch over of create_from_github() This version always errors in the "no token" case * Bring back create_from_github()'s ability to clone, if no token Lots of other refactoring. Main point of that is to GitHub checks and prep before starting any work on the local filesystem. Less likely to leave partial setup in the event of GitHub failure. * Remove have_github_token(), check_github_token() * Get rid of the repo_spec_orig() workaround * Update WORDLIST * Fixes revealed by manual tests with GHE * Fix this signature We will probably use an external mocking package soon anywa * Stop printing this message * stringAsFactors = HELLNO * Deprecate github_token() * Work on updating setup advice This needs a lot of simplification but this is better than doing nothing, for now. * Switch over the pr functions * Update WORDLIST * Work on NEWS
1 parent 2d9da2e commit 43f6d2d

38 files changed

+1120
-958
lines changed

DESCRIPTION

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ Imports:
3131
desc,
3232
fs (>= 1.3.0),
3333
gert (>= 0.3.9004),
34-
gh (>= 1.1.0),
34+
gh (>= 1.1.0.9001),
35+
gitcreds (>= 0.0.0.9000),
3536
glue (>= 1.3.0),
3637
lifecycle,
3738
purrr,
@@ -54,11 +55,14 @@ Suggests:
5455
spelling (>= 1.2),
5556
styler (>= 1.2.0),
5657
testthat (>= 2.1.0)
58+
RdMacros:
59+
lifecycle
5760
Remotes:
58-
r-lib/gert
61+
r-lib/gert,
62+
r-lib/gh,
63+
r-lib/gitcreds
5964
Encoding: UTF-8
6065
Language: en-US
6166
LazyData: true
6267
Roxygen: list(markdown = TRUE)
6368
RoxygenNote: 7.1.1
64-
RdMacros: lifecycle

NEWS.md

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

3-
## Adoption of gert and credentials
4-
5-
Usethis now uses the gert package for Git operations (<https://docs.ropensci.org/gert>), where previously we used git2r. The main motivation for this is to provide a smoother user experience by discovering and using the same credentials as command line Git (and, therefore, the same as RStudio). Under the hood, the hero is the credentials package (<https://docs.ropensci.org/credentials/>). `use_git_credentials()` and `git_credentials()` are now deprecated, since usethis no longer needs a way for a user to provide explicit credentials. The switch to gert + credentials should eliminate most credential-finding fiascos, but if you want to learn more, see the [introductory vignette](https://cran.r-project.org/web/packages/credentials/vignettes/intro.html) for the credentials package.
6-
7-
Gert also takes a different approach to wrapping libgit2, the underlying C library that does Git operations. The result is more consistent support for SSH and TLS, across all operating systems, without requiring special effort at install time. More users should enjoy Git remote operations that "just work", for both SSH and HTTPS remotes. There should be fewer "unsupported protocol" errors.
8-
93
## GitHub remote configuration
104

115
Usethis gains a more formal framework for characterizing a GitHub remote configuration. We look at:
@@ -16,17 +10,57 @@ Usethis gains a more formal framework for characterizing a GitHub remote configu
1610

1711
This is an internal matter, but users will notice that usethis is more clear about which configurations are supported by various functions and which are not. The most common configurations are reviewed in a [section of Happy Git](https://happygitwithr.com/common-remote-setups.html).
1812

19-
When working in a fork, there is sometimes a question whether to target the fork or the parent repository. For example, `use_github_links()` adds GitHub links to the URL and BugReports fields of DESCRIPTION. If someone calls `use_github_links()` when working in a fork, they probably want those links to refer to the *parent* repo, not to their fork, because the user is probably preparing a pull request. Usethis should now have better default behaviour in these situations and, in some cases, will present an interactive choice.
13+
When working in a fork, there is sometimes a question whether to target the fork or the parent repository. For example, `use_github_links()` adds GitHub links to the URL and BugReports fields of DESCRIPTION. If someone calls `use_github_links()` when working in a fork, they probably want those links to refer to the *parent* or *source* repo, not to their fork, because the user is probably preparing a pull request. Usethis should now have better default behaviour in these situations and, in some cases, will present an interactive choice.
14+
15+
## Adoption of gert and getting usethis out of the Git credential business
16+
17+
Usethis has various functions that help with Git-related tasks, which break down into two categories:
18+
19+
1. Git tasks, such as clone, push, and pull. These are things you could do with
20+
command line Git.
21+
1. GitHub tasks, such as fork, release, and open an issue / pull request. These
22+
are things you could do in the browser or with the GitHub API.
23+
24+
We've switched from git2r to the gert package for Git operations (<https://docs.ropensci.org/gert>). We continue to use the gh package for GitHub API work (<https://gh.r-lib.org>).
25+
26+
The big news in this area is that these lower-level dependencies are getting better at finding Git credentials, finding the same credentials as command line Git (and, therefore, the same as RStudio), and finding the same credentials as each other. This allows usethis to shed some of the workarounds we have needed in the past, to serve as a remedial "credential valet".
27+
28+
Under the hood, both gert and gh are now consulting your local Git credential store, when they need credentials. At the time of writing, they are using two different even-lower-level packages to do this:
29+
30+
* gert uses the credentials package (<https://docs.ropensci.org/credentials/>)
31+
* gh uses the gitcreds package (<https://r-lib.github.io/gitcreds/>)
32+
33+
Even now, gert and gh should discover the same credentials, at least for github.com. Moving forward, we are hopeful that these two packages will merge into one.
34+
35+
The main user-facing changes in usethis are:
36+
37+
* usethis should be able to work with any GitHub deployment. While github.com is the default, GitHub Enterprise deployments should be fully supported.
38+
* The target `host` is determined from the current project's configured GitHub remotes, whenever possible.
39+
* The associated `auth_token` is determined from the target `host`, whenever possible.
40+
41+
As a result, several functions are deprecated and several other functions have some deprecated arguments.
42+
43+
* Deprecated functions:
44+
- `use_git_credentials()`
45+
- `git_credentials()`
46+
- `github_token()`
47+
* Functions with (deprecated arguments):
48+
- `create_from_github()` (`auth_token`)
49+
- `use_github()` (`auth_token`)
50+
- `use_github_links()` (`host`, `auth_token`)
51+
- `use_github_labels()` (`repo_spec`, `host`, `auth_token`)
52+
- `use_tidy_labels()` (`repo_spec`, `host`, `auth_token`)
53+
- `use_github_release()` (`host`, `auth_token`)
54+
55+
The switch to gert + credentials should eliminate most credential-finding fiascos, but if you want to learn more, see the [introductory vignette](https://cran.r-project.org/web/packages/credentials/vignettes/intro.html) for the credentials package. Gert also takes a different approach to wrapping libgit2, the underlying C library that does Git operations. The result is more consistent support for SSH and TLS, across all operating systems, without requiring special effort at install time. More users should enjoy Git remote operations that "just work", for both SSH and HTTPS remotes. There should be fewer "unsupported protocol" errors.
2056

2157
## Default branch
2258

2359
There is increasing interest in making the name of a repo's default branch configurable. In principle, this is already possible, but in reality many Git tools have `master` hard-wired in various places and usethis is no exception. We are laying the groundwork to respect a repository-specific default branch in a future release. It remains to be seen if some standard will emerge for where to record this info or if usethis needs to track it in a custom Git configuration field.
2460

2561
*TODO: Summarize current level of prep or support of non-`master` default branch.*
2662

27-
## Changes to Git/GitHub-related functions
28-
29-
`use_git_credentials()` and `git_credentials()` are deprecated. All credential-handling has been delegated to the credentials package.
63+
## Changes to behaviour of Git/GitHub-related functions
3064

3165
`pr_finish()` deletes the remote PR branch if the PR has been merged and the current user has the power to do so, i.e. an external contributor deleting their own branch or a maintainer deleting a branch associated with an internal PR (#1150).
3266

R/badge.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ stages <- c(
130130
#' for additional examples.
131131
#' @export
132132
use_binder_badge <- function(urlpath = NULL) {
133-
repo_spec <- repo_spec()
133+
repo_spec <- target_repo_spec()
134134

135135
if (is.null(urlpath)) {
136136
urlpath <- ""

R/browse.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ browse_cran <- function(package = NULL) {
9292
}
9393

9494
# Try to get a GitHub repo spec from these places:
95-
# 1. Remotes associated with github.com (active project)
95+
# 1. Remotes associated with GitHub (active project)
9696
# 2. BugReports/URL fields of DESCRIPTION (active project or arbitrary
9797
# installed package)
9898
github_url <- function(package = NULL) {
9999
if (is.null(package)) {
100-
repo_spec <- repo_spec()
100+
repo_spec <- target_repo_spec()
101101
if (!is.null(repo_spec)) {
102102
return(glue("https://github.com/{repo_spec}"))
103103
}

R/ci.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use_travis <- function(browse = rlang::is_interactive(),
3737
what = "usethis::use_travis()",
3838
with = "use_github_actions()"
3939
)
40-
repo_spec <- repo_spec()
40+
repo_spec <- target_repo_spec()
4141
ext <- arg_match(ext)
4242
new <- use_template(
4343
"travis.yml",
@@ -60,7 +60,7 @@ use_travis <- function(browse = rlang::is_interactive(),
6060
#' @export
6161
#' @rdname ci
6262
use_travis_badge <- function(ext = c("com", "org"), repo_spec = NULL) {
63-
repo_spec <- repo_spec %||% repo_spec()
63+
repo_spec <- repo_spec %||% target_repo_spec()
6464
ext <- arg_match(ext)
6565
url <- glue("https://travis-ci.{ext}/{repo_spec}")
6666
img <- glue("{url}.svg?branch=master")
@@ -95,7 +95,7 @@ use_appveyor <- function(browse = rlang::is_interactive()) {
9595
what = "usethis::use_appveyor()",
9696
with = "use_github_actions()"
9797
)
98-
repo_spec <- repo_spec()
98+
repo_spec <- target_repo_spec()
9999
new <- use_template("appveyor.yml", ignore = TRUE)
100100
if (!new) {
101101
return(invisible(FALSE))
@@ -121,7 +121,7 @@ appveyor_activate <- function(browse = is_interactive()) {
121121
#' @export
122122
#' @rdname ci
123123
use_appveyor_badge <- function(repo_spec = NULL) {
124-
repo_spec <- repo_spec %||% repo_spec()
124+
repo_spec <- repo_spec %||% target_repo_spec()
125125
img <- glue(
126126
"https://ci.appveyor.com/api/projects/status/github/",
127127
"{repo_spec}?branch=master&svg=true"
@@ -165,7 +165,7 @@ use_gitlab_ci <- function() {
165165
#' @rdname ci
166166
use_circleci <- function(browse = rlang::is_interactive(),
167167
image = "rocker/verse:latest") {
168-
repo_spec <- repo_spec()
168+
repo_spec <- target_repo_spec()
169169
use_directory(".circleci", ignore = TRUE)
170170
new <- use_template(
171171
"circleci-config.yml",
@@ -189,7 +189,7 @@ use_circleci <- function(browse = rlang::is_interactive(),
189189
#' @rdname ci
190190
#' @export
191191
use_circleci_badge <- function(repo_spec = NULL) {
192-
repo_spec <- repo_spec %||% repo_spec()
192+
repo_spec <- repo_spec %||% target_repo_spec()
193193
url <- glue("https://circleci.com/gh/{repo_spec}")
194194
img <- glue("{url}.svg?style=svg")
195195
use_badge("CircleCI build status", url, img)

R/coverage.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#' @eval param_repo_spec()
99
#' @export
1010
use_coverage <- function(type = c("codecov", "coveralls"), repo_spec = NULL) {
11-
repo_spec <- repo_spec %||% repo_spec()
11+
repo_spec <- repo_spec %||% target_repo_spec()
1212
use_dependency("covr", "Suggests")
1313

1414
type <- match.arg(type)

0 commit comments

Comments
 (0)