Skip to content
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

Dev pkgdown #20

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ get_bagrov_curves_from_abimo <- function()
))
}

# github_pat -------------------------------------------------------------------
# Provide non-exported function github_pat() from package remotes
#' @importFrom utils getFromNamespace
github_pat <- utils::getFromNamespace("github_pat", "remotes")

# latest_abimo_version ---------------------------------------------------------
latest_abimo_version <- function()
{
Expand Down
36 changes: 18 additions & 18 deletions R/install_abimo.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# install_abimo ----------------------------------------------------------------

#' Install ABIMO
#'
#' @param tag tag of ABIMO version to be installed, e.g. "v3.2.2"
#' @param arch target system architecture, one of "windows", "linux", "macos"
#' @param \dots further arguments passed to \code{kwb.abimo:::download_assets}
#' @importFrom archive archive_extract
#' @importFrom kwb.utils catAndRun createDirectory
#' @importFrom kwb.utils catAndRun createDirectory stringList
#' @export
install_abimo <- function(
tag = latest_abimo_version(),
arch = get_architecture_suffix(),
Expand All @@ -16,7 +22,6 @@ install_abimo <- function(
"'architectures': ",
kwb.utils::stringList(expected_architectures),
call. = FALSE

)
}

Expand Down Expand Up @@ -48,40 +53,35 @@ install_abimo <- function(

# download_assets --------------------------------------------------------------

#' @importFrom utils download.file getFromNamespace
#' @importFrom utils download.file
download_assets <- function(
repo,
tag,
destdir = tempdir(),
pattern = NULL,
accept = "application/octet-stream",
timeout = getOption("timeout")
timeout = getOption("timeout"),
token = github_pat()
)
{
old_options <- options(timeout = timeout)
on.exit(options(old_options))

asset_info <- get_asset_info(repo, tag)
asset_info <- get_asset_info(repo, tag, token = token)

if (!is.null(pattern)) {
asset_info <- asset_info[grepl(pattern, asset_info$name), ]
}

# Provide non-exported function github_pat() from package remotes
token <- utils::getFromNamespace("github_pat", "remotes")()

# Compose HTTP header (with or without token)
headers <- c(
if (!is.null(token)) c(Authorization = paste("token", token)),
Accept = accept
)

for (i in seq_len(nrow(asset_info))) {

utils::download.file(
url = asset_info$url[i],
destfile = file.path(destdir, asset_info$name[i]),
headers = headers,
headers = c(
Authorization = paste("token", token),
Accept = accept
),
mode = "wb"
)
}
Expand All @@ -93,11 +93,11 @@ download_assets <- function(

#' @importFrom gh gh
#' @importFrom kwb.utils asNoFactorDataFrame selectElements
get_asset_info <- function(repo, tag)
get_asset_info <- function(repo, tag, token = github_pat())
{
url_releases <- sprintf("https://api.github.com/repos/%s/releases", repo)

release_info <- gh::gh(url_releases)
release_info <- gh::gh(url_releases, .token = token)

tag_names <- sapply(release_info, kwb.utils::selectElements, "tag_name")

Expand All @@ -109,7 +109,7 @@ get_asset_info <- function(repo, tag)
)

if (!length(assets)) {
stop("There are no assets for release ", tag)
stop("There are no assets for release ", tag, call. = FALSE)
}

do.call(rbind, lapply(assets, function(asset) {
Expand Down
Loading