diff --git a/DESCRIPTION b/DESCRIPTION index 2da2852..eef4275 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: piggyback -Version: 0.1.5.9004 +Version: 0.1.5.9005 Title: Managing Larger Data on a GitHub Repository Description: Helps store files as GitHub release assets, which is a convenient way for large/binary data files to piggyback onto public and private GitHub diff --git a/NEWS.md b/NEWS.md index 1958515..84a4a64 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ limits for pb_download. [#109] * `pb_download_url()` now can return choice of "browser" or "api" download URLs [#116] * Add new functions `pb_read()` and `pb_write()` as convenience wrappers around pattern of downloading to `tempfile()` and then reading into memory. [#97] +* Support customizing GitHub base URL via GITHUB_API_URL environment variable, which should help support GH Enterprise [#122] # piggyback 0.1.5 diff --git a/R/pb_info.R b/R/pb_info.R index 1668a07..55e460f 100644 --- a/R/pb_info.R +++ b/R/pb_info.R @@ -107,7 +107,7 @@ get_release_assets <- function(releases, r, .token) { upload_url = releases$upload_url[i], browser_download_url = .extract_chr(a, "browser_download_url"), api_download_url = glue::glue( - "https://api.github.com/repos/{r[[1]]}/{r[[2]]}/releases/assets/{.extract_int(a, 'id')}" + "{.gh_api_url()}/repos/{r[[1]]}/{r[[2]]}/releases/assets/{.extract_int(a, 'id')}" ), id = .extract_int(a, "id"), state = .extract_chr(a, "state"), diff --git a/R/pb_release_create.R b/R/pb_release_create.R index c984161..8d19b97 100644 --- a/R/pb_release_create.R +++ b/R/pb_release_create.R @@ -56,7 +56,7 @@ pb_release_create <- function(repo = guess_repo(), resp <- httr::RETRY( verb = "POST", - url = glue::glue("https://api.github.com/repos/{r[[1]]}/{r[[2]]}/releases"), + url = glue::glue("{.gh_api_url()}/repos/{r[[1]]}/{r[[2]]}/releases"), httr::add_headers(Authorization = paste("token",.token)), body = jsonlite::toJSON(payload, auto_unbox = TRUE), terminate_on = c(400, 401, 403, 404, 422) diff --git a/R/pb_release_delete.R b/R/pb_release_delete.R index 2c44f0f..8e3d8f8 100644 --- a/R/pb_release_delete.R +++ b/R/pb_release_delete.R @@ -26,7 +26,7 @@ pb_release_delete <- function(repo = guess_repo(), tag, .token = gh::gh_token()) resp <- httr::RETRY( verb = "DELETE", glue::glue( - "https://api.github.com/repos/{owner}/{repo}/releases/{release_id}", + "{.gh_api_url()}/repos/{owner}/{repo}/releases/{release_id}", owner = r[1], repo = r[2], release_id = release_id @@ -48,7 +48,7 @@ pb_release_delete <- function(repo = guess_repo(), tag, .token = gh::gh_token()) resp2 <- httr::RETRY( verb = "DELETE", glue::glue( - "https://api.github.com/repos/{owner}/{repo}/git/refs/tags/{tag}", + "{.gh_api_url()}/repos/{owner}/{repo}/git/refs/tags/{tag}", owner = r[1], repo = r[2], tag = tag diff --git a/R/utils.R b/R/utils.R index 0ee8562..a9ec927 100644 --- a/R/utils.R +++ b/R/utils.R @@ -61,3 +61,14 @@ guess_repo <- function(path = ".") { .as_date <- function(x) { as.Date(x, tz = "UTC") } + +#' GitHub API URL +#' +#' Reads environment variable GITHUB_API_URL to determine base URL of API. Same +#' as gh package. Defaults to `https://api.github.com`. +#' +#' @seealso +#' @return string: API base url +.gh_api_url <- function(){ + Sys.getenv("GITHUB_API_URL", unset = "https://api.github.com") +} diff --git a/R/utils_testing.R b/R/utils_testing.R index 7075f0b..b7c7706 100644 --- a/R/utils_testing.R +++ b/R/utils_testing.R @@ -13,9 +13,6 @@ #' - tanho63/piggyback-tests #' - tanho63/piggyback-private (a private repository) #' -#' @param test_token github token, typically stored at TAN_GH_TOKEN -#' @param test_repos repos used in testing -#' #' @keywords internal #' @return named vector of TRUE or FALSE as to whether the token is configured #' and can access the test repos. @@ -34,7 +31,7 @@ test_repos, function(repo) { r <- httr::GET( - paste0("https://api.github.com/repos/",repo), + paste0(.gh_api_url(),"/repos/",repo), httr::add_headers(Authorization = paste("token", test_token)) ) diff --git a/man/dot-check_test_token.Rd b/man/dot-check_test_token.Rd index 4601cad..a71c841 100644 --- a/man/dot-check_test_token.Rd +++ b/man/dot-check_test_token.Rd @@ -6,11 +6,6 @@ \usage{ .check_test_token() } -\arguments{ -\item{test_token}{github token, typically stored at TAN_GH_TOKEN} - -\item{test_repos}{repos used in testing} -} \value{ named vector of TRUE or FALSE as to whether the token is configured and can access the test repos. diff --git a/man/dot-gh_api_url.Rd b/man/dot-gh_api_url.Rd new file mode 100644 index 0000000..c4a6ae5 --- /dev/null +++ b/man/dot-gh_api_url.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{.gh_api_url} +\alias{.gh_api_url} +\title{GitHub API URL} +\usage{ +.gh_api_url() +} +\value{ +string: API base url +} +\description{ +Reads environment variable GITHUB_API_URL to determine base URL of API. Same +as gh package. Defaults to \verb{https://api.github.com}. +} +\seealso{ +\url{https://gh.r-lib.org/#environment-variables} +} diff --git a/man/piggyback-package.Rd b/man/piggyback-package.Rd index 8280b04..023f485 100644 --- a/man/piggyback-package.Rd +++ b/man/piggyback-package.Rd @@ -20,6 +20,7 @@ download data from public repositories. \seealso{ Useful links: \itemize{ + \item \url{https://docs.ropensci.org/piggyback/} \item \url{https://github.com/ropensci/piggyback} \item Report bugs at \url{https://github.com/ropensci/piggyback/issues} } diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index e6ffef8..ca5ae97 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -18,3 +18,4 @@ reference: - title: Misc contents: - "piggyback-package" + - ".gh_api_url"