diff --git a/DESCRIPTION b/DESCRIPTION index cd364c3..2585c86 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: repometrics Title: Metrics for Your Code Repository -Version: 0.1.3.003 +Version: 0.1.3.006 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/NAMESPACE b/NAMESPACE index 6a74f85..775ecec 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,7 +2,6 @@ export(repo_pkgstats_history) export(repometrics_dashboard) -export(repometrics_data) -export(rm_data_repo) -export(rm_data_user) +export(repometrics_data_pkg) +export(repometrics_data_user) importFrom(memoise,memoise) diff --git a/R/data-dependencies.R b/R/data-dependencies.R index 56eeaab..c2edaa4 100644 --- a/R/data-dependencies.R +++ b/R/data-dependencies.R @@ -62,9 +62,12 @@ rm_data_libyears <- function (path) { deps <- deps [which (!is.na (deps$published)), ] rel <- rm_data_releases_from_gh_api (path, latest_only = TRUE) - rel_date <- as.Date (strftime (rel$published_at, format = "%Y-%m-%d")) + dt <- NA_real_ + if (nrow (rel) > 0L) { + rel_date <- as.Date (strftime (rel$published_at, format = "%Y-%m-%d")) + dt <- difftime (deps$published, rel_date, units = "days") - dt <- difftime (deps$published, rel_date, units = "days") + } deps$libyears <- as.numeric (dt) / 365.25 # In years return (deps) diff --git a/R/data-repo.R b/R/data-repo.R index 48d28df..6c1151b 100644 --- a/R/data-repo.R +++ b/R/data-repo.R @@ -1,3 +1,33 @@ +#' Collate 'repometrics' data for a local R package +#' +#' @inheritParams repo_pkgstats_history +#' @return A list with two main items: +#' \enumerate{ +#' \item "pkgstats" Containing summary data from apply `pkgstats` routines +#' across the git history of the repository. +#' \item "cm" Containing data used to derive "CHAOSS metrics", primarily from +#' GitHub data. +#' } +#' +#' @export +repometrics_data_pkg <- function (path, step_days = 1L, num_cores = -1L) { + + cli::cli_alert_info ("Extracting package statistics ...") + pkgstats <- repo_pkgstats_history ( + path, + step_days = step_days, + num_cores = num_cores + ) + cli::cli_alert_success ("Done!") + + cli::cli_alert_info ("Extracting GitHub data ...") + rm <- rm_data_repo (path) + rm$contributors <- get_all_contribs (rm$contribs_from_log, rm$contribs_from_gh_api) + cli::cli_alert_success ("Done!") + + list (pkgstats = pkgstats, rm = rm) +} + #' Calculate all repository data used in CHAOSS metrics #' \url{https://chaoss.community/kb-metrics-and-metrics-models/}. #' @@ -23,7 +53,7 @@ #' \item `repo_from_gh_api` A `data.frame` of a single line, with several key #' attributes of the repository on GitHub. #' } -#' @export +#' @noRd rm_data_repo <- function (path) { checkmate::assert_directory_exists (path) @@ -51,9 +81,6 @@ get_rm_data_fns <- function () { data_fns <- data_fns [which (!grepl ("\\_internal$", data_fns))] data_fns <- data_fns [which (!data_fns == "rm_data_repo")] - index <- grep ("user", data_fns) - data_fns <- data_fns [-index] - return (data_fns) } diff --git a/R/data-user.R b/R/data-user.R index 37581bd..0b6917b 100644 --- a/R/data-user.R +++ b/R/data-user.R @@ -18,10 +18,10 @@ #' \item `issues` with information on all issues opened by user #' } #' @export -rm_data_user <- function (login, - ended_at = Sys.time (), - nyears = 1, - n_per_page = 100) { +repometrics_data_user <- function (login, + ended_at = Sys.time (), + nyears = 1, + n_per_page = 100) { checkmate::assert_character (login, len = 1L) diff --git a/R/quarto-dashboard.R b/R/quarto-dashboard.R index 6ed37bb..e9e7651 100644 --- a/R/quarto-dashboard.R +++ b/R/quarto-dashboard.R @@ -1,8 +1,8 @@ -#' Start quarto dashboard with results of main \link{repometrics_data} +#' Start quarto dashboard with results of main \link{repometrics_data_pkg} #' function. #' -#' @param data Results of main \link{repometrics_data} function applied -#' to one package. +#' @param data Results of main \link{repometrics_data_pkg} function applied to +#' one package. #' @param action One of "preview", to start and open a live preview of the #' dashboard website, or "render" to render a static version without previewing #' or opening. diff --git a/R/repometrics-data.R b/R/repometrics-data.R deleted file mode 100644 index 96947f0..0000000 --- a/R/repometrics-data.R +++ /dev/null @@ -1,29 +0,0 @@ -#' Collate 'repometrics' data for a local R package -#' -#' @inheritParams repo_pkgstats_history -#' @return A list with two main items: -#' \enumerate{ -#' \item "pkgstats" Containing summary data from apply `pkgstats` routines -#' across the git history of the repository. -#' \item "cm" Containing data used to derive "CHAOSS metrics", primarily from -#' GitHub data. -#' } -#' -#' @export -repometrics_data <- function (path, step_days = 1L, num_cores = -1L) { - - cli::cli_alert_info ("Extracting package statistics ...") - pkgstats <- repo_pkgstats_history ( - path, - step_days = step_days, - num_cores = num_cores - ) - cli::cli_alert_success ("Done!") - - cli::cli_alert_info ("Extracting GitHub data ...") - rm <- rm_data_repo (path) - rm$contributors <- get_all_contribs (rm$contribs_from_log, rm$contribs_from_gh_api) - cli::cli_alert_success ("Done!") - - list (pkgstats = pkgstats, rm = rm) -} diff --git a/codemeta.json b/codemeta.json index e5b9c7f..2fa1468 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,7 +8,7 @@ "codeRepository": "https://github.com/ropensci-review-tools/repometrics", "issueTracker": "https://github.com/ropensci-review-tools/repometrics/issues", "license": "https://spdx.org/licenses/GPL-3.0", - "version": "0.1.3.003", + "version": "0.1.3.006", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/man/repometrics_dashboard.Rd b/man/repometrics_dashboard.Rd index 8b25ed5..c7f03c6 100644 --- a/man/repometrics_dashboard.Rd +++ b/man/repometrics_dashboard.Rd @@ -2,14 +2,14 @@ % Please edit documentation in R/quarto-dashboard.R \name{repometrics_dashboard} \alias{repometrics_dashboard} -\title{Start quarto dashboard with results of main \link{repometrics_data} +\title{Start quarto dashboard with results of main \link{repometrics_data_pkg} function.} \usage{ repometrics_dashboard(data, action = "preview") } \arguments{ -\item{data}{Results of main \link{repometrics_data} function applied -to one package.} +\item{data}{Results of main \link{repometrics_data_pkg} function applied to +one package.} \item{action}{One of "preview", to start and open a live preview of the dashboard website, or "render" to render a static version without previewing @@ -21,6 +21,6 @@ that the site must be served with \code{action = "preview"}, and will not work b simply opening this "index.html" file. } \description{ -Start quarto dashboard with results of main \link{repometrics_data} +Start quarto dashboard with results of main \link{repometrics_data_pkg} function. } diff --git a/man/repometrics_data.Rd b/man/repometrics_data_pkg.Rd similarity index 88% rename from man/repometrics_data.Rd rename to man/repometrics_data_pkg.Rd index 128b7ac..0df7fe3 100644 --- a/man/repometrics_data.Rd +++ b/man/repometrics_data_pkg.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/repometrics-data.R -\name{repometrics_data} -\alias{repometrics_data} +% Please edit documentation in R/data-repo.R +\name{repometrics_data_pkg} +\alias{repometrics_data_pkg} \title{Collate 'repometrics' data for a local R package} \usage{ -repometrics_data(path, step_days = 1L, num_cores = -1L) +repometrics_data_pkg(path, step_days = 1L, num_cores = -1L) } \arguments{ \item{path}{Path to local repository containing an R package.} diff --git a/man/rm_data_user.Rd b/man/repometrics_data_user.Rd similarity index 88% rename from man/rm_data_user.Rd rename to man/repometrics_data_user.Rd index 6064670..6f77a6e 100644 --- a/man/rm_data_user.Rd +++ b/man/repometrics_data_user.Rd @@ -1,10 +1,15 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/data-user.R -\name{rm_data_user} -\alias{rm_data_user} +\name{repometrics_data_user} +\alias{repometrics_data_user} \title{Extract and combine all user data} \usage{ -rm_data_user(login, ended_at = Sys.time(), nyears = 1, n_per_page = 100) +repometrics_data_user( + login, + ended_at = Sys.time(), + nyears = 1, + n_per_page = 100 +) } \arguments{ \item{login}{GitHub login of user} diff --git a/man/rm_data_repo.Rd b/man/rm_data_repo.Rd deleted file mode 100644 index 96f49ac..0000000 --- a/man/rm_data_repo.Rd +++ /dev/null @@ -1,39 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data-repo.R -\name{rm_data_repo} -\alias{rm_data_repo} -\title{Calculate all repository data used in CHAOSS metrics -\url{https://chaoss.community/kb-metrics-and-metrics-models/}.} -\usage{ -rm_data_repo(path) -} -\arguments{ -\item{path}{Path to local source repository.} -} -\value{ -A list of the following \code{data.frame} objects: -\enumerate{ -\item \code{contribs_from_gh_api} with details of all code contributors from GitHub -\item \code{contribs_from_log} with details of all code contributors from the local git log -\item \code{dependencies} A simple \code{data.frame} of all package dependencies -\item \code{gh_repo_workflow} with details of all workflows run on GitHub, -including status of most recent runs -\item \code{gitlog} with one row for each git commit, and associated statistics -\item \code{issue_comments_from_gh_api} with details of all comments from all -repository issues on GitHub -\item \code{issues_from_gh_api} with details of all issues on GitHub -\item \code{libyears} The CHAOSS metric described at -\url{https://chaoss.community/kb/metric-libyears/}, measuring the relative -age of a project's dependencies, with lower values indicating more -up-to-date projects. This is the only item which is not a \code{data.frame}, -rather a named numerical vector of mean and median "libyears" -\item \code{prs_from_gh_api} with details of all pull requests on GitHub -\item \code{releases_from_gh_api} with details of all repository releases on GitHub -\item \code{repo_from_gh_api} A \code{data.frame} of a single line, with several key -attributes of the repository on GitHub. -} -} -\description{ -Calculate all repository data used in CHAOSS metrics -\url{https://chaoss.community/kb-metrics-and-metrics-models/}. -} diff --git a/tests/testthat/test-rm-data-gh-user.R b/tests/testthat/test-rm-data-gh-user.R index 03db9d8..5f19e2f 100644 --- a/tests/testthat/test-rm-data-gh-user.R +++ b/tests/testthat/test-rm-data-gh-user.R @@ -69,7 +69,7 @@ test_that ("rm user data internal structures", { expect_named (dat$issue_cmts, nms) }) -test_that ("rm_data_user fn", { +test_that ("repometrics_data_user fn", { Sys.setenv ("REPOMETRICS_TESTS" = "true") dat_mocked <- mock_rm_data (repo = FALSE) @@ -77,7 +77,7 @@ test_that ("rm_data_user fn", { login <- "mpadge" ended_at <- as.POSIXct ("2024-01-01T00:00:00") - dat <- rm_data_user ( + dat <- repometrics_data_user ( login = login, n_per_page = 1, ended_at = ended_at,