Skip to content

Commit

Permalink
add stats-badge fn for #9
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Aug 23, 2021
1 parent 0f3307a commit a734ef1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 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.0.0.123
Version: 0.0.0.124
Authors@R:
person(given = "Mark",
family = "Padgham",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(pkgrep_install_deps)
export(post_to_issue)
export(push_to_gh_pages)
export(serve_api)
export(stats_badge)
export(stats_version)
export(stdout_stderr_cache)
export(symbol_crs)
Expand Down
42 changes: 42 additions & 0 deletions R/srr.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,45 @@ stats_version <- function () {

return (v)
}

#' Get stats badge grade and standards version for a submission
#'
#' @param repo The submission repo
#' @param issue_num GitHub issue number of submission
#' @return A single character containing the label used directly for the issue
#' badge
#' @export
stats_badge <- function (repo = "ropensci/software-review",
issue_num = 258) {

# This by default returns only the opening comment. Additional comments can
# be extracted with the "-c" flag.
args <- list ("issue",
"view",
issue_num,
"-R",
repo)

out <- system2 ("gh", args = args, stdout = TRUE, wait = TRUE)

type <- get_html_var (out, "submission-type")
if (length (type) == 0L)
return (NULL)

grade <- get_html_var (out, "statsgrade")
version <- stats_version ()

if (type != "Stats")
return (NULL)

return (paste0 ("6\approved-", grade, "-v", version))
}

get_html_var <- function (x, expr = "submission-type") {

x <- grep (paste0 ("<!--", expr, "-->"), x, value = TRUE)
x <- regmatches (x, regexpr ("\\-\\->.*<!\\-\\-", x))
x <- gsub ("\\-\\->|<!\\-\\-", "", x)

return (x)
}
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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.0.0.123",
"version": "0.0.0.124",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
20 changes: 20 additions & 0 deletions man/stats_badge.Rd

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

0 comments on commit a734ef1

Please sign in to comment.