Skip to content

Commit b8d959a

Browse files
authored
Merge pull request #39 from ropensci-review-tools/code-change
add 'cm_metric_code_change_lines' for #11
2 parents 49d0803 + a5ff6cd commit b8d959a

File tree

4 files changed

+35
-2
lines changed

4 files changed

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

R/cm-metric-code-change.R

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cm_metric_code_change_lines <- function (path,
2+
end_date = Sys.Date (),
3+
exclude_whitespace = TRUE) {
4+
5+
log <- git_log_in_period (path, end_date)
6+
7+
changes <- sum (log$lines_added) + sum (log$lines_removed)
8+
ws <- sum (log$whitespace_added) + sum (log$whitespace_removed)
9+
if (!exclude_whitespace) {
10+
ws <- 0L
11+
}
12+
13+
return (changes - ws)
14+
}

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.114",
11+
"version": "0.1.1.115",
1212
"programmingLanguage": {
1313
"@type": "ComputerLanguage",
1414
"name": "R",

tests/testthat/test-cm-metrics.R

+19
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,22 @@ test_that ("cm metrics num forks", {
145145
expect_equal (names (forks), c ("num_in_period", "num_total"))
146146
expect_true (forks [["num_total"]] > 0)
147147
})
148+
149+
test_that ("cm metrics code change lines", {
150+
151+
path <- generate_test_pkg ()
152+
x1 <- cm_metric_code_change_lines (path, end_date = end_date)
153+
x2 <- cm_metric_code_change_lines (
154+
path,
155+
end_date = end_date,
156+
exclude_whitespace = FALSE
157+
)
158+
fs::dir_delete (path)
159+
160+
for (i in c (x1, x2)) {
161+
expect_type (i, "integer")
162+
expect_length (i, 1L)
163+
expect_true (i > 0)
164+
}
165+
expect_true (x2 > x1)
166+
})

0 commit comments

Comments
 (0)