Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Oct 8, 2024
1 parent ced0042 commit 399be6a
Show file tree
Hide file tree
Showing 11 changed files with 897 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
^starchart\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^man/universe_query\.Rd$
^\.github$
^README\.Rmd$
^man/universe_query\.Rd$
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated by roxygen2: do not edit by hand

export(universe_ls)
export(universe_package)
export(universe_packages)
28 changes: 28 additions & 0 deletions R/universe.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,31 @@ universe_packages <- function(universe, limit = 100) {
query_params = list(limit = limit)
)
}


#' Info on a single packages in an universe
#'
#' @param universe Name of the universe (character of length 1)
#' @param package Name of the package (character of length 1)
#'
#' @return A list with information on the package.
#' @export
#'
#' @examplesIf interactive()
#' universe_package("jeroen", package = "curl")
#' @family universe
universe_package <- function(universe, package) {
if (!is.character(universe) || length(universe) != 1) {
cli::cli_abort("{.arg universe} must be a character of length 1.")
}
# TODO assert that universe is an universe

if (!package %in% universe_ls(universe)) {
cli::cli_abort("Can't find package {package} in universe {universe}.")
}

universe_query(
universe_url = sprintf("https://%s.r-universe.dev", universe),
path = sprintf("packages/%s", package),
)
}
1 change: 1 addition & 0 deletions man/universe_ls.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions man/universe_package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/universe_packages.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/universe_query.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/universe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# universe_package() errors well

Code
universe_package("jeroen", package = "shiny")
Condition
Error in `universe_package()`:
! Can't find package shiny in universe jeroen.

14 changes: 14 additions & 0 deletions tests/testthat/test-universe.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ test_that("universe_packages() works", {
expect_type(packages, "list")
expect_gt(length(packages), 0)
})

test_that("universe_package() works", {
httptest2::with_mock_dir("univ-package", {
packages <- universe_package("jeroen", package = "curl")
})
expect_type(packages, "list")
expect_gt(length(packages), 0)
})

test_that("universe_package() errors well", {
expect_snapshot(error = TRUE, {
universe_package("jeroen", package = "shiny")
})
})
21 changes: 21 additions & 0 deletions tests/testthat/univ-package/jeroen.r-universe.dev/api/ls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
"RAppArmor",
"V8",
"badgen",
"base64",
"bcrypt",
"brotli",
"curl",
"gpg",
"js",
"jsonlite",
"maketools",
"mongolite",
"openssl",
"protolite",
"rjade",
"sys",
"unix",
"webp",
"webutils"
]
Loading

0 comments on commit 399be6a

Please sign in to comment.