33# ' @description
44# ' If your snapshots fail on GitHub, it can be a pain to figure out exactly
55# ' why, or to incorporate them into your local package. This function makes it
6- # ' easy.
6+ # ' easy, only requiring you to interactively select which job you want to
7+ # ' take the artifacts from.
78# '
89# ' Note that you should not generally need to use this function manually;
910# ' instead copy and paste from the hint emitted on GitHub.
1314# ' @param dest_dir Directory to download to. Defaults to the current directory.
1415# ' @export
1516snapshot_download_gh <- function (repository , run_id , dest_dir = " ." ) {
17+ check_string(repository )
18+ check_number_whole(run_id )
19+ check_string(dest_dir )
20+
1621 check_installed(" gh" )
1722
1823 dest_snaps <- file.path(dest_dir , " tests" , " testthat" , " _snaps" )
@@ -26,7 +31,11 @@ snapshot_download_gh <- function(repository, run_id, dest_dir = ".") {
2631 path <- withr :: local_tempfile(pattern = " gh-snaps-" )
2732 gh_download_artifact(repository , artifact_id , path )
2833
29- inner_dir <- dir(path , full.names = TRUE )[1 ]
34+ files <- dir(path , full.names = TRUE )
35+ if (length(files ) != 1 ) {
36+ cli :: cli_abort(" Unexpected artifact format." )
37+ }
38+ inner_dir <- files [[1 ]]
3039 src_snaps <- file.path(inner_dir , " tests" , " testthat" , " _snaps" )
3140 dir_copy(src_snaps , dest_snaps )
3241}
@@ -72,9 +81,8 @@ gh_find_artifact <- function(repository, job_id) {
7281 log_lines <- strsplit(job_logs $ message , " \r ?\n " )[[1 ]]
7382 matches <- re_match(log_lines , " Artifact download URL: (?<artifact_url>.*)" )
7483 matches <- matches [! is.na(matches $ artifact_url ), ]
75-
76- if (! nrow(matches )) {
77- cli :: cli_abort(" Failed to find artifact" )
84+ if (nrow(matches ) == 0 ) {
85+ cli :: cli_abort(" Failed to find artifact." )
7886 }
7987
8088 # Take last artifact URL; if the job has failed the previous artifact will
0 commit comments