99# ' instead copy and paste from the hint emitted on GitHub.
1010# '
1111# ' @param repository Repository name, e.g. `"r-lib/testthat"`.
12- # ' @param job_id Job ID, e.g. `"47905180716"`. You can find this in the job url.
12+ # ' @param run_id Run ID, e.g. `"47905180716"`. You can find this in the action url.
1313# ' @param dest_dir Directory to download to. Defaults to the current directory.
1414# ' @export
15- snapshot_download_gh <- function (repository , job_id , dest_dir = " ." ) {
15+ snapshot_download_gh <- function (repository , run_id , dest_dir = " ." ) {
1616 check_installed(" gh" )
1717
1818 dest_snaps <- file.path(dest_dir , " tests" , " testthat" , " _snaps" )
1919 if (! dir.exists(dest_snaps )) {
2020 cli :: cli_abort(" No snapshot directory found in {.file {dest_dir}}." )
2121 }
2222
23+ job_id <- gh_find_job(repository , run_id )
2324 artifact_id <- gh_find_artifact(repository , job_id )
2425
2526 path <- withr :: local_tempfile(pattern = " gh-snaps-" )
@@ -32,15 +33,33 @@ snapshot_download_gh <- function(repository, job_id, dest_dir = ".") {
3233
3334snap_download_hint <- function () {
3435 repository <- Sys.getenv(" GITHUB_REPOSITORY" )
35- job_id <- Sys.getenv(" GITHUB_JOB " )
36+ run_id <- Sys.getenv(" GITHUB_RUN_ID " )
3637
3738 sprintf(
3839 " * Call `gh_download_snaps(\" %s\" , %s)` to download the snapshots from GitHub.\n " ,
3940 repository ,
40- job_id
41+ run_id
4142 )
4243}
4344
45+ gh_find_job <- function (repository , run_id ) {
46+ jobs_json <- gh :: gh(
47+ " /repos/{repository}/actions/runs/{run_id}/jobs" ,
48+ repository = repository ,
49+ run_id = run_id
50+ )
51+ jobs <- data.frame (
52+ id = map_dbl(jobs_json $ jobs , \(x ) x $ id ),
53+ name = map_chr(jobs_json $ jobs , \(x ) x $ name )
54+ )
55+ jobs <- jobs [order(jobs $ name ), ]
56+
57+ idx <- menu(jobs $ name , title = " Which job?" )
58+ if (idx == 0 ) {
59+ cli :: cli_abort(" Selection cancelled." )
60+ }
61+ jobs $ id [[idx ]]
62+ }
4463
4564gh_find_artifact <- function (repository , job_id ) {
4665 job_logs <- gh :: gh(
0 commit comments