Skip to content

Commit 5fafdcd

Browse files
committed
add test for change-requests metric #11
1 parent c7a6f5b commit 5fafdcd

4 files changed

+27
-5
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.007
3+
Version: 0.1.1.008
44
Authors@R:
55
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-2172-5265"))

R/chaoss-metrics-internal-change-req.R

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88
#' 'Merge Requests' and Gerrit 'code reviews'." These are here analysed as
99
#' merge commits in the git log, even though these may not have been actual PRs
1010
#' 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.
1114
#' noRd
1215
chaoss_internal_change_req <- function (path, end_date = Sys.Date ()) {
1316

1417
log <- git_log_in_period (path, end_date, get_repometrics_period ())
15-
length (which (log$merge)) / nrow (log)
18+
res <- NA_integer_
19+
if (nrow (log) > 0L) {
20+
res <- length (which (log$merge)) / nrow (log)
21+
}
22+
return (res)
1623
}

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.007",
11+
"version": "0.1.1.008",
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)