-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle host for use_github() same way as auth_token #1333
Comments
I'm intrigued by the idea. It might avoid the necessity for a company-specific function like I have written and packaged (privately), Maybe the company-specific helper function would do something different, writing the project-level The one thing I cannot reason about is what might happen if we rely on a project-level definition of I will have to make an experiment :) |
OK good point. So any GHE solution needs to not make github.com API calls impossible or extremely awkward. Too bad |
I am mindful that I am likely diverting the thread, but here's (the start of) a writeup of how I have approached the GHE solution: http://ijlyttle.github.io/nondim_devtools_gh.html - it's very rough at this point, but if I wait until I get the prose right, well, we'll be waiting... As I note, I don't pretend that this a best practice, simply that it is a practice. If nothing else, maybe it can shake loose some ideas. |
Nice! So maybe I will try some variation on your solution for a while. |
Thanks! |
This is awesome! One thing I'd like to add is that with https://github.com/cscheid/rgithub I can use OAuth token instead of PAT. The upside is that I no longer need to ask every user to go to a page, click, type, click, copy, create file, paste, save and makes mistake. Downside is that token can expire and as long as they are logged in, they just need to close the page. A sample code might looks like this if (!requireNamespace("devtools", quietly = TRUE)) {
message("Installing devtools package...")
install.packages("devtools")
}
if (!requireNamespace("github", quietly = TRUE)) {
message("Installing rGithub package...")
devtools::install_github("cscheid/rgithub")
}
#' Generate an Interactive GHE Context
#'
#' Authenticate with GHE using OAuth token.
#'
#' @seealso \link[httr]{oauth2.0_token}
ghe_context <- function() {
# Save current httr OAuth caching option
old_httr_oauth_cache <- getOption("httr_oauth_cache")
# Cache OAuth token at home directory instead
options(httr_oauth_cache = "~/.utilr{{private}}/.httr-oauth-ghe")
# Restore httr OAuth caching option
on.exit(options(httr_oauth_cache = old_httr_oauth_cache))
client_id <- "{{not_so_secret_id}}"
client_secret <- "{{not_so_secret_token}}"
base_url <- "{{private host}}"
api_url <- file.path(base_url, "api", "v3")
github::interactive.login(client_id, client_secret, NULL, base_url, api_url)
}
#' Updates utilr{{private}} and all of its required packages to the latest versions
#'
#' @export
update_utilr <- function(...) {
ctx <- ghe_context()
auth_token <- ctx$token$credentials$access_token
devtools::install_github("{{private}}/utilr", host = ctx$api_url, auth_token = auth_token, ...)
} |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
I propose handling the host for
use_github()
in a similar fashion asauth_token
, which is this:github_pat()
is called, which tries to retrieve PAT from env var GITHUB_PATCould we use an env var named GITHUB_API_URL for this? I suggest it because
gh
already does this. If GITHUB_API_URL is not defined, then use existing defaulthttps://api.github.com
.This makes it easier to define a user-level GITHUB_PAT for github.com and, for individual projects, store an alternative host and PAT for GitHub Enterprise in a project-level
.Renviron
.cc @ijlyttle
The text was updated successfully, but these errors were encountered: