@@ -149,14 +149,14 @@ pandoc_install_nightly <- function(n_last = 1L) {
149
149
version <- " nightly"
150
150
install_dir <- pandoc_home(version )
151
151
rlang :: inform(c(i = " Retrieving last available nightly informations..." ))
152
- runs <- gh :: gh (" /repos/jgm/pandoc/actions/workflows/nightly.yml/runs" ,
152
+ runs <- gh_wrapper (" /repos/jgm/pandoc/actions/workflows/nightly.yml/runs" ,
153
153
.limit = max(15L , n_last + 5 )
154
154
)
155
155
runs <- keep(runs $ workflow_runs , ~ .x $ conclusion == " success" )
156
156
ind <- min(length(runs ), n_last )
157
157
artifacts_url <- runs [[ind ]][[" artifacts_url" ]]
158
158
head_sha <- runs [[ind ]][[" head_sha" ]]
159
- artifacts <- gh :: gh (artifacts_url )
159
+ artifacts <- gh_wrapper (artifacts_url )
160
160
artifact_url <- keep(artifacts $ artifacts , ~ .x $ name == bundle_name )[[1 ]][[" archive_download_url" ]]
161
161
if (fs :: dir_exists(install_dir )) {
162
162
current_version <- pandoc_nightly_version()
@@ -171,7 +171,7 @@ pandoc_install_nightly <- function(n_last = 1L) {
171
171
bundle_name <- fs :: path_ext_set(head_sha , " zip" )
172
172
rlang :: inform(c(i = " Installing last available nightly..." ))
173
173
tmp_file <- with_download_cache(" nightly" , bundle_name , {
174
- gh :: gh (artifact_url , .destfile = bundle_name )
174
+ gh_wrapper (artifact_url , .destfile = bundle_name )
175
175
})
176
176
177
177
utils :: unzip(tmp_file , exdir = install_dir , junkpaths = TRUE )
@@ -293,7 +293,7 @@ pandoc_releases <- function() {
293
293
fetch_gh_releases <- function (limit = Inf ) {
294
294
gh_required()
295
295
rlang :: inform(c(i = " Fetching Pandoc releases info from github..." ))
296
- gh :: gh (
296
+ gh_wrapper (
297
297
" GET /repos/:owner/:repo/releases" ,
298
298
owner = " jgm" ,
299
299
repo = " pandoc" ,
@@ -337,6 +337,23 @@ pandoc_os <- function() {
337
337
)
338
338
}
339
339
340
+ # fallback for bad token errors. See
341
+ # https://github.com/cderv/pandoc/issues/30#issuecomment-1691712036
342
+ # for details
343
+ gh_wrapper <- function (... ) {
344
+ tryCatch(gh :: gh(... ),
345
+ http_error_401 = function (e ) {
346
+ rlang :: inform(c(
347
+ " !" = " Bad GitHub credentials found" ,
348
+ i = " Attempting to install without credentials..." ))
349
+ # if we get a 401 error, the user has a bad token and we should try with
350
+ # an empty token
351
+ e $ call $ .token <- " "
352
+ eval(e $ call )
353
+ }
354
+ )
355
+ }
356
+
340
357
# nocov start
341
358
gh_required <- function () {
342
359
rlang :: check_installed(
0 commit comments