diff --git a/DESCRIPTION b/DESCRIPTION index 7f2753d..0884b9f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: conbenchcoms Title: An API wrapper for conbench communications -Version: 0.0.7 +Version: 0.0.8 Authors@R: c( person("Jonathan", "Keane", , "jon@voltrondata.com", role = c("aut", "ctb"), comment = c(ORCID = "0000-0001-7087-9776")), diff --git a/NEWS.md b/NEWS.md index c028c92..7cb412b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# conbenchcoms 0.0.8 +* Remove `simplifyVector` and `flatten` arguments from `history` +* `history` now always returns a `tibble` +* `history` now paginates until all matching data is returned, which works only with Conbench servers of at least version [649a9ac](https://github.com/conbench/conbench/commit/649a9ac) + # conbenchcoms 0.0.7 * Remove `sha`, `simplifyVector`, and `flatten` arguments from `runs` * Add `commit_hashes` argument to `runs` diff --git a/R/history.R b/R/history.R index 26c3215..acd04bb 100644 --- a/R/history.R +++ b/R/history.R @@ -1,14 +1,27 @@ #' Get history for a benchmark #' -#' @param benchmark_id the hash of a benchmark to get the history for -#' @inheritParams jsonlite::fromJSON +#' @param benchmark_id the ID of a benchmark result to get the history for #' -#' @return the response +#' @return a tibble of history #' @export -history <- function(benchmark_id, simplifyVector = TRUE, flatten = TRUE, ...) { +history <- function(benchmark_id) { req <- req_url_path_append(conbench_request(), "history", benchmark_id) - + req <- req_url_query(req, page_size = 1000) resp <- conbench_perform(req) + json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE) + data <- dplyr::as_tibble(json[["data"]]) + + while (!is.null(json[["metadata"]][["next_page_cursor"]])) { + req <- req_url_path_append(conbench_request(), "history", benchmark_id) + req <- req_url_query( + req, + page_size = 1000, + cursor = json[["metadata"]][["next_page_cursor"]] + ) + resp <- conbench_perform(req) + json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE) + data <- dplyr::bind_rows(data, dplyr::as_tibble(json[["data"]])) + } - resp_body_json(resp, simplifyVector = simplifyVector, flatten = flatten, ...) + data } diff --git a/man/history.Rd b/man/history.Rd index 1974ecf..6832053 100644 --- a/man/history.Rd +++ b/man/history.Rd @@ -4,19 +4,13 @@ \alias{history} \title{Get history for a benchmark} \usage{ -history(benchmark_id, simplifyVector = TRUE, flatten = TRUE, ...) +history(benchmark_id) } \arguments{ -\item{benchmark_id}{the hash of a benchmark to get the history for} - -\item{simplifyVector}{coerce JSON arrays containing only primitives into an atomic vector} - -\item{flatten}{automatically \code{\link[jsonlite:flatten]{flatten()}} nested data frames into a single non-nested data frame} - -\item{...}{arguments passed on to class specific \code{print} methods} +\item{benchmark_id}{the ID of a benchmark result to get the history for} } \value{ -the response +a tibble of history } \description{ Get history for a benchmark diff --git a/tests/testthat/resp-class/localhost/api/history/hist-id-981e53.json b/tests/testthat/resp-class/localhost/api/history/hist-id-981e53.json new file mode 100644 index 0000000..6f3170c --- /dev/null +++ b/tests/testthat/resp-class/localhost/api/history/hist-id-981e53.json @@ -0,0 +1,12 @@ +{ + "data": [ + { + "benchmark_id": "hist-id", + "timestamp": "2022-04-07T21:11:19", + "unit": "s" + } + ], + "metadata": { + "next_page_cursor": null + } +} diff --git a/tests/testthat/resp-class/localhost/api/history/hist-id.json b/tests/testthat/resp-class/localhost/api/history/hist-id.json deleted file mode 100644 index ad36b96..0000000 --- a/tests/testthat/resp-class/localhost/api/history/hist-id.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "benchmark_id": "hist-id", - "timestamp": "2022-04-07T21:11:19", - "unit": "s" - } -] diff --git a/tests/testthat/test-history.R b/tests/testthat/test-history.R index fdce2e9..b0dd115 100644 --- a/tests/testthat/test-history.R +++ b/tests/testthat/test-history.R @@ -2,7 +2,7 @@ with_mock_dir(test_path("logged-in"), { test_that("history()", { expect_GET( history("C0C0A"), - "http://localhost/api/history/C0C0A" + "http://localhost/api/history/C0C0A?page_size=1000" ) }) }) @@ -10,20 +10,12 @@ with_mock_dir(test_path("logged-in"), { with_mock_dir(test_path("resp-class"), { the_id <- "hist-id" - test_that("history() returns a data.frame", { + test_that("history() returns a tibble", { the_history <- history(benchmark_id = the_id) expect_s3_class( the_history, - "data.frame" + "tbl_df" ) expect_identical(the_id, the_history$benchmark_id) }) - test_that("history(...,simplifyVector = FALSE, flatten = FALSE) returns a list", { - the_list_history <- history(benchmark_id = the_id, simplifyVector = FALSE, flatten = FALSE) - expect_type( - the_list_history, - "list" - ) - expect_identical(the_id, the_list_history[[1]]$benchmark_id) - }) -}) \ No newline at end of file +})