-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from conbench/aus/paginate2
Add pagination to runs()
- Loading branch information
Showing
16 changed files
with
97 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: conbenchcoms | ||
Title: An API wrapper for conbench communications | ||
Version: 0.0.6 | ||
Version: 0.0.7 | ||
Authors@R: c( | ||
person("Jonathan", "Keane", , "[email protected]", role = c("aut", "ctb"), | ||
comment = c(ORCID = "0000-0001-7087-9776")), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,32 @@ | ||
#' Get a list of runs | ||
#' Get runs | ||
#' | ||
#' @param sha the hash of a commit to search for (default: `NULL`, list all) | ||
#' @inheritParams jsonlite::fromJSON | ||
#' @inheritDotParams httr2::resp_body_json | ||
#' @param commit_hashes the commit hashes to search for (required) | ||
#' | ||
#' @return the response | ||
#' @return a tibble of runs | ||
#' @export | ||
runs <- function(sha = NULL, simplifyVector = TRUE, flatten = TRUE, ...) { | ||
runs <- function(commit_hashes) { | ||
req <- req_url_path_append(conbench_request(), "runs") | ||
req <- req_url_query( | ||
req, | ||
page_size = 1000, | ||
commit_hash = paste0(commit_hashes, collapse = ",") | ||
) | ||
resp <- conbench_perform(req) | ||
json <- resp_body_json(resp, simplifyVector = TRUE, flatten = TRUE) | ||
data <- dplyr::as_tibble(json[["data"]]) | ||
|
||
if (!is.null(sha)) { | ||
req <- req_url_query(req, sha = paste0(sha, collapse = ",")) | ||
while (!is.null(json[["metadata"]][["next_page_cursor"]])) { | ||
req <- req_url_path_append(conbench_request(), "runs") | ||
req <- req_url_query( | ||
req, | ||
page_size = 1000, | ||
commit_hash = paste0(commit_hashes, collapse = ","), | ||
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 <- conbench_perform(req) | ||
|
||
resp_body_json(resp, simplifyVector = simplifyVector, flatten = flatten, ...) | ||
} | ||
data | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"commit": { | ||
"sha": "babb1ed", | ||
"timestamp": "2022-03-20T21:05:12" | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"next_page_cursor": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"commit": { | ||
"id": "id1", | ||
"sha": "babb1ed", | ||
"timestamp": "2022-03-20T21:05:12" | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"next_page_cursor": "curse" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"commit": { | ||
"id": "id2", | ||
"sha": "5eaf00d", | ||
"timestamp": "2022-05-20T21:05:12" | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"next_page_cursor": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,32 @@ | ||
with_mock_dir(test_path("logged-in"), { | ||
test_that("runs()", { | ||
expect_GET( | ||
runs(), | ||
"http://localhost/api/runs" | ||
) | ||
|
||
expect_GET( | ||
runs(sha = "C0C0A"), | ||
"http://localhost/api/runs?sha=C0C0A" | ||
runs(commit_hashes = c("C0C0A", "BEEF")), | ||
"http://localhost/api/runs?page_size=1000&commit_hash=C0C0A%2CBEEF" | ||
) | ||
}) | ||
}) | ||
|
||
with_mock_dir(test_path("resp-class"), { | ||
sha_1 <- "babb1ed" | ||
sha_2 <- "5eaf00d" | ||
test_that("runs() returns a data.frame", { | ||
the_run <- runs(sha = sha_1) | ||
test_that("runs() returns a tibble", { | ||
the_run <- runs(commit_hashes = sha_1) | ||
expect_s3_class( | ||
the_run, | ||
"data.frame" | ||
"tbl_df" | ||
) | ||
expect_identical(sha_1, the_run$commit.sha) | ||
}) | ||
|
||
test_that("runs() accepts and returns multiple values", { | ||
shas <- c(sha_1, sha_2) | ||
runs <- runs(sha = shas) | ||
runs <- runs(commit_hashes = shas) | ||
expect_s3_class( | ||
runs, | ||
"data.frame" | ||
"tbl_df" | ||
) | ||
expect_identical(shas, unique(runs$commit.sha)) | ||
}) | ||
|
||
test_that("runs() returns a list", { | ||
the_list_run <- runs(sha = sha_1, simplifyVector = FALSE, flatten = FALSE) | ||
expect_type( | ||
the_list_run, | ||
"list" | ||
) | ||
expect_identical(sha_1, the_list_run[[1]]$commit$sha) | ||
}) | ||
}) |