Skip to content

Commit

Permalink
Merge branch 'main' into burstiness
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge authored Jan 26, 2025
2 parents 4015389 + 947edd1 commit ee839d5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
34 changes: 21 additions & 13 deletions R/cm-metrics-change-req.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
#' merge commits in the git log, even though these may not have been actual PRs
#' on GitHub or similar, and may not have been reviewed.
#'
#' @return NA if no commits made in given period, otherwise the proportion of
#' commits which came from merged branches.
#' @return A vector of three named numeric values, each measured over the
#' defined time period:
#' \enumerate{
#' \item n_opened = Number of change requests opened.
#' \item n_merged = Number of change requests merged.
#' \item prop_merged = Proportion of all change requests which were merged.
#' \item prop_code_from_prs = Proportion of all code committed by change
#' request.
#' }
#' @noRd
cm_metric_change_req <- function (path, end_date = Sys.Date ()) {

Expand All @@ -22,9 +29,19 @@ cm_metric_change_req <- function (path, end_date = Sys.Date ()) {

prs <- get_prs_in_period (path, end_date)

res <- sum (prs$num_commits) / nrow (log)
ret <- c (
n_opened = 0, n_closed = 0, prop_merged = 0, prop_code_from_prs = 0
)
if (nrow (prs) > 0L) {
ret <- c (
n_opened = nrow (prs),
n_closed = length (which (prs$merged)),
prop_merged = length (which (prs$merged)) / nrow (prs),
prop_code_from_prs = sum (prs$num_commits) / nrow (log)
)
}

return (res)
return (ret)
}

get_prs_in_period <- function (path, end_date = Sys.Date ()) {
Expand All @@ -38,12 +55,3 @@ get_prs_in_period <- function (path, end_date = Sys.Date ()) {

return (prs)
}

#' https://chaoss.community/kb/metric-change-requests-accepted/
#' @return Single integer counting number of merged PRs.
#' @noRd
cm_metric_change_req_accepted <- function (path, end_date = Sys.Date ()) {

prs <- get_prs_in_period (path, end_date)
length (which (prs$merged))
}
15 changes: 8 additions & 7 deletions tests/testthat/test-cm-metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,18 @@ test_that ("cm metric change reqests", { # R/cm-metrics-change-req.R
Sys.setenv ("REPOMETRICS_TESTS" = "true")
dat <- mock_rm_data ()
path <- generate_test_pkg ()
op <- getOption ("repometrics_period")
options ("repometrics_period" = 10000)

pr_dat <- cm_metric_change_req (path, end_date = end_date)
prs_accepted <- cm_metric_change_req_accepted (path, end_date = end_date)

options ("repometrics_period" = op)
fs::dir_delete (path)

expect_type (pr_dat, "double")
expect_length (pr_dat, 1L)
expect_equal (pr_dat, 0.)

expect_type (prs_accepted, "integer")
expect_length (prs_accepted, 1L)
expect_equal (prs_accepted, 0L)
expect_length (pr_dat, 4L)
expect_named (pr_dat, c ("n_opened", "n_closed", "prop_merged", "prop_code_from_prs"))
expect_true (all (pr_dat > 0))
})

test_that ("cm metric issues-to-prs", { # R/cm-metric-issues-to-prs.R
Expand Down

0 comments on commit ee839d5

Please sign in to comment.