Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bundle forcegraph.js definition in network.qmd for #59 #62

Merged
merged 18 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: repometrics
Title: Metrics for Your Code Repository
Version: 0.1.3.044
Version: 0.1.3.060
Authors@R:
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
9 changes: 7 additions & 2 deletions R/analyse-users.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ user_relation_matrices <- function (user_data) {
user_data [[n]] <- user_relate_fields (user_data, user_names, what = n)
})

res <- dplyr::left_join (overlap [[1]], overlap [[2]], by = c ("login1", "login2")) |>
res <- dplyr::left_join (
overlap [[1]],
overlap [[2]],
by = c ("login1", "login2")
) |>
dplyr::left_join (overlap [[3]], by = c ("login1", "login2")) |>
dplyr::left_join (overlap [[4]], by = c ("login1", "login2")) |>
dplyr::left_join (overlap [[5]], by = c ("login1", "login2")) |>
Expand Down Expand Up @@ -108,7 +112,8 @@ user_relate_fields <- function (user_data, user_names, what = "commits") {

user_combs <- t (utils::combn (user_names, m = 2L))
if (what == "commits") {
user_data [[what]] <- dplyr::rename (user_data [[what]], n = num_commits)
user_data [[what]] <-
dplyr::rename (user_data [[what]], n = num_commits)
} else if (what == "commit_cmt") {
user_data$commit_cmt$n <- 1L
}
Expand Down
4 changes: 3 additions & 1 deletion R/cm-metric-issues-to-prs.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ cm_metric_issues_to_prs <- function (path, end_date = Sys.Date ()) {
return (ret)
}

get_issues_in_period <- function (path, end_date = Sys.Date (), closed_only = FALSE) {
get_issues_in_period <- function (path,
end_date = Sys.Date (),
closed_only = FALSE) {

issues <- rm_data_issues_from_gh_api (path)
closed_dates <- as.Date (issues$closed_at)
Expand Down
9 changes: 6 additions & 3 deletions R/cm-metric-labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ cm_metric_label_inclusivity <- function (path, end_date = Sys.Date ()) {

if (length (labels) > 0) {
friendly_ptn <- "newcomer|first\\s*issue|welcome|help"
labels_newcomer_friendly <- grep (friendly_ptn, labels, value = TRUE, ignore.case = TRUE)
prop_labelled_friendly <- length (labels_newcomer_friendly) / length (labels)
prop_friendly_overall <- length (labels_newcomer_friendly) / nrow (issues_data)
labels_newcomer_friendly <-
grep (friendly_ptn, labels, value = TRUE, ignore.case = TRUE)
prop_labelled_friendly <-
length (labels_newcomer_friendly) / length (labels)
prop_friendly_overall <-
length (labels_newcomer_friendly) / nrow (issues_data)
}

c (
Expand Down
18 changes: 12 additions & 6 deletions R/cm-metrics-issue-response.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ cm_metric_issue_response_time <- function (path, end_date = Sys.Date ()) {
# suppress no visible warning notes:
user_login <- issue_number <- created_at <- response_date <- NULL

ctbs_main_recent <- main_contributors (path, end_date = end_date, period = 365)
ctbs_main_all <- main_contributors (path, end_date = end_date, period = NULL)
ctbs_main_recent <-
main_contributors (path, end_date = end_date, period = 365)
ctbs_main_all <-
main_contributors (path, end_date = end_date, period = NULL)
ctbs_main <- unique (c (ctbs_main_recent, ctbs_main_all))

issues <- rm_data_issues_from_gh_api (path)
Expand All @@ -17,7 +19,8 @@ cm_metric_issue_response_time <- function (path, end_date = Sys.Date ()) {
response_date = as.Date (dplyr::first (created_at))
) |>
dplyr::rename (number = issue_number)
issue_responses <- dplyr::left_join (issues, cmt_responses, by = "number") |>
issue_responses <-
dplyr::left_join (issues, cmt_responses, by = "number") |>
dplyr::mutate (created_at = as.Date (created_at)) |>
dplyr::mutate (
response_time = difftime (response_date, created_at, units = "days")
Expand All @@ -31,14 +34,16 @@ cm_metric_issue_response_time <- function (path, end_date = Sys.Date ()) {
if (length (index) > 0L) {
ret <- c (
mean = mean (as.numeric (issue_responses$response_time [index])),
median = stats::median (as.numeric (issue_responses$response_time [index]))
median = stats::median (
as.numeric (issue_responses$response_time [index])
)
)
}

return (ret)
}

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

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

bugs$created_at <- as.Date (bugs$created_at)
bugs$closed_at <- as.Date (bugs$closed_at)
bugs$resolution_dur <- difftime (bugs$closed_at, bugs$created_at, units = "days")
bugs$resolution_dur <-
difftime (bugs$closed_at, bugs$created_at, units = "days")
bugs$resolution_dur <- as.numeric (bugs$resolution_dur)
start_date <- end_date - get_repometrics_period ()
index <- which (bugs$created_at >= start_date & bugs$closed_at <= end_date)
Expand Down
9 changes: 6 additions & 3 deletions R/cm-metrics-pr-reviews.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ cm_metric_pr_reviews <- function (path, end_date = Sys.Date ()) {
prs$review_decision [which (is.na (prs$review_decision))] <- "NA"

index_approved <- which (prs$review_decision == "APPROVED")
index_rejected <- which (prs$review_decision != "APPROVED" & !prs$merged & prs$closed)
index_rejected <-
which (prs$review_decision != "APPROVED" & !prs$merged & prs$closed)
index_other <- which (prs$review_decision != "APPROVED" & prs$merged)
index_open <- which (!prs$merged)

Expand Down Expand Up @@ -67,8 +68,10 @@ cm_metric_pr_reviews <- function (path, end_date = Sys.Date ()) {
n_commenters_per_approved <- mean_to_na (num_commenters [index_approved])
n_commenters_per_rejected <- mean_to_na (num_commenters [index_rejected])
n_commenters_per_other <- mean_to_na (num_commenters [index_other])
n_iterations_per_approved <- mean_to_na (num_comment_iterations [index_approved])
n_iterations_per_rejected <- mean_to_na (num_comment_iterations [index_rejected])
n_iterations_per_approved <-
mean_to_na (num_comment_iterations [index_approved])
n_iterations_per_rejected <-
mean_to_na (num_comment_iterations [index_rejected])
n_iterations_per_other <- mean_to_na (num_comment_iterations [index_other])

ret <- data.frame (
Expand Down
5 changes: 3 additions & 2 deletions R/data-dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ rm_data_dependencies <- function (path) {
#'
#' Note that this all works even for packages which aren't on CRAN.
#' @noRd
rm_data_dependencies_downstream <- function (path) {
rm_data_dependencies_downstream <- function (path) { # nolint

cran_db <- cran_pkg_db ()
pkg_name <- pkg_name_from_path (path)
i <- which (cran_db$Package == pkg_name)
revdep_cols <- grep ("reverse", names (cran_db), ignore.case = TRUE)
revdeps <- unname (do.call (c, cran_db [i, revdep_cols]))
revdeps <- unlist (lapply (revdeps, function (i) strsplit (i, ",\\s*") [[1]]))
revdeps <-
unlist (lapply (revdeps, function (i) strsplit (i, ",\\s*") [[1]]))
revdeps <- revdeps [which (!is.na (revdeps))]
if (is.null (revdeps)) {
revdeps <- character (0L)
Expand Down
10 changes: 7 additions & 3 deletions R/data-gh-contribs.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ rm_data_contribs_from_log <- function (path) {
#' @param n_per_page Not used here, but needed so all functions can safely be
#' called with this parameter.
#' @noRd
rm_data_contribs_from_gh_api_internal <- function (path, n_per_page = 100L) {
rm_data_contribs_from_gh_api_internal <- function (path, n_per_page = 100L) { # nolint

is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
n_per_page <- n_per_page_in_tests (n_per_page)
Expand Down Expand Up @@ -125,7 +125,10 @@ user_from_gh_api <- function (user) {
)
}

main_contributors <- function (path, end_date = Sys.Date (), threshold = 0.9, period = NULL) {
main_contributors <- function (path,
end_date = Sys.Date (),
threshold = 0.9,
period = NULL) {

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

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

return (log_contribs$login [index])
Expand Down
6 changes: 3 additions & 3 deletions R/data-gh-issues.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rm_data_issues_from_gh_api_internal <- function (path, n_per_page = 100) {
rm_data_issues_from_gh_api_internal <- function (path, n_per_page = 100) { # nolint

is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
n_per_page <- n_per_page_in_tests (n_per_page)
Expand Down Expand Up @@ -95,7 +95,7 @@ get_issue_reactions <- function (body) {
return (reaction_counts)
}

rm_data_issue_comments_from_gh_api_internal <- function (path,
rm_data_issue_comments_from_gh_api_internal <- function (path, # nolint
n_per_page = 100) {

is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
Expand Down Expand Up @@ -148,5 +148,5 @@ rm_data_issue_comments_from_gh_api_internal <- function (path,
issue_body = issue_body
)
}
rm_data_issue_comments_from_gh_api <-
rm_data_issue_comments_from_gh_api <- # nolint
memoise::memoise (rm_data_issue_comments_from_gh_api_internal)
9 changes: 7 additions & 2 deletions R/data-gh-prs.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ gh_prs_qry <- function (org = "ropensci-review-tools",
return (q)
}

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

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

num_comments <- i$totalCommentsCount

lens <- c (length (login), length (state), length (created_at), length (submitted_at))
lens <- c (
length (login),
length (state),
length (created_at),
length (submitted_at)
)
has_content <- any (lens > 0L) | num_comments > 0L

if (has_content) {
Expand Down
2 changes: 1 addition & 1 deletion R/data-gh-releases.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rm_data_releases_from_gh_api_internal <- function (path,
rm_data_releases_from_gh_api_internal <- function (path, # nolint
n_per_page = 100L,
latest_only = FALSE) {

Expand Down
2 changes: 1 addition & 1 deletion R/data-gh-repo.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' @param path Local path to repository
#' @noRd
rm_data_repo_from_gh_api_internal <- function (path) {
rm_data_repo_from_gh_api_internal <- function (path) { # nolint

or <- org_repo_from_path (path)

Expand Down
2 changes: 1 addition & 1 deletion R/data-gh-stargazers.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ gh_stargazers_qry <- function (org = "ropensci-review-tools",
return (q)
}

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

is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
n_per_page <- n_per_page_in_tests (n_per_page)
Expand Down
33 changes: 26 additions & 7 deletions R/data-gh-user.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ gh_user_general_internal <- function (login = "",
bio = null2na_char (user$bio),
avatarUrl = null2na_char (user$avatarUrl),
num_repositories = null2na_int (user$repositories$totalCount),
repos_contributed_to = null2na_int (user$repositoriesContributedTo$totalCount),
repos_contributed_to =
null2na_int (user$repositoriesContributedTo$totalCount),
num_starred_repos = null2na_int (user$starredRepositories$totalCount)
)

Expand Down Expand Up @@ -238,11 +239,19 @@ gh_user_commit_cmt_internal <- function (login,
)
repourl <- c (
repourl,
vapply (nodes, function (i) i$repository$nameWithOwner, character (1L))
vapply (
nodes,
function (i) i$repository$nameWithOwner,
character (1L)
)
)
repo_stargazers <- c (
repo_stargazers,
vapply (nodes, function (i) i$repository$stargazerCount, integer (1L))
vapply (
nodes,
function (i) i$repository$stargazerCount,
integer (1L)
)
)

has_next_page <- dat$data$user$commitComments$pageInfo$hasNextPage
Expand Down Expand Up @@ -359,12 +368,20 @@ gh_user_commits_internal <- function (login,
)

dates_i <- lapply (commits, function (i) {
vapply (i$contributions$nodes, function (j) j$occurredAt, character (1L))
vapply (
i$contributions$nodes,
function (j) j$occurredAt,
character (1L)
)
})
n_i <- vapply (dates_i, length, integer (1L))
dates <- c (dates, unlist (dates_i))
commit_count_i <- lapply (commits, function (i) {
vapply (i$contributions$nodes, function (j) j$commitCount, integer (1L))
vapply (
i$contributions$nodes,
function (j) j$commitCount,
integer (1L)
)
})
num_commits <- c (num_commits, unlist (commit_count_i))

Expand Down Expand Up @@ -478,7 +495,8 @@ gh_user_issues_internal <- function (login,
n_per_page <- n_per_page_in_tests (n_per_page)

created_at <- closed_at <- org_repo <- issue_num <- end_cursor <-
num_issue_comments <- num_issue_participants <- num_repo_languages <- NULL
num_issue_comments <- num_issue_participants <-
num_repo_languages <- NULL
repo_languages <- list ()
total_issue_contribs <- 0L
has_next_page <- TRUE
Expand Down Expand Up @@ -638,7 +656,8 @@ gh_user_issue_cmts_internal <- function (login,
num_comments <- num_participants <- NULL
has_next_page <- TRUE

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

while (has_next_page) {
Expand Down
2 changes: 1 addition & 1 deletion R/data-gh-workflow.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Retrieve latest GitHub workflow results from Rest API
#'
#' @noRd
rm_data_gh_repo_workflow_internal <- function (path, n_per_page = 30L) {
rm_data_gh_repo_workflow_internal <- function (path, n_per_page = 30L) { # nolint

n_per_page <- n_per_page_in_tests (n_per_page)
or <- org_repo_from_path (path)
Expand Down
15 changes: 10 additions & 5 deletions R/data-pkgstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ extract_pkgstats_data_single <- function (log, path) {
}

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

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

reset_repo <- function (path, hash) {

g <- gert::git_reset_hard (ref = hash, repo = path)
g <- gert::git_reset_hard (ref = hash, repo = path) # nolint
flist <- fs::dir_ls (path, recurse = TRUE, type = "file")
# Reduce to paths relative to 'path' itself:
flist <- fs::path_rel (flist, path)
Expand Down Expand Up @@ -148,10 +148,15 @@ run_one_pkgstats <- function (path, pkg_date) {
!is.na (s$objects$npars)
)
# Empty results do not contain all columns:
nms <- c ("fn_name", "language", "loc", "npars", "has_dots", "exported", "num_doclines")
nms <- c (
"fn_name", "language", "loc", "npars",
"has_dots", "exported", "num_doclines"
)

nms <- nms [which (nms %in% names (s$objects))]
fns <- s$objects [index, ] |> dplyr::select (dplyr::all_of (nms))
doclines <- mn_med_sum (fns$num_doclines [which (!is.na (fns$num_doclines))])
doclines <-
mn_med_sum (fns$num_doclines [which (!is.na (fns$num_doclines))])
npars <- mn_med_sum (fns$npars)
loc <- mn_med_sum (fns$loc)

Expand Down
Loading