Skip to content

Commit

Permalink
Use ref instead of hash
Browse files Browse the repository at this point in the history
As this can take any ref, a hash, a branch name etc.
  • Loading branch information
r-ash committed Feb 29, 2024
1 parent d55d9cb commit a0ae287
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/git.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion R/porcelain.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ first_dirname <- function(paths) {
dir
}
vcapply(paths, first_dir, USE.NAMES = FALSE)
}
}
2 changes: 1 addition & 1 deletion R/util_assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion tests/testthat/helper-orderly-runner.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion tests/testthat/test-util-assert.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
})
2 changes: 1 addition & 1 deletion tests/testthat/test-util.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})
2 changes: 1 addition & 1 deletion tests/testthat/test-zzz-e2e.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a0ae287

Please sign in to comment.