From 1017db48acf0413b94d9f124c6c0fb0228c8f3ed Mon Sep 17 00:00:00 2001 From: mpadge Date: Tue, 27 Aug 2024 15:19:27 +0200 Subject: [PATCH] rearrange srr 'stats_badge' fn and extend tests --- DESCRIPTION | 2 +- R/srr.R | 12 +++++++++-- codemeta.json | 2 +- tests/testthat/test-srr.R | 44 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 50ba277..f9a85e8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: roreviewapi Title: Plumber API to report package structure and function -Version: 0.1.0.045 +Version: 0.1.0.046 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/srr.R b/R/srr.R index 2da2597..cd6f0cb 100644 --- a/R/srr.R +++ b/R/srr.R @@ -258,6 +258,11 @@ stats_badge <- function (repo = "ropensci/software-review", out <- system2 ("gh", args = args, stdout = TRUE, wait = TRUE) + return (stats_badge_from_opening_comment (out)) +} + +stats_badge_from_opening_comment <- function (out) { + type <- get_html_var (out, "submission-type") if (length (type) == 0L) { return (NULL) @@ -267,6 +272,7 @@ stats_badge <- function (repo = "ropensci/software-review", } labels <- grep ("^labels\\:", out, value = TRUE) [1] + res <- NULL if (grepl ("approved", labels)) { @@ -279,8 +285,10 @@ stats_badge <- function (repo = "ropensci/software-review", } else { grade <- get_html_var (out, "statsgrade") - version <- stats_version (truncated = TRUE) - res <- paste0 ("6/approved-", grade, "-v", version) + if (length (grade) > 0L) { + version <- stats_version (truncated = TRUE) + res <- paste0 ("6/approved-", grade, "-v", version) + } } diff --git a/codemeta.json b/codemeta.json index 208c883..ef6a838 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/roreviewapi", "issueTracker": "https://github.com/ropensci-review-tools/roreviewapi/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.1.0.045", + "version": "0.1.0.046", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/tests/testthat/test-srr.R b/tests/testthat/test-srr.R index 1ea1689..cd262a9 100644 --- a/tests/testthat/test-srr.R +++ b/tests/testthat/test-srr.R @@ -53,3 +53,47 @@ test_that ("srr", { # But should include non-zero counts of stds not complied with: expect_true (grepl ("Not complied with", counts, fixed = TRUE)) }) + +test_that ("srr stats version", { + v <- stats_version () + expect_type (v, "character") + expect_length (v, 1L) + expect_true (grepl ("^[0-9]\\.[0-9]$", v)) +}) + +test_that ("html-var", { + x <- "Standard" + v <- get_html_var (x) + expect_type (v, "character") + expect_length (v, 1L) + expect_equal (v, "Standard") +}) + +test_that ("stats_badge", { + expect_null (stats_badge_from_opening_comment ("")) + out <- "Submission type: Not-Stats" + expect_null (stats_badge_from_opening_comment (out)) + out <- c ( + "Submission type: Stats", + "labels: A label" + ) + expect_null (stats_badge_from_opening_comment (out)) + out [2] <- "labels: approved" + b <- stats_badge_from_opening_comment (out) + expect_length (b, 0L) # character(0) rather than NULL + lbl <- "6/approved-bronze-v1.2" + out [2] <- paste0 ("labels: ", lbl) + b <- stats_badge_from_opening_comment (out) + expect_type (b, "character") + expect_length (b, 1L) + expect_equal (b, lbl) + + out <- c ( + "Submission type: Stats", + "Badge grade: gold" + ) + b <- stats_badge_from_opening_comment (out) + expect_type (b, "character") + expect_length (b, 1L) + expect_true (grepl ("^6\\/approved\\-gold\\-", b)) +})