Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chaoss data for #23 #24

Merged
merged 8 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand All @@ -16,6 +16,7 @@ Imports:
dplyr,
fs,
gert,
git2r,
httr2,
memoise,
pbapply,
Expand Down
1 change: 1 addition & 0 deletions R/chaoss-external.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
52 changes: 52 additions & 0 deletions R/cm-data-git.R
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 18 additions & 6 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -193,7 +205,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=httr2"
},
"7": {
"8": {
"@type": "SoftwareApplication",
"identifier": "memoise",
"name": "memoise",
Expand All @@ -205,7 +217,7 @@
},
"sameAs": "https://CRAN.R-project.org/package=memoise"
},
"8": {
"9": {
"@type": "SoftwareApplication",
"identifier": "pbapply",
"name": "pbapply",
Expand All @@ -217,15 +229,15 @@
},
"sameAs": "https://CRAN.R-project.org/package=pbapply"
},
"9": {
"10": {
"@type": "SoftwareApplication",
"identifier": "pkgstats",
"name": "pkgstats",
"sameAs": "https://github.com/ropensci-review-tools/pkgstats"
},
"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",
Expand Down
30 changes: 30 additions & 0 deletions tests/testthat/test-cm-data.R
Original file line number Diff line number Diff line change
@@ -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)
})