Skip to content

Commit 832e1b8

Browse files
authored
Merge pull request #62 from ropensci-review-tools/network
bundle forcegraph.js definition in network.qmd for #59
2 parents 058b194 + d1b0466 commit 832e1b8

23 files changed

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

R/analyse-users.R

+7-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ user_relation_matrices <- function (user_data) {
4747
user_data [[n]] <- user_relate_fields (user_data, user_names, what = n)
4848
})
4949

50-
res <- dplyr::left_join (overlap [[1]], overlap [[2]], by = c ("login1", "login2")) |>
50+
res <- dplyr::left_join (
51+
overlap [[1]],
52+
overlap [[2]],
53+
by = c ("login1", "login2")
54+
) |>
5155
dplyr::left_join (overlap [[3]], by = c ("login1", "login2")) |>
5256
dplyr::left_join (overlap [[4]], by = c ("login1", "login2")) |>
5357
dplyr::left_join (overlap [[5]], by = c ("login1", "login2")) |>
@@ -108,7 +112,8 @@ user_relate_fields <- function (user_data, user_names, what = "commits") {
108112

109113
user_combs <- t (utils::combn (user_names, m = 2L))
110114
if (what == "commits") {
111-
user_data [[what]] <- dplyr::rename (user_data [[what]], n = num_commits)
115+
user_data [[what]] <-
116+
dplyr::rename (user_data [[what]], n = num_commits)
112117
} else if (what == "commit_cmt") {
113118
user_data$commit_cmt$n <- 1L
114119
}

R/cm-metric-issues-to-prs.R

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ cm_metric_issues_to_prs <- function (path, end_date = Sys.Date ()) {
1111
return (ret)
1212
}
1313

14-
get_issues_in_period <- function (path, end_date = Sys.Date (), closed_only = FALSE) {
14+
get_issues_in_period <- function (path,
15+
end_date = Sys.Date (),
16+
closed_only = FALSE) {
1517

1618
issues <- rm_data_issues_from_gh_api (path)
1719
closed_dates <- as.Date (issues$closed_at)

R/cm-metric-labels.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ cm_metric_label_inclusivity <- function (path, end_date = Sys.Date ()) {
3636

3737
if (length (labels) > 0) {
3838
friendly_ptn <- "newcomer|first\\s*issue|welcome|help"
39-
labels_newcomer_friendly <- grep (friendly_ptn, labels, value = TRUE, ignore.case = TRUE)
40-
prop_labelled_friendly <- length (labels_newcomer_friendly) / length (labels)
41-
prop_friendly_overall <- length (labels_newcomer_friendly) / nrow (issues_data)
39+
labels_newcomer_friendly <-
40+
grep (friendly_ptn, labels, value = TRUE, ignore.case = TRUE)
41+
prop_labelled_friendly <-
42+
length (labels_newcomer_friendly) / length (labels)
43+
prop_friendly_overall <-
44+
length (labels_newcomer_friendly) / nrow (issues_data)
4245
}
4346

4447
c (

R/cm-metrics-issue-response.R

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ cm_metric_issue_response_time <- function (path, end_date = Sys.Date ()) {
33
# suppress no visible warning notes:
44
user_login <- issue_number <- created_at <- response_date <- NULL
55

6-
ctbs_main_recent <- main_contributors (path, end_date = end_date, period = 365)
7-
ctbs_main_all <- main_contributors (path, end_date = end_date, period = NULL)
6+
ctbs_main_recent <-
7+
main_contributors (path, end_date = end_date, period = 365)
8+
ctbs_main_all <-
9+
main_contributors (path, end_date = end_date, period = NULL)
810
ctbs_main <- unique (c (ctbs_main_recent, ctbs_main_all))
911

1012
issues <- rm_data_issues_from_gh_api (path)
@@ -17,7 +19,8 @@ cm_metric_issue_response_time <- function (path, end_date = Sys.Date ()) {
1719
response_date = as.Date (dplyr::first (created_at))
1820
) |>
1921
dplyr::rename (number = issue_number)
20-
issue_responses <- dplyr::left_join (issues, cmt_responses, by = "number") |>
22+
issue_responses <-
23+
dplyr::left_join (issues, cmt_responses, by = "number") |>
2124
dplyr::mutate (created_at = as.Date (created_at)) |>
2225
dplyr::mutate (
2326
response_time = difftime (response_date, created_at, units = "days")
@@ -31,14 +34,16 @@ cm_metric_issue_response_time <- function (path, end_date = Sys.Date ()) {
3134
if (length (index) > 0L) {
3235
ret <- c (
3336
mean = mean (as.numeric (issue_responses$response_time [index])),
34-
median = stats::median (as.numeric (issue_responses$response_time [index]))
37+
median = stats::median (
38+
as.numeric (issue_responses$response_time [index])
39+
)
3540
)
3641
}
3742

3843
return (ret)
3944
}
4045

41-
cm_metric_defect_resolution_dur <- function (path, end_date = Sys.Date ()) {
46+
cm_metric_defect_resolution_dur <- function (path, end_date = Sys.Date ()) { # nolint
4247

4348
issues <- rm_data_issues_from_gh_api (path)
4449
index <- grep ("bug|defect|fix", issues$label, ignore.case = TRUE)
@@ -53,7 +58,8 @@ cm_metric_defect_resolution_dur <- function (path, end_date = Sys.Date ()) {
5358

5459
bugs$created_at <- as.Date (bugs$created_at)
5560
bugs$closed_at <- as.Date (bugs$closed_at)
56-
bugs$resolution_dur <- difftime (bugs$closed_at, bugs$created_at, units = "days")
61+
bugs$resolution_dur <-
62+
difftime (bugs$closed_at, bugs$created_at, units = "days")
5763
bugs$resolution_dur <- as.numeric (bugs$resolution_dur)
5864
start_date <- end_date - get_repometrics_period ()
5965
index <- which (bugs$created_at >= start_date & bugs$closed_at <= end_date)

R/cm-metrics-pr-reviews.R

+6-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ cm_metric_pr_reviews <- function (path, end_date = Sys.Date ()) {
2929
prs$review_decision [which (is.na (prs$review_decision))] <- "NA"
3030

3131
index_approved <- which (prs$review_decision == "APPROVED")
32-
index_rejected <- which (prs$review_decision != "APPROVED" & !prs$merged & prs$closed)
32+
index_rejected <-
33+
which (prs$review_decision != "APPROVED" & !prs$merged & prs$closed)
3334
index_other <- which (prs$review_decision != "APPROVED" & prs$merged)
3435
index_open <- which (!prs$merged)
3536

@@ -67,8 +68,10 @@ cm_metric_pr_reviews <- function (path, end_date = Sys.Date ()) {
6768
n_commenters_per_approved <- mean_to_na (num_commenters [index_approved])
6869
n_commenters_per_rejected <- mean_to_na (num_commenters [index_rejected])
6970
n_commenters_per_other <- mean_to_na (num_commenters [index_other])
70-
n_iterations_per_approved <- mean_to_na (num_comment_iterations [index_approved])
71-
n_iterations_per_rejected <- mean_to_na (num_comment_iterations [index_rejected])
71+
n_iterations_per_approved <-
72+
mean_to_na (num_comment_iterations [index_approved])
73+
n_iterations_per_rejected <-
74+
mean_to_na (num_comment_iterations [index_rejected])
7275
n_iterations_per_other <- mean_to_na (num_comment_iterations [index_other])
7376

7477
ret <- data.frame (

R/data-dependencies.R

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ rm_data_dependencies <- function (path) {
3333
#'
3434
#' Note that this all works even for packages which aren't on CRAN.
3535
#' @noRd
36-
rm_data_dependencies_downstream <- function (path) {
36+
rm_data_dependencies_downstream <- function (path) { # nolint
3737

3838
cran_db <- cran_pkg_db ()
3939
pkg_name <- pkg_name_from_path (path)
4040
i <- which (cran_db$Package == pkg_name)
4141
revdep_cols <- grep ("reverse", names (cran_db), ignore.case = TRUE)
4242
revdeps <- unname (do.call (c, cran_db [i, revdep_cols]))
43-
revdeps <- unlist (lapply (revdeps, function (i) strsplit (i, ",\\s*") [[1]]))
43+
revdeps <-
44+
unlist (lapply (revdeps, function (i) strsplit (i, ",\\s*") [[1]]))
4445
revdeps <- revdeps [which (!is.na (revdeps))]
4546
if (is.null (revdeps)) {
4647
revdeps <- character (0L)

R/data-gh-contribs.R

+7-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rm_data_contribs_from_log <- function (path) {
4040
#' @param n_per_page Not used here, but needed so all functions can safely be
4141
#' called with this parameter.
4242
#' @noRd
43-
rm_data_contribs_from_gh_api_internal <- function (path, n_per_page = 100L) {
43+
rm_data_contribs_from_gh_api_internal <- function (path, n_per_page = 100L) { # nolint
4444

4545
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
4646
n_per_page <- n_per_page_in_tests (n_per_page)
@@ -125,7 +125,10 @@ user_from_gh_api <- function (user) {
125125
)
126126
}
127127

128-
main_contributors <- function (path, end_date = Sys.Date (), threshold = 0.9, period = NULL) {
128+
main_contributors <- function (path,
129+
end_date = Sys.Date (),
130+
threshold = 0.9,
131+
period = NULL) {
129132

130133
# suppress no visible warning notes:
131134
login <- n <- NULL
@@ -152,7 +155,8 @@ main_contributors <- function (path, end_date = Sys.Date (), threshold = 0.9, pe
152155

153156
index <- which (log_contribs$sum <= threshold)
154157
# Then include the next entry as well, if it exists, because for example
155-
# with only two entries the first may be skipped if it's below the threshold.
158+
# with only two entries the first may be skipped if it's below the
159+
# threshold.
156160
index <- c (index, length (index) + 1L)
157161

158162
return (log_contribs$login [index])

R/data-gh-issues.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
rm_data_issues_from_gh_api_internal <- function (path, n_per_page = 100) {
1+
rm_data_issues_from_gh_api_internal <- function (path, n_per_page = 100) { # nolint
22

33
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
44
n_per_page <- n_per_page_in_tests (n_per_page)
@@ -95,7 +95,7 @@ get_issue_reactions <- function (body) {
9595
return (reaction_counts)
9696
}
9797

98-
rm_data_issue_comments_from_gh_api_internal <- function (path,
98+
rm_data_issue_comments_from_gh_api_internal <- function (path, # nolint
9999
n_per_page = 100) {
100100

101101
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
@@ -148,5 +148,5 @@ rm_data_issue_comments_from_gh_api_internal <- function (path,
148148
issue_body = issue_body
149149
)
150150
}
151-
rm_data_issue_comments_from_gh_api <-
151+
rm_data_issue_comments_from_gh_api <- # nolint
152152
memoise::memoise (rm_data_issue_comments_from_gh_api_internal)

R/data-gh-prs.R

+7-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ gh_prs_qry <- function (org = "ropensci-review-tools",
108108
return (q)
109109
}
110110

111-
rm_data_prs_from_gh_api_internal <- function (path, n_per_page = 30L) {
111+
rm_data_prs_from_gh_api_internal <- function (path, n_per_page = 30L) { # nolint
112112

113113
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
114114
n_per_page <- n_per_page_in_tests (n_per_page)
@@ -197,7 +197,12 @@ rm_data_prs_from_gh_api_internal <- function (path, n_per_page = 30L) {
197197

198198
num_comments <- i$totalCommentsCount
199199

200-
lens <- c (length (login), length (state), length (created_at), length (submitted_at))
200+
lens <- c (
201+
length (login),
202+
length (state),
203+
length (created_at),
204+
length (submitted_at)
205+
)
201206
has_content <- any (lens > 0L) | num_comments > 0L
202207

203208
if (has_content) {

R/data-gh-releases.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
rm_data_releases_from_gh_api_internal <- function (path,
1+
rm_data_releases_from_gh_api_internal <- function (path, # nolint
22
n_per_page = 100L,
33
latest_only = FALSE) {
44

R/data-gh-repo.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' @param path Local path to repository
44
#' @noRd
5-
rm_data_repo_from_gh_api_internal <- function (path) {
5+
rm_data_repo_from_gh_api_internal <- function (path) { # nolint
66

77
or <- org_repo_from_path (path)
88

R/data-gh-stargazers.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ gh_stargazers_qry <- function (org = "ropensci-review-tools",
3030
return (q)
3131
}
3232

33-
rm_data_repo_stargazers_internal <- function (path, n_per_page = 100L) {
33+
rm_data_repo_stargazers_internal <- function (path, n_per_page = 100L) { # nolint
3434

3535
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
3636
n_per_page <- n_per_page_in_tests (n_per_page)

R/data-gh-user.R

+26-7
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ gh_user_general_internal <- function (login = "",
5959
bio = null2na_char (user$bio),
6060
avatarUrl = null2na_char (user$avatarUrl),
6161
num_repositories = null2na_int (user$repositories$totalCount),
62-
repos_contributed_to = null2na_int (user$repositoriesContributedTo$totalCount),
62+
repos_contributed_to =
63+
null2na_int (user$repositoriesContributedTo$totalCount),
6364
num_starred_repos = null2na_int (user$starredRepositories$totalCount)
6465
)
6566

@@ -238,11 +239,19 @@ gh_user_commit_cmt_internal <- function (login,
238239
)
239240
repourl <- c (
240241
repourl,
241-
vapply (nodes, function (i) i$repository$nameWithOwner, character (1L))
242+
vapply (
243+
nodes,
244+
function (i) i$repository$nameWithOwner,
245+
character (1L)
246+
)
242247
)
243248
repo_stargazers <- c (
244249
repo_stargazers,
245-
vapply (nodes, function (i) i$repository$stargazerCount, integer (1L))
250+
vapply (
251+
nodes,
252+
function (i) i$repository$stargazerCount,
253+
integer (1L)
254+
)
246255
)
247256

248257
has_next_page <- dat$data$user$commitComments$pageInfo$hasNextPage
@@ -359,12 +368,20 @@ gh_user_commits_internal <- function (login,
359368
)
360369

361370
dates_i <- lapply (commits, function (i) {
362-
vapply (i$contributions$nodes, function (j) j$occurredAt, character (1L))
371+
vapply (
372+
i$contributions$nodes,
373+
function (j) j$occurredAt,
374+
character (1L)
375+
)
363376
})
364377
n_i <- vapply (dates_i, length, integer (1L))
365378
dates <- c (dates, unlist (dates_i))
366379
commit_count_i <- lapply (commits, function (i) {
367-
vapply (i$contributions$nodes, function (j) j$commitCount, integer (1L))
380+
vapply (
381+
i$contributions$nodes,
382+
function (j) j$commitCount,
383+
integer (1L)
384+
)
368385
})
369386
num_commits <- c (num_commits, unlist (commit_count_i))
370387

@@ -478,7 +495,8 @@ gh_user_issues_internal <- function (login,
478495
n_per_page <- n_per_page_in_tests (n_per_page)
479496

480497
created_at <- closed_at <- org_repo <- issue_num <- end_cursor <-
481-
num_issue_comments <- num_issue_participants <- num_repo_languages <- NULL
498+
num_issue_comments <- num_issue_participants <-
499+
num_repo_languages <- NULL
482500
repo_languages <- list ()
483501
total_issue_contribs <- 0L
484502
has_next_page <- TRUE
@@ -638,7 +656,8 @@ gh_user_issue_cmts_internal <- function (login,
638656
num_comments <- num_participants <- NULL
639657
has_next_page <- TRUE
640658

641-
start_timestamp <- format (Sys.time () - 60 * 60 * 24 * 365 * nyears, "%Y-%m-%dT%H:%M:%S")
659+
start_timestamp <-
660+
format (Sys.time () - 60 * 60 * 24 * 365 * nyears, "%Y-%m-%dT%H:%M:%S")
642661
start_timestamp <- as.POSIXct (start_timestamp)
643662

644663
while (has_next_page) {

R/data-gh-workflow.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#' Retrieve latest GitHub workflow results from Rest API
22
#'
33
#' @noRd
4-
rm_data_gh_repo_workflow_internal <- function (path, n_per_page = 30L) {
4+
rm_data_gh_repo_workflow_internal <- function (path, n_per_page = 30L) { # nolint
55

66
n_per_page <- n_per_page_in_tests (n_per_page)
77
or <- org_repo_from_path (path)

R/data-pkgstats.R

+10-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ extract_pkgstats_data_single <- function (log, path) {
8181
}
8282

8383
res <- pbapply::pblapply (seq_len (nrow (log)), function (i) {
84-
flist <- reset_repo (path_cp, log$hash [i])
84+
flist <- reset_repo (path_cp, log$hash [i]) # nolint
8585
run_one_pkgstats (path = path_cp, pkg_date = log$timestamp [i])
8686
})
8787

@@ -102,7 +102,7 @@ extract_pkgstats_data_multi <- function (log, path, num_cores) {
102102
)
103103
res <- pbapply::pblapply (seq_len (nrow (log)), function (i) {
104104
path_cp <- fs::dir_copy (path, fs::path_temp ())
105-
flist <- reset_repo (path_cp, log$hash [i])
105+
flist <- reset_repo (path_cp, log$hash [i]) # nolint
106106
s <- run_one_pkgstats (path = path_cp, pkg_date = log$timestamp [i])
107107
fs::dir_delete (path_cp)
108108
return (s)
@@ -116,7 +116,7 @@ extract_pkgstats_data_multi <- function (log, path, num_cores) {
116116

117117
reset_repo <- function (path, hash) {
118118

119-
g <- gert::git_reset_hard (ref = hash, repo = path)
119+
g <- gert::git_reset_hard (ref = hash, repo = path) # nolint
120120
flist <- fs::dir_ls (path, recurse = TRUE, type = "file")
121121
# Reduce to paths relative to 'path' itself:
122122
flist <- fs::path_rel (flist, path)
@@ -148,10 +148,15 @@ run_one_pkgstats <- function (path, pkg_date) {
148148
!is.na (s$objects$npars)
149149
)
150150
# Empty results do not contain all columns:
151-
nms <- c ("fn_name", "language", "loc", "npars", "has_dots", "exported", "num_doclines")
151+
nms <- c (
152+
"fn_name", "language", "loc", "npars",
153+
"has_dots", "exported", "num_doclines"
154+
)
155+
152156
nms <- nms [which (nms %in% names (s$objects))]
153157
fns <- s$objects [index, ] |> dplyr::select (dplyr::all_of (nms))
154-
doclines <- mn_med_sum (fns$num_doclines [which (!is.na (fns$num_doclines))])
158+
doclines <-
159+
mn_med_sum (fns$num_doclines [which (!is.na (fns$num_doclines))])
155160
npars <- mn_med_sum (fns$npars)
156161
loc <- mn_med_sum (fns$loc)
157162

0 commit comments

Comments
 (0)