Skip to content

Commit

Permalink
rearrange srr 'stats_badge' fn and extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Aug 27, 2024
1 parent ea2d48e commit 1017db4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
12 changes: 10 additions & 2 deletions R/srr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -267,6 +272,7 @@ stats_badge <- function (repo = "ropensci/software-review",
}

labels <- grep ("^labels\\:", out, value = TRUE) [1]
res <- NULL

if (grepl ("approved", labels)) {

Expand All @@ -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)
}

}

Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions tests/testthat/test-srr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <- "<!--submission-type-->Standard<!--end-submission-type-->"
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: <!--submission-type-->Not-Stats<!--end-submission-type-->"
expect_null (stats_badge_from_opening_comment (out))
out <- c (
"Submission type: <!--submission-type-->Stats<!--end-submission-type-->",
"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: <!--submission-type-->Stats<!--end-submission-type-->",
"Badge grade: <!--statsgrade-->gold<!--end-statsgrade-->"
)
b <- stats_badge_from_opening_comment (out)
expect_type (b, "character")
expect_length (b, 1L)
expect_true (grepl ("^6\\/approved\\-gold\\-", b))
})

0 comments on commit 1017db4

Please sign in to comment.