Skip to content

Commit 563ab18

Browse files
authored
Merge pull request #36 from ropensci-review-tools/issues-to-prs
issues to prs for #11
2 parents 7d49a45 + 20ae2aa commit 563ab18

5 files changed

+48
-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.104
3+
Version: 0.1.1.108
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-issues-to-prs.R

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cm_metric_issues_to_prs <- function (path, end_date = Sys.Date ()) {
2+
3+
prs <- get_prs_in_period (path, end_date) # in cm-metrics-change-req.R
4+
issues <- get_issues_in_period (path, end_date)
5+
6+
ret <- 1
7+
if (nrow (prs) > 0) {
8+
ret <- nrow (issues) / nrow (prs)
9+
}
10+
11+
return (ret)
12+
}
13+
14+
get_issues_in_period <- function (path, end_date = Sys.Date ()) {
15+
16+
issues <- cm_data_issues_from_gh_api (path)
17+
created_dates <- as.Date (issues$created_at)
18+
closed_dates <- as.Date (issues$closed_at)
19+
start_date <- end_date - get_repometrics_period ()
20+
index <- which (created_dates >= start_date & closed_dates <= end_date)
21+
22+
return (issues [index, ])
23+
}

R/cm-metrics-change-req.R

+10-3
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@ cm_metric_change_req <- function (path, end_date = Sys.Date ()) {
2020
return (0)
2121
}
2222

23+
prs <- get_prs_in_period (path, end_date)
24+
25+
res <- sum (prs$num_commits) / nrow (log)
26+
27+
return (res)
28+
}
29+
30+
get_prs_in_period <- function (path, end_date = Sys.Date ()) {
31+
2332
prs <- cm_data_prs_from_gh_api (path)
2433
prs <- prs [which (prs$merged), ]
2534
closed_dates <- as.Date (prs$closed_at)
2635
start_date <- end_date - get_repometrics_period ()
2736
index <- which (closed_dates >= start_date & closed_dates <= end_date)
2837
prs <- prs [index, ]
2938

30-
res <- sum (prs$num_commits) / nrow (log)
31-
32-
return (res)
39+
return (prs)
3340
}

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

tests/testthat/test-cm-metrics.R

+13
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,16 @@ test_that ("cm metrics change req frequency", {
9595
expect_length (dat, 1L)
9696
expect_equal (dat, 0.)
9797
})
98+
99+
test_that ("cm metrics issues-to-prs", {
100+
101+
Sys.setenv ("REPOMETRICS_TESTS" = "true")
102+
mock_cm_data ()
103+
path <- generate_test_pkg ()
104+
x <- cm_metric_issues_to_prs (path, end_date = end_date)
105+
fs::dir_delete (path)
106+
107+
expect_type (x, "double")
108+
expect_length (x, 1L)
109+
expect_true (x > 0)
110+
})

0 commit comments

Comments
 (0)