From a0ae287f061d225e9959a4a4730b25f35d0ff378 Mon Sep 17 00:00:00 2001 From: Rob Ashton Date: Thu, 29 Feb 2024 10:30:23 +0000 Subject: [PATCH] Use ref instead of hash As this can take any ref, a hash, a branch name etc. --- R/api.R | 8 ++++---- R/git.R | 2 +- R/porcelain.R | 2 +- R/util.R | 2 +- R/util_assert.R | 2 +- tests/testthat/helper-orderly-runner.R | 2 +- tests/testthat/test-util-assert.R | 2 +- tests/testthat/test-util.R | 2 +- tests/testthat/test-zzz-e2e.R | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/api.R b/R/api.R index 537e61c..c01881a 100644 --- a/R/api.R +++ b/R/api.R @@ -33,10 +33,10 @@ root <- function() { ##' @porcelain ##' GET /report/list => json(report_list) -##' query hash :: string +##' query ref :: string ##' state root :: root -report_list <- function(root, hash) { - contents <- gert::git_ls(root, ref = hash) +report_list <- function(root, ref) { + contents <- gert::git_ls(root, ref = ref) re <- "^src/([^/]+)/(\\1|orderly)\\.(yml|R)$" nms <- sub(re, "\\1", grep(re, contents$path, value = TRUE, perl = TRUE), @@ -45,7 +45,7 @@ report_list <- function(root, hash) { max(contents$modified[startsWith(contents$path, sprintf("src/%s", nm))]) } updated_time <- vnapply(nms, last_changed, USE.NAMES = FALSE) - modified_sources <- git_get_modified(hash, relative_dir = "src/", repo = root) + modified_sources <- git_get_modified(ref, relative_dir = "src/", repo = root) modified_reports <- unique(first_dirname(modified_sources)) has_modifications <- vlapply(nms, function(report_name) { report_name %in% modified_reports diff --git a/R/git.R b/R/git.R index 66b1e31..2eac894 100644 --- a/R/git.R +++ b/R/git.R @@ -51,4 +51,4 @@ git_get_modified <- function(ref, base = NULL, sprintf("%s...%s", base, git_ref_to_sha(ref, repo = repo, check = TRUE)), additional_args), repo = repo, check = TRUE)$output -} \ No newline at end of file +} diff --git a/R/porcelain.R b/R/porcelain.R index e290b13..3d81a7d 100644 --- a/R/porcelain.R +++ b/R/porcelain.R @@ -14,7 +14,7 @@ "GET", "/report/list", report_list, - porcelain::porcelain_input_query(hash = "string"), + porcelain::porcelain_input_query(ref = "string"), porcelain::porcelain_state(root = state$root), returning = porcelain::porcelain_returning_json("report_list"), validate = validate) diff --git a/R/util.R b/R/util.R index cdd2c69..a00eb9e 100644 --- a/R/util.R +++ b/R/util.R @@ -57,4 +57,4 @@ first_dirname <- function(paths) { dir } vcapply(paths, first_dir, USE.NAMES = FALSE) -} \ No newline at end of file +} diff --git a/R/util_assert.R b/R/util_assert.R index ee6429d..93ec841 100644 --- a/R/util_assert.R +++ b/R/util_assert.R @@ -20,4 +20,4 @@ assert_scalar_character <- function(x, name = deparse(substitute(x)), arg = name, call = NULL) { assert_scalar(x, name, arg = arg, call = call) assert_character(x, name, arg = arg, call = call) -} \ No newline at end of file +} diff --git a/tests/testthat/helper-orderly-runner.R b/tests/testthat/helper-orderly-runner.R index eeb113b..5e940b6 100644 --- a/tests/testthat/helper-orderly-runner.R +++ b/tests/testthat/helper-orderly-runner.R @@ -79,4 +79,4 @@ create_new_branch <- function(path, branch_name = "other") { commit_sha <- create_new_commit(path, branch_name) gert::git_branch_checkout(initial_branch, repo = path) list(branch = branch_name, sha = commit_sha) -} \ No newline at end of file +} diff --git a/tests/testthat/test-util-assert.R b/tests/testthat/test-util-assert.R index 187897f..73d9105 100644 --- a/tests/testthat/test-util-assert.R +++ b/tests/testthat/test-util-assert.R @@ -9,4 +9,4 @@ test_that("assert_character", { expect_silent(assert_character("a")) expect_error(assert_character(1), "must be character") expect_error(assert_character(TRUE), "must be character") -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-util.R b/tests/testthat/test-util.R index edc4986..f1176ca 100644 --- a/tests/testthat/test-util.R +++ b/tests/testthat/test-util.R @@ -9,4 +9,4 @@ test_that("first_dirname gets the first dir part of the filename", { expect_equal( first_dirname(c("test/file/name.txt", "test", ".", "testing/file.txt")), c("test", "test", ".", "testing")) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-zzz-e2e.R b/tests/testthat/test-zzz-e2e.R index 7cc6ee9..bcaf32e 100644 --- a/tests/testthat/test-zzz-e2e.R +++ b/tests/testthat/test-zzz-e2e.R @@ -19,7 +19,7 @@ test_that("can run server", { }) test_that("can list reports", { - r <- bg$request("GET", "/report/list?hash=HEAD") + r <- bg$request("GET", "/report/list?ref=HEAD") expect_equal(httr::status_code(r), 200) dat <- httr::content(r)