From 2dab4c2facd43aea2e5884709aa591f45732b47a Mon Sep 17 00:00:00 2001 From: Rebecca Butler Date: Tue, 23 Jul 2024 16:43:58 -0700 Subject: [PATCH] Update github_token.R to point Linux users to article (#1875) * Update github_token.R to point Linux users to article `usethis::create_github_token()` returns code for calling `gitcreds::gitcreds_set()` to set credentials. This may not (does not?) work as a user would likely expect on Linux systems, as documented in the Managing Git(Hub) Credentials article as well as various issues. However, `gitcreds::gitcreds_set()` does not give any such indication, and I think a simple addition to the `create_github_token()` output would be valuable git can be overwhelming, silent errors are extra challenging, the straightforward "Call `gitcreds::gitcreds_set() to register this token" sounds authoritative (leading to extra confusion when things don't work as expected), and {usethis} is such an excellent resource for getting people up and running with git. Thus, explicitly telling Linux users that they may need to reference additional documentation would likely be valuable thanks for considering! * Re-introduce, conditionally, the Linux-specific tip --------- Co-authored-by: Jenny Bryan --- R/github_token.R | 17 ++++++++++++++--- R/utils.R | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/R/github_token.R b/R/github_token.R index 3e5840bbc..819b72194 100644 --- a/R/github_token.R +++ b/R/github_token.R @@ -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( + message <- c( "_" = "Call {.code {hint}} to register this token in the local Git - credential store.", + 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() } diff --git a/R/utils.R b/R/utils.R index 50c9846a2..fcba6e889 100644 --- a/R/utils.R +++ b/R/utils.R @@ -95,6 +95,10 @@ is_windows <- function() { .Platform$OS.type == "windows" } +is_linux <- function() { + identical(tolower(Sys.info()[["sysname"]]), "linux") +} + # For stability of `stringsAsFactors` across versions data.frame <- function(..., stringsAsFactors = FALSE) { base::data.frame(..., stringsAsFactors = stringsAsFactors)