11# install_abimo ----------------------------------------------------------------
22
3+ # ' Install ABIMO
4+ # '
5+ # ' @param tag tag of ABIMO version to be installed, e.g. "v3.2.2"
6+ # ' @param arch target system architecture, one of "windows", "linux", "macos"
7+ # ' @param \dots further arguments passed to \code{kwb.abimo:::download_assets}
38# ' @importFrom archive archive_extract
4- # ' @importFrom kwb.utils catAndRun createDirectory
9+ # ' @importFrom kwb.utils catAndRun createDirectory stringList
10+ # ' @export
511install_abimo <- function (
612 tag = latest_abimo_version(),
713 arch = get_architecture_suffix(),
@@ -16,7 +22,6 @@ install_abimo <- function(
1622 " 'architectures': " ,
1723 kwb.utils :: stringList(expected_architectures ),
1824 call. = FALSE
19-
2025 )
2126 }
2227
@@ -48,40 +53,35 @@ install_abimo <- function(
4853
4954# download_assets --------------------------------------------------------------
5055
51- # ' @importFrom utils download.file getFromNamespace
56+ # ' @importFrom utils download.file
5257download_assets <- function (
5358 repo ,
5459 tag ,
5560 destdir = tempdir(),
5661 pattern = NULL ,
5762 accept = " application/octet-stream" ,
58- timeout = getOption(" timeout" )
63+ timeout = getOption(" timeout" ),
64+ token = github_pat()
5965)
6066{
6167 old_options <- options(timeout = timeout )
6268 on.exit(options(old_options ))
6369
64- asset_info <- get_asset_info(repo , tag )
70+ asset_info <- get_asset_info(repo , tag , token = token )
6571
6672 if (! is.null(pattern )) {
6773 asset_info <- asset_info [grepl(pattern , asset_info $ name ), ]
6874 }
6975
70- # Provide non-exported function github_pat() from package remotes
71- token <- utils :: getFromNamespace(" github_pat" , " remotes" )()
72-
73- # Compose HTTP header (with or without token)
74- headers <- c(
75- if (! is.null(token )) c(Authorization = paste(" token" , token )),
76- Accept = accept
77- )
78-
7976 for (i in seq_len(nrow(asset_info ))) {
8077
8178 utils :: download.file(
8279 url = asset_info $ url [i ],
8380 destfile = file.path(destdir , asset_info $ name [i ]),
84- headers = headers ,
81+ headers = c(
82+ Authorization = paste(" token" , token ),
83+ Accept = accept
84+ ),
8585 mode = " wb"
8686 )
8787 }
@@ -93,11 +93,11 @@ download_assets <- function(
9393
9494# ' @importFrom gh gh
9595# ' @importFrom kwb.utils asNoFactorDataFrame selectElements
96- get_asset_info <- function (repo , tag )
96+ get_asset_info <- function (repo , tag , token = github_pat() )
9797{
9898 url_releases <- sprintf(" https://api.github.com/repos/%s/releases" , repo )
9999
100- release_info <- gh :: gh(url_releases )
100+ release_info <- gh :: gh(url_releases , .token = token )
101101
102102 tag_names <- sapply(release_info , kwb.utils :: selectElements , " tag_name" )
103103
@@ -109,7 +109,7 @@ get_asset_info <- function(repo, tag)
109109 )
110110
111111 if (! length(assets )) {
112- stop(" There are no assets for release " , tag )
112+ stop(" There are no assets for release " , tag , call. = FALSE )
113113 }
114114
115115 do.call(rbind , lapply(assets , function (asset ) {
0 commit comments