Skip to content

Commit 062c43e

Browse files
authored
Merge pull request #21 from ropensci-review-tools/change-req
change request chaoss metric for #11
2 parents 9df4156 + 476d4d7 commit 062c43e

10 files changed

+125
-89
lines changed

DESCRIPTION

+1-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.005
3+
Version: 0.1.1.009
44
Authors@R:
55
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-2172-5265"))
File renamed without changes.
File renamed without changes.

R/chaoss-internal-change-req.R

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#' From \url{https://chaoss.community/kb/metrics-model-collaboration-development-index/},
2+
#' the "Code Commit linked with Change Request" (which is not hyperlinked to
3+
#' anywhere else), is defined as "Percentage of new code commits linked with
4+
#' change request in last 90 days." The interpretation of "Change Request" is
5+
#' defined at \url{https://chaoss.community/kb/metric-change-requests/} as
6+
#' "proposals for modifications to a project's source code that have been
7+
#' submitted for review ... Examples include GitHub 'Pull Request', GitLab
8+
#' 'Merge Requests' and Gerrit 'code reviews'." These are here analysed as
9+
#' merge commits in the git log, even though these may not have been actual PRs
10+
#' on GitHub or similar, and may not have been reviewed.
11+
#'
12+
#' @return NA if no commits made in given period, otherwise the proportion of
13+
#' commits which came from merged branches.
14+
#' @noRd
15+
chaoss_internal_change_req <- function (path, end_date = Sys.Date ()) {
16+
17+
log <- git_log_in_period (path, end_date, get_repometrics_period ())
18+
res <- NA_integer_
19+
if (nrow (log) > 0L) {
20+
res <- length (which (log$merge)) / nrow (log)
21+
}
22+
return (res)
23+
}

R/chaoss-internal-ci.R

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#' Return names of CI services from corresponding configuration files contained
2+
#' in local repo.
3+
#' @noRd
4+
repo_has_ci_files <- function (path) {
5+
6+
flist <- fs::dir_ls (path, type = "file", all = TRUE, recurse = TRUE)
7+
ptns <- c (
8+
"\\.appveyor\\.yml",
9+
"\\.github\\/workflows",
10+
"\\.gitlab\\-ci\\.yml",
11+
"\\.circleci\\/config\\.yml",
12+
"codefresh\\.yml",
13+
"drone\\.yml",
14+
"\\.travis\\.yml"
15+
)
16+
has_it <- vapply (ptns, function (i) any (grepl (i, flist)), logical (1L))
17+
nms <- gsub ("\\\\.|\\\\.y.*$|\\\\/.*$|\\\\-.*$", "", ptns)
18+
19+
return (nms [which (has_it)])
20+
}

R/chaoss-internal-num-ctb.R

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
chaoss_internal_num_contributors <- function (path, end_date = Sys.Date ()) {
2+
3+
log <- git_log_in_period (path, end_date, get_repometrics_period ())
4+
5+
auths_un <- unique (log$author)
6+
7+
# separate handles from emails:
8+
emails <- regmatches (auths_un, gregexpr ("<.*>", auths_un))
9+
emails <- vapply (emails, function (i) {
10+
ifelse (length (i) == 0L, "", gsub ("<|>", "", i))
11+
}, character (1L))
12+
handles <- gsub ("<.*$", "", auths_un)
13+
14+
# Remove any duplicates of either, but excluding non-entries:
15+
rm_dup_rows <- function (x) {
16+
x <- gsub ("\\s+", "", x)
17+
index <- seq_along (x)
18+
index_out <- which (duplicated (x) & nzchar (x))
19+
if (length (index_out) > 0) {
20+
index <- index [-(index_out)]
21+
}
22+
return (index)
23+
}
24+
index1 <- rm_dup_rows (handles)
25+
index2 <- rm_dup_rows (emails)
26+
27+
# Then extract only instances where neither handles nor emails are
28+
# duplicated:
29+
index_table <- table (c (index1, index2))
30+
index <- as.integer (names (index_table) [which (index_table == 2L)])
31+
32+
auths_un <- auths_un [index]
33+
34+
return (length (auths_un))
35+
}

R/chaoss-internal.R

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
chaoss_internal_num_commits <- function (path, end_date = Sys.Date ()) {
2+
3+
log <- git_log_in_period (path, end_date, get_repometrics_period ())
4+
5+
return (nrow (log))
6+
}
7+
8+
git_log_in_period_internal <- function (path, end_date = Sys.Date (), period = 90) {
9+
checkmate::assert_character (path, len = 1L)
10+
checkmate::assert_directory (path)
11+
checkmate::assert_date (end_date)
12+
13+
h <- gert::git_log (repo = path, max = 1e6)
14+
if (nrow (h) == 0) {
15+
return (h)
16+
}
17+
dates <- as.Date (h$time)
18+
today_minus_period <- as.Date (end_date - period)
19+
index <- which (dates >= today_minus_period)
20+
h <- h [index, ]
21+
22+
if (dates [1] > end_date) {
23+
h <- h [which (dates <= end_date), ]
24+
}
25+
26+
return (h)
27+
}
28+
git_log_in_period <- memoise::memoise (git_log_in_period_internal)

R/chaoss-metrics-internal.R

-85
This file was deleted.

codemeta.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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.005",
11+
"version": "0.1.1.009",
1212
"programmingLanguage": {
1313
"@type": "ComputerLanguage",
1414
"name": "R",

tests/testthat/test-chaoss-metrics-internal.R

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
end_date <- as.Date ("2024-08-01")
2+
13
test_that ("chaoss internal num_commits", {
24
pkg <- system.file ("extdata", "testpkg.zip", package = "repometrics")
35
flist <- unzip (pkg, exdir = fs::path_temp ())
46
path <- fs::path_dir (flist [1])
57

6-
n <- chaoss_internal_num_commits (path, end_date = as.Date ("2024-08-01"))
8+
n <- chaoss_internal_num_commits (path, end_date = end_date)
79
expect_equal (n, 4L)
810

9-
n <- chaoss_internal_num_contributors (path, end_date = as.Date ("2024-08-01"))
11+
n <- chaoss_internal_num_contributors (path, end_date = end_date)
1012
expect_equal (n, 1L)
1113

1214
fs::dir_delete (path)
@@ -38,3 +40,16 @@ test_that ("chaoss has CI internal", {
3840

3941
fs::dir_delete (path)
4042
})
43+
44+
test_that ("chaoss internal change requests", {
45+
pkg <- system.file ("extdata", "testpkg.zip", package = "repometrics")
46+
flist <- unzip (pkg, exdir = fs::path_temp ())
47+
path <- fs::path_dir (flist [1])
48+
49+
x <- chaoss_internal_change_req (path, end_date = end_date)
50+
expect_equal (x, 0)
51+
x <- chaoss_internal_change_req (path, end_date = Sys.Date ())
52+
expect_equal (x, NA_integer_) # no commits, so NA returned
53+
54+
fs::dir_delete (path)
55+
})

0 commit comments

Comments
 (0)