Skip to content

Commit b55febf

Browse files
committed
Refactor hint creation
1 parent ece871d commit b55febf

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

R/snapshot-file.R

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,8 @@ snapshot_review_hint <- function(
181181
path <- paste0("tests/testthat/_snaps/", test, "/", new_name(name))
182182

183183
if (check) {
184-
gh_hint <- snap_download_hint()
185-
on_gh <- !is.null(gh_hint)
186-
187-
if (on_gh) {
188-
bullets <- gh_hint
184+
if (on_gh()) {
185+
bullets <- snap_download_hint()
189186
} else {
190187
bullets <- c(
191188
if (ci) "* Download and unzip run artifact\n",

R/snapshot-github.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ snap_download_hint <- function() {
3434
repository <- Sys.getenv("GITHUB_REPOSITORY")
3535
job_id <- Sys.getenv("GITHUB_JOB")
3636

37-
if (repository == "" || job_id == "") {
38-
return()
39-
}
40-
4137
sprintf(
4238
"* Call `gh_download_snaps(\"%s\", %s)` to download the snapshots from GitHub.\n",
4339
repository,
@@ -119,3 +115,7 @@ dir_copy <- function(src_dir, dst_dir) {
119115
same_file <- function(x, y) {
120116
file.exists(x) && file.exists(y) && hash_file(x) == hash_file(y)
121117
}
118+
119+
on_gh <- function() {
120+
Sys.getenv("GITHUB_ACTIONS") == "true"
121+
}

tests/testthat/test-snapshot-file.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ test_that("snapshot_hint output differs in R CMD check", {
181181
ci = TRUE
182182
)))
183183

184-
withr::local_envvar(GITHUB_REPOSITORY = "r-lib/testthat", GITHUB_JOB = "123")
184+
withr::local_envvar(
185+
GITHUB_ACTIONS = "true",
186+
GITHUB_REPOSITORY = "r-lib/testthat",
187+
GITHUB_JOB = "123"
188+
)
185189
expect_snapshot(cat(snapshot_review_hint(
186190
"lala",
187191
"foo.r",

0 commit comments

Comments
 (0)