From aeb86b2f4ae2711452ac72eb9229feb21020a0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlle=20Salmon?= Date: Tue, 8 Oct 2024 10:30:33 +0200 Subject: [PATCH] some more work --- .Rbuildignore | 1 + DESCRIPTION | 9 +- NAMESPACE | 1 + R/universe.R | 27 ++ R/utils.R | 28 +- man/starchart-package.Rd | 8 + man/universe_ls.Rd | 5 + man/universe_packages.Rd | 30 ++ man/universe_query.Rd | 22 + tests/testthat.R | 12 + tests/testthat/setup.R | 1 + tests/testthat/test-universe.R | 15 + .../univ-ls/maelle.r-universe.dev/api/ls.json | 6 + .../api/packages-b93a9c.json | 399 ++++++++++++++++++ 14 files changed, 555 insertions(+), 9 deletions(-) create mode 100644 man/universe_packages.Rd create mode 100644 man/universe_query.Rd create mode 100644 tests/testthat.R create mode 100644 tests/testthat/setup.R create mode 100644 tests/testthat/test-universe.R create mode 100644 tests/testthat/univ-ls/maelle.r-universe.dev/api/ls.json create mode 100644 tests/testthat/univ-packages/maelle.r-universe.dev/api/packages-b93a9c.json diff --git a/.Rbuildignore b/.Rbuildignore index 62e7f5b..98fafb7 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,4 @@ ^starchart\.Rproj$ ^\.Rproj\.user$ ^LICENSE\.md$ +^man/universe_query\.Rd$ diff --git a/DESCRIPTION b/DESCRIPTION index d1bcc35..5d04db2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,12 +7,17 @@ Authors@R: Description: Client to access the 'R-Universe' 'API'. License: MIT + file LICENSE Encoding: UTF-8 -Roxygen: list(markdown = TRUE) +Roxygen: list(markdown = TRUE, roclets = c("collate", "rd", "namespace", "devtag::dev_roclet")) RoxygenNote: 7.3.2 -Depends: +Depends: R (>= 4.2.0) Imports: cli, httr2 URL: https://github.com/ropenscilabs/starchart BugReports: https://github.com/ropenscilabs/starchart/issues +Config/Needs/build: moodymudskipper/devtag +Suggests: + httptest2, + testthat (>= 3.0.0) +Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 65a3aa7..9ecbf4e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,3 +1,4 @@ # Generated by roxygen2: do not edit by hand export(universe_ls) +export(universe_packages) diff --git a/R/universe.R b/R/universe.R index 96da412..68151cb 100644 --- a/R/universe.R +++ b/R/universe.R @@ -8,6 +8,7 @@ #' @examplesIf interactive() #' universe_ls("jeroen") #' universe_ls("ropensci") +#' @family universe universe_ls <- function(universe) { if (!is.character(universe) || length(universe) != 1) { cli::cli_abort("{.arg universe} must be a character of length 1.") @@ -20,3 +21,29 @@ universe_ls <- function(universe) { ) |> unlist() } + + +#' Info on all packages in an universe +#' +#' @param universe Name of the universe (character of length 1) +#' @param limit Number of results to return (integer of length 1) +#' +#' @return A list with information on all packages in the universe. +#' @export +#' +#' @examplesIf interactive() +#' universe_packages("jeroen") +#' universe_packages("ropensci") +#' @family universe +universe_packages <- function(universe, limit = 100) { + 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 + + universe_query( + universe_url = sprintf("https://%s.r-universe.dev", universe), + path = "packages", + query_params = list(limit = limit) + ) +} diff --git a/R/utils.R b/R/utils.R index 09a4839..97c08bc 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,8 +1,22 @@ -universe_query <- function(universe_url, path) { - httr2::request(universe_url) |> - httr2::req_url_path("api") |> - httr2::req_url_path_append(path) |> - httr2::req_user_agent("starchart R package") |> - httr2::req_perform() |> - httr2::resp_body_json() +#' Query the API of a single universe +#' +#' @param universe_url URL to the universe like ""https://jeroen.r-universe.dev" +#' @param path Path to append after api like "ls" +#' @param query_params Named list of query parameters +#' +#' @return The JSON from the API as a list +#' @dev +#' +universe_query <- function(universe_url, path, query_params = NULL) { + request <- httr2::request(universe_url) |> + httr2::req_url_path("api") |> + httr2::req_url_path_append(path) |> + httr2::req_user_agent("starchart R package") + + if (!is.null(query_params)) { + request <- httr2::req_url_query(request, !!!query_params) + } + + httr2::req_perform(request) |> + httr2::resp_body_json() } diff --git a/man/starchart-package.Rd b/man/starchart-package.Rd index e69c690..cf8238a 100644 --- a/man/starchart-package.Rd +++ b/man/starchart-package.Rd @@ -7,6 +7,14 @@ \title{starchart: 'R-Universe' 'API'} \description{ Client to access the 'R-Universe' 'API'. +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://github.com/ropenscilabs/starchart} + \item Report bugs at \url{https://github.com/ropenscilabs/starchart/issues} +} + } \author{ \strong{Maintainer}: Maëlle Salmon \email{msmaellesalmon@gmail.com} (\href{https://orcid.org/0000-0002-2815-0399}{ORCID}) diff --git a/man/universe_ls.Rd b/man/universe_ls.Rd index 491c3a1..add54eb 100644 --- a/man/universe_ls.Rd +++ b/man/universe_ls.Rd @@ -21,3 +21,8 @@ universe_ls("jeroen") universe_ls("ropensci") \dontshow{\}) # examplesIf} } +\seealso{ +Other universe: +\code{\link{universe_packages}()} +} +\concept{universe} diff --git a/man/universe_packages.Rd b/man/universe_packages.Rd new file mode 100644 index 0000000..80d1813 --- /dev/null +++ b/man/universe_packages.Rd @@ -0,0 +1,30 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/universe.R +\name{universe_packages} +\alias{universe_packages} +\title{Info on all packages in an universe} +\usage{ +universe_packages(universe, limit = 100) +} +\arguments{ +\item{universe}{Name of the universe (character of length 1)} + +\item{limit}{Number of results to return (integer of length 1)} +} +\value{ +A list with information on all packages in the universe. +} +\description{ +Info on all packages in an universe +} +\examples{ +\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +universe_packages("jeroen") +universe_packages("ropensci") +\dontshow{\}) # examplesIf} +} +\seealso{ +Other universe: +\code{\link{universe_ls}()} +} +\concept{universe} diff --git a/man/universe_query.Rd b/man/universe_query.Rd new file mode 100644 index 0000000..a7334f3 --- /dev/null +++ b/man/universe_query.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{universe_query} +\alias{universe_query} +\title{Query the API of a single universe} +\usage{ +universe_query(universe_url, path, query_params) +} +\arguments{ +\item{universe_url}{URL to the universe like ""https://jeroen.r-universe.dev"} + +\item{path}{Path to append after api like "ls"} + +\item{query_params}{Named list of query parameters} +} +\value{ +The JSON from the API as a list +} +\description{ +Query the API of a single universe +} +\keyword{internal} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..e37309d --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(starchart) + +test_check("starchart") diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R new file mode 100644 index 0000000..4c9cf1d --- /dev/null +++ b/tests/testthat/setup.R @@ -0,0 +1 @@ +library(httptest2) diff --git a/tests/testthat/test-universe.R b/tests/testthat/test-universe.R new file mode 100644 index 0000000..5341f53 --- /dev/null +++ b/tests/testthat/test-universe.R @@ -0,0 +1,15 @@ +test_that("universe_ls() works", { + httptest2::with_mock_dir("univ-ls", { + packages <- universe_ls("maelle") + }) + expect_type(packages, "character") + expect_gt(length(packages), 0) +}) + +test_that("universe_packages() works", { + httptest2::with_mock_dir("univ-packages", { + packages <- universe_packages("maelle", limit = 1) + }) + expect_type(packages, "list") + expect_gt(length(packages), 0) +}) diff --git a/tests/testthat/univ-ls/maelle.r-universe.dev/api/ls.json b/tests/testthat/univ-ls/maelle.r-universe.dev/api/ls.json new file mode 100644 index 0000000..a2fedf4 --- /dev/null +++ b/tests/testthat/univ-ls/maelle.r-universe.dev/api/ls.json @@ -0,0 +1,6 @@ +[ + "cransays", + "glitter", + "roblog", + "testthat" +] diff --git a/tests/testthat/univ-packages/maelle.r-universe.dev/api/packages-b93a9c.json b/tests/testthat/univ-packages/maelle.r-universe.dev/api/packages-b93a9c.json new file mode 100644 index 0000000..c3323b1 --- /dev/null +++ b/tests/testthat/univ-packages/maelle.r-universe.dev/api/packages-b93a9c.json @@ -0,0 +1,399 @@ +[ + { + "Package": "cransays", + "Title": "Creates an Overview of CRAN Incoming Submissions", + "Version": "0.0.0.9000", + "Authors@R": "c(\nperson(\"Hugo\", \"Gruson\", , \"hugo.gruson+R@normalesup.org\", role = c(\"cre\", \"aut\"),\ncomment = c(ORCID = \"0000-0002-4094-1476\")),\nperson(\"Maëlle\", \"Salmon\", role = c(\"aut\", \"ccp\"),\ncomment = c(ORCID = \"0000-0002-2815-0399\")),\nperson(\"Locke Data\", role = \"fnd\",\ncomment = \"https://itsalocke.com\"),\nperson(\"Stephanie\", \"Locke\", , \"steph@itsalocke.com\", role = \"aut\",\ncomment = c(ORCID = \"0000-0002-2387-3723\")),\nperson(\"Mitchell\", \"O'Hara-Wild\", role = \"aut\",\ncomment = c(ORCID = \"0000-0001-6729-7695\")),\nperson(\"Lluís\", \"Revilla Sancho\", role = \"aut\",\ncomment = c(ORCID = \"0000-0001-9747-2570\")),\nperson(\"Jim\", \"Hester\", role = \"ctb\",\ncomment = c(ORCID = \"0000-0002-2739-7082\")),\nperson(\"Hadley\", \"Wickham\", role = \"ctb\",\ncomment = c(ORCID = \"0000-0003-4757-117X\"))\n)", + "Description": "It scrapes the CRAN incoming FTP folder to find where each\nsubmission is.", + "License": "MIT + file LICENSE", + "URL": "https://github.com/r-hub/cransays,\nhttps://r-hub.github.io/cransays/", + "BugReports": "https://github.com/r-hub/cransays/issues", + "VignetteBuilder": "knitr", + "Encoding": "UTF-8", + "RoxygenNote": "7.1.2", + "Repository": "https://maelle.r-universe.dev", + "RemoteUrl": "https://github.com/lockedata/cransays", + "RemoteRef": "HEAD", + "RemoteSha": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "NeedsCompilation": "no", + "Packaged": { + "Date": "2024-09-26 05:16:30 UTC", + "User": "root" + }, + "Author": "Hugo Gruson [cre, aut] (),\nMaëlle Salmon [aut, ccp] (),\nLocke Data [fnd] (https://itsalocke.com),\nStephanie Locke [aut] (),\nMitchell O'Hara-Wild [aut] (),\nLluís Revilla Sancho [aut] (),\nJim Hester [ctb] (),\nHadley Wickham [ctb] ()", + "Maintainer": "Hugo Gruson ", + "MD5sum": "c364b22c24fd3a1274225ca029d6826f", + "_user": "maelle", + "_type": "src", + "_file": "cransays_0.0.0.9000.tar.gz", + "_fileid": "c364b22c24fd3a1274225ca029d6826f", + "_filesize": 390388, + "_sha256": "b21e0b4f7c0f93564f951be6920693a6faea0587952de334ac3ada4ba4ef9b2d", + "_created": "2024-09-26T05:16:30.000Z", + "_published": "2024-09-26T05:22:02.150Z", + "_upstream": "https://github.com/lockedata/cransays", + "_commit": { + "id": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "author": "Hugo Gruson <10783929+Bisaloo@users.noreply.github.com>", + "committer": "Hugo Gruson <10783929+Bisaloo@users.noreply.github.com>", + "message": "Add seconds to filename for historical archives\n\nTo avoid conflicts when two workflows happen to snapshot at the same minute.\n", + "time": 1724754984 + }, + "_maintainer": { + "name": "Hugo Gruson", + "email": "hugo.gruson+r@normalesup.org", + "login": "bisaloo", + "mastodon": "https://mastodon.social/@grusonh", + "uuid": 10783929, + "orcid": "0000-0002-4094-1476" + }, + "_distro": "noble", + "_host": "GitHub-Actions", + "_status": "success", + "_pkgdocs": "skipped", + "_winbinary": "success", + "_macbinary": "success", + "_wasmbinary": "success", + "_linuxdevel": "success", + "_windevel": "success", + "_buildurl": "https://github.com/r-universe/maelle/actions/runs/11045976753", + "_registered": true, + "_dependencies": [ + { + "package": "curl", + "role": "Imports" + }, + { + "package": "dplyr", + "role": "Imports" + }, + { + "package": "glue", + "role": "Imports" + }, + { + "package": "lubridate", + "role": "Imports" + }, + { + "package": "magrittr", + "role": "Imports" + }, + { + "package": "prettyunits", + "role": "Imports" + }, + { + "package": "ps", + "role": "Imports" + }, + { + "package": "purrr", + "role": "Imports" + }, + { + "package": "reactable", + "role": "Imports" + }, + { + "package": "tibble", + "role": "Imports" + }, + { + "package": "tidyr", + "role": "Imports" + }, + { + "package": "utils", + "role": "Imports" + }, + { + "package": "knitr", + "role": "Suggests" + }, + { + "package": "pkgdown", + "role": "Suggests" + }, + { + "package": "rmarkdown", + "role": "Suggests" + } + ], + "_owner": "lockedata", + "_selfowned": false, + "_usedby": 0, + "_updates": [ + { + "week": "2023-49", + "n": 1 + }, + { + "week": "2023-50", + "n": 5 + }, + { + "week": "2024-05", + "n": 1 + }, + { + "week": "2024-09", + "n": 1 + }, + { + "week": "2024-13", + "n": 10 + }, + { + "week": "2024-18", + "n": 1 + }, + { + "week": "2024-19", + "n": 1 + }, + { + "week": "2024-35", + "n": 1 + } + ], + "_tags": [ + + ], + "_stars": 77, + "_contributions": { + "maelle": 110, + "bisaloo": 59, + "mitchelloharawild": 7, + "jimhester": 3, + "stephlocke": 3, + "hadley": 2, + "llrs": 2, + "alexisderumigny": 1, + "bbolker": 1, + "gadenbuie": 1, + "jeroen": 1, + "olivroy": 1 + }, + "_userbio": { + "uuid": 8360597, + "type": "user", + "name": "Maëlle Salmon", + "description": "R(esearch) Software Engineer, Blogger" + }, + "_downloads": { + "count": 0, + "source": "https://cranlogs.r-pkg.org/downloads/total/last-month/cransays" + }, + "_devurl": "https://github.com/r-hub/cransays", + "_pkgdown": "https://r-hub.github.io/cransays", + "_searchresults": 0, + "_assets": [ + "extra/citation.cff", + "extra/citation.html", + "extra/citation.json", + "extra/citation.txt", + "extra/contents.json", + "extra/cransays.html", + "extra/readme.html", + "extra/readme.md", + "manual.pdf" + ], + "_cranurl": false, + "_exports": [ + "%>%", + "download_history", + "take_snapshot" + ], + "_help": [ + { + "page": "download_history", + "title": "Downloads history", + "topics": [ + "download_history" + ] + }, + { + "page": "take_snapshot", + "title": "Take Snapshot of CRAN incoming folder", + "topics": [ + "take_snapshot" + ] + } + ], + "_readme": "https://github.com/lockedata/cransays/raw/HEAD/README.md", + "_rundeps": [ + "base64enc", + "bslib", + "cachem", + "cli", + "cpp11", + "curl", + "digest", + "dplyr", + "evaluate", + "fansi", + "fastmap", + "fontawesome", + "fs", + "generics", + "glue", + "highr", + "htmltools", + "htmlwidgets", + "jquerylib", + "jsonlite", + "knitr", + "lifecycle", + "lubridate", + "magrittr", + "memoise", + "mime", + "pillar", + "pkgconfig", + "prettyunits", + "ps", + "purrr", + "R6", + "rappdirs", + "reactable", + "reactR", + "rlang", + "rmarkdown", + "sass", + "stringi", + "stringr", + "tibble", + "tidyr", + "tidyselect", + "timechange", + "tinytex", + "utf8", + "vctrs", + "withr", + "xfun", + "yaml" + ], + "_vignettes": [ + { + "source": "dashboard.Rmd", + "filename": "dashboard.html", + "title": "CRAN incoming dashboard", + "engine": "knitr::rmarkdown", + "headings": [ + "Dashboard", + "CRAN review workflow" + ], + "created": "2018-10-09 07:48:47", + "modified": "2024-08-27 10:36:24", + "commits": 34 + } + ], + "_score": 6.529943401658668, + "_indexed": false, + "_nocasepkg": "cransays", + "_universes": [ + "maelle" + ], + "_binaries": [ + { + "r": "4.5.0", + "os": "linux", + "version": "0.0.0.9000", + "date": "2024-09-26T05:18:46.000Z", + "distro": "noble", + "commit": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "fileid": "8ab633f49c6a158aca344c814d1beece", + "status": "success", + "check": "NOTE", + "buildurl": "https://github.com/r-universe/maelle/actions/runs/11045976753" + }, + { + "r": "4.4.1", + "os": "linux", + "version": "0.0.0.9000", + "date": "2024-09-26T05:16:30.000Z", + "distro": "noble", + "commit": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "fileid": "a8953d8f099ff41faa39587479f38114", + "status": "success", + "buildurl": "https://github.com/r-universe/maelle/actions/runs/11045976753" + }, + { + "r": "4.3.3", + "os": "mac", + "version": "0.0.0.9000", + "date": "2024-09-26T05:21:36.000Z", + "commit": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "fileid": "aa45889efd86e136caf15a061bc8914b", + "status": "success", + "check": "NOTE", + "buildurl": "https://github.com/r-universe/maelle/actions/runs/11045976753" + }, + { + "r": "4.4.1", + "os": "mac", + "version": "0.0.0.9000", + "date": "2024-09-26T05:21:39.000Z", + "commit": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "fileid": "2d68c6fa1e61f28a4b0a3ac3b3583363", + "status": "success", + "check": "NOTE", + "buildurl": "https://github.com/r-universe/maelle/actions/runs/11045976753" + }, + { + "r": "4.3.3", + "os": "wasm", + "version": "0.0.0.9000", + "date": "2024-09-26T05:18:46.000Z", + "commit": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "fileid": "ff50acfd777af1b66a29a652124c59b7", + "status": "success", + "buildurl": "https://github.com/r-universe/maelle/actions/runs/11045976753" + }, + { + "r": "4.4.1", + "os": "wasm", + "version": "0.0.0.9000", + "date": "2024-09-26T05:18:44.000Z", + "commit": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "fileid": "3551c062b11828e777811bf5f91365ff", + "status": "success", + "buildurl": "https://github.com/r-universe/maelle/actions/runs/11045976753" + }, + { + "r": "4.5.0", + "os": "win", + "version": "0.0.0.9000", + "date": "2024-09-26T05:18:21.000Z", + "commit": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "fileid": "5d7d3b0ea015a6c4ab2d614cb01c7142", + "status": "success", + "check": "NOTE", + "buildurl": "https://github.com/r-universe/maelle/actions/runs/11045976753" + }, + { + "r": "4.3.3", + "os": "win", + "version": "0.0.0.9000", + "date": "2024-09-26T05:18:20.000Z", + "commit": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "fileid": "f6616f5d91c23e8b3d8bf645a8b91cc2", + "status": "success", + "check": "NOTE", + "buildurl": "https://github.com/r-universe/maelle/actions/runs/11045976753" + }, + { + "r": "4.4.1", + "os": "win", + "version": "0.0.0.9000", + "date": "2024-09-26T05:18:24.000Z", + "commit": "6fee0071e425a5cf1082ce5c91c8745045b64fc7", + "fileid": "b4996840ede644187c5c3b6b23182d92", + "status": "success", + "check": "NOTE", + "buildurl": "https://github.com/r-universe/maelle/actions/runs/11045976753" + } + ] + } +]