Skip to content

Commit e57fea1

Browse files
authored
Merge pull request #24 from ropensci-review-tools/chaoss-data
chaoss data for #23
2 parents aaef55b + f0fd5ca commit e57fea1

File tree

5 files changed

+103
-7
lines changed

5 files changed

+103
-7
lines changed

DESCRIPTION

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: repometrics
22
Title: Metrics for Your Code Repository
3-
Version: 0.1.1.018
3+
Version: 0.1.1.026
44
Authors@R:
55
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-2172-5265"))
@@ -16,6 +16,7 @@ Imports:
1616
dplyr,
1717
fs,
1818
gert,
19+
git2r,
1920
httr2,
2021
memoise,
2122
pbapply,

R/chaoss-external.R

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ has_gh_ci_tests <- function (path) {
3939
#' is defined as, "Percentage of new code commits linked with change requests
4040
#' in the last 90 days."
4141
#' \url{https://chaoss.community/kb/metrics-model-collaboration-development-index/}.
42+
#' @noRd
4243
prop_commits_in_change_req <- function (path, end_date = Sys.Date ()) {
4344

4445
or <- org_repo_from_path (path)

R/cm-data-git.R

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
cm_data_gitlog_internal <- function (path) {
2+
3+
cmt <- git2r::commits (repo = path)
4+
5+
hash <- vapply (cmt, function (i) i$sha, character (1L))
6+
aut_name <- vapply (cmt, function (i) i$author$name, character (1L))
7+
aut_email <- vapply (cmt, function (i) i$author$email, character (1L))
8+
timestamp <- vapply (cmt, function (i) as.character (i$author$when), character (1L))
9+
cmt_message <- vapply (cmt, function (i) i$message, character (1L))
10+
cmt_message <- gsub ("\\n$", "", cmt_message)
11+
12+
stats <- lapply (
13+
hash,
14+
function (i) gert::git_commit_stats (ref = i, repo = path)
15+
)
16+
17+
lines_added <- vapply (stats, function (i) i$insertions, integer (1L))
18+
lines_removed <- vapply (stats, function (i) i$deletions, integer (1L))
19+
nfiles_changed <- vapply (stats, function (i) i$files, integer (1L))
20+
21+
diffs <- lapply (
22+
hash,
23+
function (i) gert::git_diff (ref = i, repo = path)
24+
)
25+
26+
files_changed <- lapply (diffs, function (i) i$new)
27+
28+
# bench::marking shows this form is quicker than either:
29+
# `length (grep ("^(\\-|\\+)$", j))` or
30+
# `length (which (j %in% c ("-", "+")))`.
31+
whitespace <- vapply (diffs, function (i) {
32+
patch_i <- suppressWarnings (strsplit (i$patch, "\\n"))
33+
res <- vapply (patch_i, function (j) {
34+
c (length (which (j == "+")), length (which (j == "-")))
35+
}, integer (2L))
36+
as.integer (rowSums (res))
37+
}, integer (2L))
38+
39+
data.frame (
40+
hash = hash,
41+
aut_name = aut_name,
42+
aut_email = aut_email,
43+
timestamp = as.POSIXct (timestamp),
44+
message = cmt_message,
45+
nfiles_changed = nfiles_changed,
46+
lines_added = lines_added,
47+
lines_removed = lines_removed,
48+
whitespace_added = whitespace [1, ],
49+
whitespace_removed = whitespace [2, ]
50+
)
51+
}
52+
cm_data_gitlog <- memoise::memoise (cm_data_gitlog_internal)

codemeta.json

+18-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"codeRepository": "https://github.com/ropensci-review-tools/repometrics",
99
"issueTracker": "https://github.com/ropensci-review-tools/repometrics/issues",
1010
"license": "https://spdx.org/licenses/GPL-3.0",
11-
"version": "0.1.1.018",
11+
"version": "0.1.1.026",
1212
"programmingLanguage": {
1313
"@type": "ComputerLanguage",
1414
"name": "R",
1515
"url": "https://r-project.org"
1616
},
17-
"runtimePlatform": "R version 4.4.1 (2024-06-14)",
17+
"runtimePlatform": "R version 4.4.2 (2024-10-31)",
1818
"author": [
1919
{
2020
"@type": "Person",
@@ -182,6 +182,18 @@
182182
"sameAs": "https://CRAN.R-project.org/package=gert"
183183
},
184184
"6": {
185+
"@type": "SoftwareApplication",
186+
"identifier": "git2r",
187+
"name": "git2r",
188+
"provider": {
189+
"@id": "https://cran.r-project.org",
190+
"@type": "Organization",
191+
"name": "Comprehensive R Archive Network (CRAN)",
192+
"url": "https://cran.r-project.org"
193+
},
194+
"sameAs": "https://CRAN.R-project.org/package=git2r"
195+
},
196+
"7": {
185197
"@type": "SoftwareApplication",
186198
"identifier": "httr2",
187199
"name": "httr2",
@@ -193,7 +205,7 @@
193205
},
194206
"sameAs": "https://CRAN.R-project.org/package=httr2"
195207
},
196-
"7": {
208+
"8": {
197209
"@type": "SoftwareApplication",
198210
"identifier": "memoise",
199211
"name": "memoise",
@@ -205,7 +217,7 @@
205217
},
206218
"sameAs": "https://CRAN.R-project.org/package=memoise"
207219
},
208-
"8": {
220+
"9": {
209221
"@type": "SoftwareApplication",
210222
"identifier": "pbapply",
211223
"name": "pbapply",
@@ -217,15 +229,15 @@
217229
},
218230
"sameAs": "https://CRAN.R-project.org/package=pbapply"
219231
},
220-
"9": {
232+
"10": {
221233
"@type": "SoftwareApplication",
222234
"identifier": "pkgstats",
223235
"name": "pkgstats",
224236
"sameAs": "https://github.com/ropensci-review-tools/pkgstats"
225237
},
226238
"SystemRequirements": {}
227239
},
228-
"fileSize": "125.292KB",
240+
"fileSize": "142.573KB",
229241
"readme": "https://github.com/ropensci-review-tools/repometrics/blob/main/README.md",
230242
"contIntegration": [
231243
"https://github.com/ropensci-review-tools/repometrics/actions?query=workflow%3AR-CMD-check",

tests/testthat/test-cm-data.R

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
test_that ("cm data git", {
2+
3+
pkg <- system.file ("extdata", "testpkg.zip", package = "repometrics")
4+
flist <- unzip (pkg, exdir = fs::path_temp ())
5+
path <- fs::path_dir (flist [1])
6+
7+
log <- cm_data_gitlog (path)
8+
9+
expect_s3_class (log, "data.frame")
10+
expect_equal (ncol (log), 10L)
11+
nms <- c (
12+
"hash", "aut_name", "aut_email", "timestamp", "message",
13+
"nfiles_changed", "lines_added", "lines_removed", "whitespace_added",
14+
"whitespace_removed"
15+
)
16+
expect_equal (names (log), nms)
17+
18+
char_nms <- nms [c (1:3, 5)]
19+
int_nms <- nms [6:10]
20+
for (n in names (log)) {
21+
type <- ifelse (n %in% char_nms, "character", "integer")
22+
if (n == "timestamp") {
23+
expect_s3_class (log [[n]], "POSIXct")
24+
} else {
25+
expect_type (log [[n]], type)
26+
}
27+
}
28+
29+
fs::dir_delete (path)
30+
})

0 commit comments

Comments
 (0)