Skip to content

Commit 3c2b739

Browse files
authored
Merge pull request #31 from ropensci-review-tools/libyears
libyears for #23
2 parents 00d7b99 + 768eb0f commit 3c2b739

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
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.065
3+
Version: 0.1.1.068
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-data-dependencies.R

+18
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,21 @@ cm_data_dependencies <- function (path) {
2323

2424
data.frame (do.call (rbind, deps))
2525
}
26+
27+
cm_data_libyears <- function (path) {
28+
29+
deps <- cm_data_dependencies (path)
30+
cran_db <- data.frame (tools::CRAN_package_db ())
31+
index <- match (deps$name, cran_db$Package)
32+
deps$cran_version <- cran_db$Version [index]
33+
deps$published <- as.Date (cran_db$Published [index])
34+
deps <- deps [which (!is.na (deps$published)), ]
35+
36+
rel <- releases_from_gh_api (path, latest_only = TRUE)
37+
rel_date <- as.Date (strftime (rel$published_at, format = "%Y-%m-%d"))
38+
39+
dt <- difftime (deps$published, rel_date, units = "days")
40+
dt <- as.numeric (dt) / 365.25 # In years
41+
42+
c (mean = mean (dt), median = stats::median (dt))
43+
}

R/cm-data-gh-releases.R

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
releases_from_gh_api <- function (path, n_per_page = 100L) {
1+
releases_from_gh_api <- function (path, n_per_page = 100L, latest_only = FALSE) {
2+
3+
checkmate::assert_integerish (n_per_page)
4+
checkmate::assert_logical (latest_only)
5+
6+
if (latest_only) {
7+
n_per_page <- 1L
8+
}
29

310
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
411

@@ -19,7 +26,7 @@ releases_from_gh_api <- function (path, n_per_page = 100L) {
1926
body <- c (body, httr2::resp_body_json (resp))
2027

2128
next_page <- gh_next_page (resp)
22-
if (is_test_env) {
29+
if (is_test_env || latest_only) {
2330
next_page <- NULL
2431
}
2532

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

tests/testthat/test-cm-data-git.R

+17
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,20 @@ test_that ("cm data dependencies", {
4242
expect_type (deps [[n]], "character")
4343
}
4444
})
45+
46+
skip_on_cran ()
47+
48+
test_that ("cm data libyears", {
49+
50+
path <- generate_test_pkg ()
51+
libyears <- with_mock_dir ("gh_libyears", {
52+
cm_data_libyears (path)
53+
})
54+
fs::dir_delete (path)
55+
56+
expect_type (libyears, "double")
57+
expect_length (libyears, 2L)
58+
expect_named (libyears)
59+
expect_equal (names (libyears), c ("mean", "median"))
60+
expect_true (all (libyears > 0))
61+
})

0 commit comments

Comments
 (0)