From f13baa8fe88950c021b1fa08ca57ee587d83df95 Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 25 Nov 2024 13:53:05 +0100 Subject: [PATCH 1/8] rename all cm-data fns 'cm_data_' for #23 --- DESCRIPTION | 2 +- R/cm-data-dependencies.R | 6 ++++-- R/cm-data-gh-contribs.R | 8 ++++++-- R/cm-data-gh-issues.R | 8 ++++++-- R/cm-data-gh-prs.R | 3 ++- R/cm-data-gh-releases.R | 3 ++- R/cm-data-gh-repo.R | 3 ++- codemeta.json | 2 +- 8 files changed, 24 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ae6f6b2..05865f4 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: repometrics Title: Metrics for Your Code Repository -Version: 0.1.1.069 +Version: 0.1.1.070 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/cm-data-dependencies.R b/R/cm-data-dependencies.R index 55ea603..d184de3 100644 --- a/R/cm-data-dependencies.R +++ b/R/cm-data-dependencies.R @@ -27,13 +27,13 @@ cm_data_dependencies <- function (path) { cm_data_libyears <- function (path) { deps <- cm_data_dependencies (path) - cran_db <- data.frame (tools::CRAN_package_db ()) + cran_db <- data.frame (cran_pkg_db ()) index <- match (deps$name, cran_db$Package) deps$cran_version <- cran_db$Version [index] deps$published <- as.Date (cran_db$Published [index]) deps <- deps [which (!is.na (deps$published)), ] - rel <- releases_from_gh_api (path, latest_only = TRUE) + rel <- cm_data_releases_from_gh_api (path, latest_only = TRUE) rel_date <- as.Date (strftime (rel$published_at, format = "%Y-%m-%d")) dt <- difftime (deps$published, rel_date, units = "days") @@ -41,3 +41,5 @@ cm_data_libyears <- function (path) { c (mean = mean (dt), median = stats::median (dt)) } + +cran_pkg_db <- memoise::memoise (tools::CRAN_package_db) diff --git a/R/cm-data-gh-contribs.R b/R/cm-data-gh-contribs.R index 82a990b..968e8c5 100644 --- a/R/cm-data-gh-contribs.R +++ b/R/cm-data-gh-contribs.R @@ -1,4 +1,6 @@ -contribs_from_log <- function (log) { +cm_data_contribs_from_log <- function (path) { + + log <- cm_data_gitlog (path) gh_handle <- unique (log$aut_name) gh_email <- log$aut_email [match (gh_handle, log$aut_name)] @@ -27,7 +29,7 @@ contribs_from_log <- function (log) { ) [index, ] } -contribs_from_gh_api <- function (path, n_per_page = 100) { +cm_data_contribs_from_gh_api_internal <- function (path, n_per_page = 100) { is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true" @@ -80,6 +82,8 @@ contribs_from_gh_api <- function (path, n_per_page = 100) { return (ctbs) } +cm_data_contribs_from_gh_api <- + memoise::memoise (cm_data_contribs_from_gh_api_internal) user_from_gh_api <- function (user) { diff --git a/R/cm-data-gh-issues.R b/R/cm-data-gh-issues.R index 94bce78..1771014 100644 --- a/R/cm-data-gh-issues.R +++ b/R/cm-data-gh-issues.R @@ -1,4 +1,4 @@ -issues_from_gh_api <- function (path, n_per_page = 100) { +cm_data_issues_from_gh_api_internal <- function (path, n_per_page = 100) { is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true" @@ -69,6 +69,8 @@ issues_from_gh_api <- function (path, n_per_page = 100) { return (issues) } +cm_data_issues_from_gh_api <- + memoise::memoise (cm_data_issues_from_gh_api_internal) get_issue_reactions <- function (body) { @@ -87,7 +89,7 @@ get_issue_reactions <- function (body) { return (reaction_counts) } -issue_comments_from_gh_api <- function (path, n_per_page = 100) { +cm_data_issue_comments_from_gh_api_internal <- function (path, n_per_page = 100) { is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true" @@ -138,3 +140,5 @@ issue_comments_from_gh_api <- function (path, n_per_page = 100) { issue_body = issue_body ) } +cm_data_issue_comments_from_gh_api <- + memoise::memoise (cm_data_issue_comments_from_gh_api_internal) diff --git a/R/cm-data-gh-prs.R b/R/cm-data-gh-prs.R index 4e1c863..d15158e 100644 --- a/R/cm-data-gh-prs.R +++ b/R/cm-data-gh-prs.R @@ -107,7 +107,7 @@ gh_prs_qry <- function (org = "ropensci-review-tools", return (q) } -prs_from_gh_api <- function (path, n_per_page = 30L) { +cm_data_prs_from_gh_api_internal <- function (path, n_per_page = 30L) { is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true" if (is_test_env) { @@ -193,3 +193,4 @@ prs_from_gh_api <- function (path, n_per_page = 30L) { reviews = I (reviews) ) } +cm_data_prs_from_gh_api <- memoise::memoise (cm_data_prs_from_gh_api_internal) diff --git a/R/cm-data-gh-releases.R b/R/cm-data-gh-releases.R index 08af318..4a0f56d 100644 --- a/R/cm-data-gh-releases.R +++ b/R/cm-data-gh-releases.R @@ -1,4 +1,4 @@ -releases_from_gh_api <- function (path, n_per_page = 100L, latest_only = FALSE) { +cm_data_releases_from_gh_api_internal <- function (path, n_per_page = 100L, latest_only = FALSE) { checkmate::assert_integerish (n_per_page) checkmate::assert_logical (latest_only) @@ -48,3 +48,4 @@ releases_from_gh_api <- function (path, n_per_page = 100L, latest_only = FALSE) published_at = vapply (body, function (i) i$published_at, character (1L)) ) } +cm_data_releases_from_gh_api <- memoise::memoise (cm_data_releases_from_gh_api_internal) diff --git a/R/cm-data-gh-repo.R b/R/cm-data-gh-repo.R index 6a31ca4..abc65dd 100644 --- a/R/cm-data-gh-repo.R +++ b/R/cm-data-gh-repo.R @@ -1,4 +1,4 @@ -repo_from_gh_api <- function (path) { +cm_data_repo_from_gh_api_internal <- function (path) { or <- org_repo_from_path (path) @@ -36,3 +36,4 @@ repo_from_gh_api <- function (path) { default_branch = null2na_char (body$default_branch) ) } +cm_data_repo_from_gh_api <- memoise::memoise (cm_data_repo_from_gh_api_internal) diff --git a/codemeta.json b/codemeta.json index db3ae0e..0fbf355 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.1.069", + "version": "0.1.1.070", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From eb0689d56298b06f2a69ed25109154a263e6dcde Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 25 Nov 2024 13:54:54 +0100 Subject: [PATCH 2/8] rename test fns for #23 --- DESCRIPTION | 2 +- codemeta.json | 2 +- tests/testthat/test-cm-data-github.R | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 05865f4..7f7f64d 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: repometrics Title: Metrics for Your Code Repository -Version: 0.1.1.070 +Version: 0.1.1.071 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/codemeta.json b/codemeta.json index 0fbf355..e78fcfb 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.1.070", + "version": "0.1.1.071", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/tests/testthat/test-cm-data-github.R b/tests/testthat/test-cm-data-github.R index 9c6c074..31c6a05 100644 --- a/tests/testthat/test-cm-data-github.R +++ b/tests/testthat/test-cm-data-github.R @@ -4,7 +4,7 @@ test_that ("cm data gh contribs", { path <- generate_test_pkg () ctbs <- with_mock_dir ("gh_api_ctbs", { - contribs_from_gh_api (path, n_per_page = 2L) + cm_data_contribs_from_gh_api (path, n_per_page = 2L) }) fs::dir_delete (path) @@ -33,7 +33,7 @@ test_that ("cm data gh repo", { path <- generate_test_pkg () repo <- with_mock_dir ("gh_api_repo", { - repo_from_gh_api (path) + cm_data_repo_from_gh_api (path) }) fs::dir_delete (path) @@ -68,7 +68,7 @@ test_that ("cm data gh issues", { path <- generate_test_pkg () issues <- with_mock_dir ("gh_api_issues", { - issues_from_gh_api (path, n_per_page = 2L) + cm_data_issues_from_gh_api (path, n_per_page = 2L) }) fs::dir_delete (path) @@ -105,7 +105,7 @@ test_that ("cm data gh issue comments", { path <- generate_test_pkg () cmts <- with_mock_dir ("gh_api_issue_cmts", { - issue_comments_from_gh_api (path, n_per_page = 2L) + cm_data_issue_comments_from_gh_api (path, n_per_page = 2L) }) fs::dir_delete (path) @@ -138,7 +138,7 @@ test_that ("cm data gh prs", { path <- generate_test_pkg () prs <- with_mock_dir ("gh_api_prs", { - prs_from_gh_api (path, n_per_page = 2L) + cm_data_prs_from_gh_api (path, n_per_page = 2L) }) fs::dir_delete (path) @@ -182,7 +182,7 @@ test_that ("cm data gh releases", { path <- generate_test_pkg () releases <- with_mock_dir ("gh_api_releases", { - releases_from_gh_api (path, n_per_page = 2L) + cm_data_releases_from_gh_api (path, n_per_page = 2L) }) fs::dir_delete (path) From 7763c68edee2449b5b7daa4527a8a6a84ed35c50 Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 25 Nov 2024 14:03:10 +0100 Subject: [PATCH 3/8] add missing 'gh_libyears' mock test results --- DESCRIPTION | 2 +- codemeta.json | 2 +- .../ghrepos/repo/releases-4aabf7.json | 56 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 tests/testthat/gh_libyears/ghrepos/repo/releases-4aabf7.json diff --git a/DESCRIPTION b/DESCRIPTION index 7f7f64d..9fe2840 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: repometrics Title: Metrics for Your Code Repository -Version: 0.1.1.071 +Version: 0.1.1.072 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/codemeta.json b/codemeta.json index e78fcfb..f6b7c00 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.1.071", + "version": "0.1.1.072", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/tests/testthat/gh_libyears/ghrepos/repo/releases-4aabf7.json b/tests/testthat/gh_libyears/ghrepos/repo/releases-4aabf7.json new file mode 100644 index 0000000..d25e509 --- /dev/null +++ b/tests/testthat/gh_libyears/ghrepos/repo/releases-4aabf7.json @@ -0,0 +1,56 @@ +[ + { + "url": "ghrepos/repo//releases/158953460", + "assets_url": "ghrepos/repo//releases/158953460/assets", + "upload_url": "https://uploads.github.com/repos/repo//releases/158953460/assets{?name,label}", + "html_url": "https://github.com/repo//releases/tag/v1.0.5", + "id": 158953460, + "author": { + "login": "mpadge", + "id": 6697851, + "node_id": "MDQ6VXNlcjY2OTc4NTE=", + "avatar_url": "https://avatars.githubusercontent.com/u/6697851?v=4", + "gravatar_id": "", + "url": "ghusers/mpadge", + "html_url": "https://github.com/mpadge", + "followers_url": "ghusers/mpadge/followers", + "following_url": "ghusers/mpadge/following{/other_user}", + "gists_url": "ghusers/mpadge/gists{/gist_id}", + "starred_url": "ghusers/mpadge/starred{/owner}{/repo}", + "subscriptions_url": "ghusers/mpadge/subscriptions", + "organizations_url": "ghusers/mpadge/orgs", + "repos_url": "ghusers/mpadge/repos", + "events_url": "ghusers/mpadge/events{/privacy}", + "received_events_url": "ghusers/mpadge/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "node_id": "RE_kwDOAwboEs4JeW_0", + "tag_name": "v1.0.5", + "target_commitish": "main", + "name": "goodpractice 1.0.5", + "draft": false, + "prerelease": false, + "created_at": "2024-06-05T09:31:17Z", + "published_at": "2024-06-05T09:34:42Z", + "assets": [ + + ], + "tarball_url": "ghrepos/repo//tarball/v1.0.5", + "zipball_url": "ghrepos/repo//zipball/v1.0.5", + "body": "* New maintainer: rOpenSci\r\n* Package reinstated on CRAN, after archiving of previous version.\r\n* CRAN fixes - skipping failing test and adding \\alias{goodpractice} to package Rd\r\n* Adding docs.ropensci site to DESCRIPTION", + "reactions": { + "url": "ghrepos/repo//releases/158953460/reactions", + "total_count": 1, + "+1": 0, + "-1": 0, + "laugh": 0, + "hooray": 0, + "confused": 0, + "heart": 1, + "rocket": 0, + "eyes": 0 + } + } +] From e7c06cbf41a4a0141a5ec4666ef2780f6b7978a0 Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 25 Nov 2024 14:03:44 +0100 Subject: [PATCH 4/8] add main 'cm-data.R' for #23 --- DESCRIPTION | 2 +- R/cm-data.R | 18 ++++++++++++++++++ codemeta.json | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 R/cm-data.R diff --git a/DESCRIPTION b/DESCRIPTION index 9fe2840..48a4fc8 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: repometrics Title: Metrics for Your Code Repository -Version: 0.1.1.072 +Version: 0.1.1.073 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/cm-data.R b/R/cm-data.R new file mode 100644 index 0000000..3b48044 --- /dev/null +++ b/R/cm-data.R @@ -0,0 +1,18 @@ +cm_data <- function (path) { + + data_fns <- get_cm_data_fns () + + res <- pbapply::pblapply (data_fns, function (i) { + do.call (i, list (path)) + }) + names (res) <- gsub ("^cm\\_data\\_", "", data_fns) + + return (res) +} + +get_cm_data_fns <- function () { + + pkg_fns <- ls (envir = asNamespace ("repometrics")) + data_fns <- grep ("^cm\\_data\\_", pkg_fns, value = TRUE) + data_fns [which (!grepl ("\\_internal$", data_fns))] +} diff --git a/codemeta.json b/codemeta.json index f6b7c00..a36a79a 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.1.072", + "version": "0.1.1.073", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From d17eb137ccdd45443aa4a04da4b7a31cea8739b8 Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 25 Nov 2024 14:16:58 +0100 Subject: [PATCH 5/8] only call pblapply if data_fns not already memoised #23 --- DESCRIPTION | 2 +- R/cm-data.R | 23 ++++++++++++++++++++--- codemeta.json | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 48a4fc8..4fcb30e 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: repometrics Title: Metrics for Your Code Repository -Version: 0.1.1.073 +Version: 0.1.1.074 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/cm-data.R b/R/cm-data.R index 3b48044..955c780 100644 --- a/R/cm-data.R +++ b/R/cm-data.R @@ -2,9 +2,15 @@ cm_data <- function (path) { data_fns <- get_cm_data_fns () - res <- pbapply::pblapply (data_fns, function (i) { - do.call (i, list (path)) - }) + if (all_cm_data_fns_memoised (data_fns, path)) { + res <- lapply (data_fns, function (i) { + do.call (i, list (path)) + }) + } else { + res <- pbapply::pblapply (data_fns, function (i) { + do.call (i, list (path)) + }) + } names (res) <- gsub ("^cm\\_data\\_", "", data_fns) return (res) @@ -16,3 +22,14 @@ get_cm_data_fns <- function () { data_fns <- grep ("^cm\\_data\\_", pkg_fns, value = TRUE) data_fns [which (!grepl ("\\_internal$", data_fns))] } + +all_cm_data_fns_memoised <- function (data_fns, path) { + is_memoised <- vapply (data_fns, function (i) { + tryCatch ( + memoise::has_cache (get (i)) (path), + error = function (e) FALSE + ) + }, logical (1L)) + + length (which (is_memoised)) > (length (data_fns) / 2) +} diff --git a/codemeta.json b/codemeta.json index a36a79a..04b1bef 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.1.073", + "version": "0.1.1.074", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From 30857d2181dd48b0b10a5bee6c73528b05943a6c Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 25 Nov 2024 14:48:34 +0100 Subject: [PATCH 6/8] fix bug in prs_from_gh_api for #23 --- DESCRIPTION | 2 +- R/cm-data-gh-prs.R | 2 +- codemeta.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4fcb30e..86914c9 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: repometrics Title: Metrics for Your Code Repository -Version: 0.1.1.074 +Version: 0.1.1.075 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/cm-data-gh-prs.R b/R/cm-data-gh-prs.R index d15158e..60c7e7b 100644 --- a/R/cm-data-gh-prs.R +++ b/R/cm-data-gh-prs.R @@ -158,7 +158,7 @@ cm_data_prs_from_gh_api_internal <- function (path, n_per_page = 30L) { reviews <- lapply (pr_data, function (i) { login <- vapply (i$reviews$nodes, function (j) j$author$login, character (1L)) state <- vapply (i$reviews$nodes, function (j) j$state, character (1L)) - submitted_at <- vapply (i$reviews$nodes, function (j) j$submittedAt, character (1L)) + submitted_at <- vapply (i$reviews$nodes, function (j) null2na_char (j$submittedAt), character (1L)) body <- vapply (i$reviews$nodes, function (j) j$body, character (1L)) data.frame ( login = login, diff --git a/codemeta.json b/codemeta.json index 04b1bef..4d99287 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.1.074", + "version": "0.1.1.075", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", From 84d82b9a39b3ac8bb970d1aa127d6e0009db2a09 Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 25 Nov 2024 14:52:27 +0100 Subject: [PATCH 7/8] mv 'git_log_in_period' -> cm-data-git.R for #23 --- DESCRIPTION | 2 +- R/chaoss-internal-change-req.R | 17 ++++++++++---- R/chaoss-internal-num-ctb.R | 19 ++++----------- R/chaoss-internal.R | 22 ------------------ R/cm-data-git.R | 23 +++++++++++++++++++ codemeta.json | 2 +- tests/testthat/test-chaoss-metrics-internal.R | 12 ---------- 7 files changed, 42 insertions(+), 55 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 86914c9..2baa590 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: repometrics Title: Metrics for Your Code Repository -Version: 0.1.1.075 +Version: 0.1.1.076 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/chaoss-internal-change-req.R b/R/chaoss-internal-change-req.R index a9b9e94..82de74a 100644 --- a/R/chaoss-internal-change-req.R +++ b/R/chaoss-internal-change-req.R @@ -15,9 +15,18 @@ chaoss_internal_change_req <- function (path, end_date = Sys.Date ()) { log <- git_log_in_period (path, end_date, get_repometrics_period ()) - res <- NA_integer_ - if (nrow (log) > 0L) { - res <- length (which (log$merge)) / nrow (log) - } + prs <- cm_data_prs_from_gh_api (path) + prs <- prs [which (prs$merged), ] + closed_dates <- as.Date (prs$closed_at) + start_date <- end_date - get_repometrics_period () + index <- which (closed_dates >= start_date & closed_dates <= end_date) + prs <- prs [index, ] + + num_commits <- vapply (prs$commit_oids, function (i) { + length (strsplit (i, ",") [[1]]) + }, integer (1L), USE.NAMES = FALSE) + + res <- sum (num_commits) / nrow (log) + return (res) } diff --git a/R/chaoss-internal-num-ctb.R b/R/chaoss-internal-num-ctb.R index 5e66566..510f9bd 100644 --- a/R/chaoss-internal-num-ctb.R +++ b/R/chaoss-internal-num-ctb.R @@ -2,16 +2,7 @@ chaoss_internal_num_contributors <- function (path, end_date = Sys.Date ()) { log <- git_log_in_period (path, end_date, get_repometrics_period ()) - auths_un <- unique (log$author) - - # separate handles from emails: - emails <- regmatches (auths_un, gregexpr ("<.*>", auths_un)) - emails <- vapply (emails, function (i) { - ifelse (length (i) == 0L, "", gsub ("<|>", "", i)) - }, character (1L)) - handles <- gsub ("<.*$", "", auths_un) - - # Remove any duplicates of either, but excluding non-entries: + # Remove any duplicates of either names or emails, but excluding non-entries: rm_dup_rows <- function (x) { x <- gsub ("\\s+", "", x) index <- seq_along (x) @@ -21,15 +12,13 @@ chaoss_internal_num_contributors <- function (path, end_date = Sys.Date ()) { } return (index) } - index1 <- rm_dup_rows (handles) - index2 <- rm_dup_rows (emails) + index1 <- rm_dup_rows (log$aut_name) + index2 <- rm_dup_rows (log$aut_email) # Then extract only instances where neither handles nor emails are # duplicated: index_table <- table (c (index1, index2)) index <- as.integer (names (index_table) [which (index_table == 2L)]) - auths_un <- auths_un [index] - - return (length (auths_un)) + return (length (index)) } diff --git a/R/chaoss-internal.R b/R/chaoss-internal.R index 54c5e07..74523c5 100644 --- a/R/chaoss-internal.R +++ b/R/chaoss-internal.R @@ -4,25 +4,3 @@ chaoss_internal_num_commits <- function (path, end_date = Sys.Date ()) { return (nrow (log)) } - -git_log_in_period_internal <- function (path, end_date = Sys.Date (), period = 90) { - checkmate::assert_character (path, len = 1L) - checkmate::assert_directory (path) - checkmate::assert_date (end_date) - - h <- gert::git_log (repo = path, max = 1e6) - if (nrow (h) == 0) { - return (h) - } - dates <- as.Date (h$time) - today_minus_period <- as.Date (end_date - period) - index <- which (dates >= today_minus_period) - h <- h [index, ] - - if (dates [1] > end_date) { - h <- h [which (dates <= end_date), ] - } - - return (h) -} -git_log_in_period <- memoise::memoise (git_log_in_period_internal) diff --git a/R/cm-data-git.R b/R/cm-data-git.R index c491f0e..8d7b956 100644 --- a/R/cm-data-git.R +++ b/R/cm-data-git.R @@ -50,3 +50,26 @@ cm_data_gitlog_internal <- function (path) { ) } cm_data_gitlog <- memoise::memoise (cm_data_gitlog_internal) + +git_log_in_period <- function (path, end_date = Sys.Date (), period = 90) { + + checkmate::assert_character (path, len = 1L) + checkmate::assert_directory (path) + checkmate::assert_date (end_date) + + log <- cm_data_gitlog (path) + + if (nrow (log) == 0) { + return (log) + } + dates <- as.Date (log$time) + today_minus_period <- as.Date (end_date - period) + index <- which (dates >= today_minus_period) + log <- log [index, ] + + if (dates [1] > end_date) { + log <- log [which (dates <= end_date), ] + } + + return (log) +} diff --git a/codemeta.json b/codemeta.json index 4d99287..ab3e0d7 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.1.075", + "version": "0.1.1.076", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/tests/testthat/test-chaoss-metrics-internal.R b/tests/testthat/test-chaoss-metrics-internal.R index 646bb96..bca9ac7 100644 --- a/tests/testthat/test-chaoss-metrics-internal.R +++ b/tests/testthat/test-chaoss-metrics-internal.R @@ -39,15 +39,3 @@ test_that ("chaoss has CI internal", { fs::dir_delete (path) }) - -test_that ("chaoss internal change requests", { - - path <- generate_test_pkg () - - x <- chaoss_internal_change_req (path, end_date = end_date) - expect_equal (x, 0) - x <- chaoss_internal_change_req (path, end_date = Sys.Date ()) - expect_equal (x, NA_integer_) # no commits, so NA returned - - fs::dir_delete (path) -}) From a3ad8dd96c7904420640019395e51622419b8b36 Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 25 Nov 2024 14:55:44 +0100 Subject: [PATCH 8/8] mv file 'cm-metrics-num-commits for #23 + rename fn 'cm_metrics_' --- DESCRIPTION | 2 +- R/{chaoss-internal.R => cm-metrics-num-commits.R} | 2 +- codemeta.json | 2 +- tests/testthat/test-chaoss-metrics-internal.R | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename R/{chaoss-internal.R => cm-metrics-num-commits.R} (58%) diff --git a/DESCRIPTION b/DESCRIPTION index 2baa590..ba15d4f 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: repometrics Title: Metrics for Your Code Repository -Version: 0.1.1.076 +Version: 0.1.1.077 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/R/chaoss-internal.R b/R/cm-metrics-num-commits.R similarity index 58% rename from R/chaoss-internal.R rename to R/cm-metrics-num-commits.R index 74523c5..1b66aaa 100644 --- a/R/chaoss-internal.R +++ b/R/cm-metrics-num-commits.R @@ -1,4 +1,4 @@ -chaoss_internal_num_commits <- function (path, end_date = Sys.Date ()) { +cm_metrics_num_commits <- function (path, end_date = Sys.Date ()) { log <- git_log_in_period (path, end_date, get_repometrics_period ()) diff --git a/codemeta.json b/codemeta.json index ab3e0d7..d5f8531 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.1.076", + "version": "0.1.1.077", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", diff --git a/tests/testthat/test-chaoss-metrics-internal.R b/tests/testthat/test-chaoss-metrics-internal.R index bca9ac7..b7df984 100644 --- a/tests/testthat/test-chaoss-metrics-internal.R +++ b/tests/testthat/test-chaoss-metrics-internal.R @@ -4,7 +4,7 @@ test_that ("chaoss internal num_commits", { path <- generate_test_pkg () - n <- chaoss_internal_num_commits (path, end_date = end_date) + n <- cm_metrics_num_commits (path, end_date = end_date) expect_equal (n, 4L) n <- chaoss_internal_num_contributors (path, end_date = end_date)