diff --git a/DESCRIPTION b/DESCRIPTION index f605866..eea8950 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: repometrics Title: Metrics for Your Code Repository -Version: 0.1.1.018 +Version: 0.1.1.026 Authors@R: person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) @@ -16,6 +16,7 @@ Imports: dplyr, fs, gert, + git2r, httr2, memoise, pbapply, diff --git a/R/chaoss-external.R b/R/chaoss-external.R index 8a77d93..2f0a6ea 100644 --- a/R/chaoss-external.R +++ b/R/chaoss-external.R @@ -39,6 +39,7 @@ has_gh_ci_tests <- function (path) { #' is defined as, "Percentage of new code commits linked with change requests #' in the last 90 days." #' \url{https://chaoss.community/kb/metrics-model-collaboration-development-index/}. +#' @noRd prop_commits_in_change_req <- function (path, end_date = Sys.Date ()) { or <- org_repo_from_path (path) diff --git a/R/cm-data-git.R b/R/cm-data-git.R new file mode 100644 index 0000000..c491f0e --- /dev/null +++ b/R/cm-data-git.R @@ -0,0 +1,52 @@ +cm_data_gitlog_internal <- function (path) { + + cmt <- git2r::commits (repo = path) + + hash <- vapply (cmt, function (i) i$sha, character (1L)) + aut_name <- vapply (cmt, function (i) i$author$name, character (1L)) + aut_email <- vapply (cmt, function (i) i$author$email, character (1L)) + timestamp <- vapply (cmt, function (i) as.character (i$author$when), character (1L)) + cmt_message <- vapply (cmt, function (i) i$message, character (1L)) + cmt_message <- gsub ("\\n$", "", cmt_message) + + stats <- lapply ( + hash, + function (i) gert::git_commit_stats (ref = i, repo = path) + ) + + lines_added <- vapply (stats, function (i) i$insertions, integer (1L)) + lines_removed <- vapply (stats, function (i) i$deletions, integer (1L)) + nfiles_changed <- vapply (stats, function (i) i$files, integer (1L)) + + diffs <- lapply ( + hash, + function (i) gert::git_diff (ref = i, repo = path) + ) + + files_changed <- lapply (diffs, function (i) i$new) + + # bench::marking shows this form is quicker than either: + # `length (grep ("^(\\-|\\+)$", j))` or + # `length (which (j %in% c ("-", "+")))`. + whitespace <- vapply (diffs, function (i) { + patch_i <- suppressWarnings (strsplit (i$patch, "\\n")) + res <- vapply (patch_i, function (j) { + c (length (which (j == "+")), length (which (j == "-"))) + }, integer (2L)) + as.integer (rowSums (res)) + }, integer (2L)) + + data.frame ( + hash = hash, + aut_name = aut_name, + aut_email = aut_email, + timestamp = as.POSIXct (timestamp), + message = cmt_message, + nfiles_changed = nfiles_changed, + lines_added = lines_added, + lines_removed = lines_removed, + whitespace_added = whitespace [1, ], + whitespace_removed = whitespace [2, ] + ) +} +cm_data_gitlog <- memoise::memoise (cm_data_gitlog_internal) diff --git a/codemeta.json b/codemeta.json index 0572622..afd0744 100644 --- a/codemeta.json +++ b/codemeta.json @@ -8,13 +8,13 @@ "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.018", + "version": "0.1.1.026", "programmingLanguage": { "@type": "ComputerLanguage", "name": "R", "url": "https://r-project.org" }, - "runtimePlatform": "R version 4.4.1 (2024-06-14)", + "runtimePlatform": "R version 4.4.2 (2024-10-31)", "author": [ { "@type": "Person", @@ -182,6 +182,18 @@ "sameAs": "https://CRAN.R-project.org/package=gert" }, "6": { + "@type": "SoftwareApplication", + "identifier": "git2r", + "name": "git2r", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=git2r" + }, + "7": { "@type": "SoftwareApplication", "identifier": "httr2", "name": "httr2", @@ -193,7 +205,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=httr2" }, - "7": { + "8": { "@type": "SoftwareApplication", "identifier": "memoise", "name": "memoise", @@ -205,7 +217,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=memoise" }, - "8": { + "9": { "@type": "SoftwareApplication", "identifier": "pbapply", "name": "pbapply", @@ -217,7 +229,7 @@ }, "sameAs": "https://CRAN.R-project.org/package=pbapply" }, - "9": { + "10": { "@type": "SoftwareApplication", "identifier": "pkgstats", "name": "pkgstats", @@ -225,7 +237,7 @@ }, "SystemRequirements": {} }, - "fileSize": "125.292KB", + "fileSize": "142.573KB", "readme": "https://github.com/ropensci-review-tools/repometrics/blob/main/README.md", "contIntegration": [ "https://github.com/ropensci-review-tools/repometrics/actions?query=workflow%3AR-CMD-check", diff --git a/tests/testthat/test-cm-data.R b/tests/testthat/test-cm-data.R new file mode 100644 index 0000000..8363811 --- /dev/null +++ b/tests/testthat/test-cm-data.R @@ -0,0 +1,30 @@ +test_that ("cm data git", { + + pkg <- system.file ("extdata", "testpkg.zip", package = "repometrics") + flist <- unzip (pkg, exdir = fs::path_temp ()) + path <- fs::path_dir (flist [1]) + + log <- cm_data_gitlog (path) + + expect_s3_class (log, "data.frame") + expect_equal (ncol (log), 10L) + nms <- c ( + "hash", "aut_name", "aut_email", "timestamp", "message", + "nfiles_changed", "lines_added", "lines_removed", "whitespace_added", + "whitespace_removed" + ) + expect_equal (names (log), nms) + + char_nms <- nms [c (1:3, 5)] + int_nms <- nms [6:10] + for (n in names (log)) { + type <- ifelse (n %in% char_nms, "character", "integer") + if (n == "timestamp") { + expect_s3_class (log [[n]], "POSIXct") + } else { + expect_type (log [[n]], type) + } + } + + fs::dir_delete (path) +})