Skip to content

Commit 0c71a2a

Browse files
committed
Let user pick job
1 parent fbd0aba commit 0c71a2a

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export(skip_on_os)
192192
export(skip_on_travis)
193193
export(skip_unless_r)
194194
export(snapshot_accept)
195+
export(snapshot_download_gh)
195196
export(snapshot_reject)
196197
export(snapshot_review)
197198
export(source_dir)

R/snapshot-github.R

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
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

3334
snap_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

4564
gh_find_artifact <- function(repository, job_id) {
4665
job_logs <- gh::gh(

man/snapshot_download_gh.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-snapshot-file.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
test_that("diagonstics", {
2-
expect_snapshot(readLines(Sys.getenv("GITHUB_EVENT_PATH")))
32
})
43

54
test_that("expect_snapshot_file works", {

0 commit comments

Comments
 (0)