Skip to content

Commit 29215a7

Browse files
authored
Merge pull request #34 from ropensci-review-tools/tests
restructure tests for #23
2 parents 9f2985f + 8a55be2 commit 29215a7

24 files changed

+935
-691
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.090
3+
Version: 0.1.1.100
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

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#' Extract package dependencies from "DESCRIPTION" file.
22
#'
33
#' @param path Local path to repository
4-
#' @param n_per_page Not used here, but needed so all functions can safely be
5-
#' called with this parameter.
64
#' @noRd
7-
cm_data_dependencies <- function (path, n_per_page = 30L) {
5+
cm_data_dependencies <- function (path) {
86

97
desc_path <- fs::dir_ls (path, type = "file", regexp = "DESCRIPTION$")
108
checkmate::assert_file_exists (desc_path)
@@ -33,10 +31,8 @@ cm_data_dependencies <- function (path, n_per_page = 30L) {
3331
#' Extract CHAOSS "libyears" metric
3432
#'
3533
#' @param path Local path to repository
36-
#' @param n_per_page Not used here, but needed so all functions can safely be
37-
#' called with this parameter.
3834
#' @noRd
39-
cm_data_libyears <- function (path, n_per_page = 30L) {
35+
cm_data_libyears <- function (path) {
4036

4137
deps <- cm_data_dependencies (path)
4238
cran_db <- data.frame (cran_pkg_db ())

R/cm-data-gh-contribs.R

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#' Get contributors from the git log
22
#'
33
#' @param path Local path to repository
4-
#' @param n_per_page Not used here, but needed so all functions can safely be
5-
#' called with this parameter.
64
#' @noRd
7-
cm_data_contribs_from_log <- function (path, n_per_page = 30L) {
5+
cm_data_contribs_from_log <- function (path) {
86

97
log <- cm_data_gitlog (path)
108

@@ -45,6 +43,7 @@ cm_data_contribs_from_log <- function (path, n_per_page = 30L) {
4543
cm_data_contribs_from_gh_api_internal <- function (path, n_per_page = 100L) {
4644

4745
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
46+
n_per_page <- n_per_page_in_tests (n_per_page)
4847

4948
u_endpoint <- gh_rest_api_endpoint (path = path, endpoint = "contributors")
5049

R/cm-data-gh-issues.R

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cm_data_issues_from_gh_api_internal <- function (path, n_per_page = 100) {
22

33
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
4+
n_per_page <- n_per_page_in_tests (n_per_page)
45

56
u_endpoint <- gh_rest_api_endpoint (path = path, endpoint = "issues")
67

@@ -35,7 +36,8 @@ cm_data_issues_from_gh_api_internal <- function (path, n_per_page = 100) {
3536
user_login = vapply (body, function (i) i$user$login, character (1L)),
3637
user_id = vapply (body, function (i) i$user$id, integer (1L)),
3738
labels = vapply (body, function (i) {
38-
these_labels <- vapply (i$labels, function (j) j$name, character (1L))
39+
these_labels <-
40+
vapply (i$labels, function (j) j$name, character (1L))
3941
paste0 (these_labels, collapse = ", ")
4042
}, character (1L)),
4143
state = vapply (body, function (i) i$state, character (1L)),
@@ -52,7 +54,11 @@ cm_data_issues_from_gh_api_internal <- function (path, n_per_page = 100) {
5254
function (i) null2na_char (i$closed_at),
5355
character (1L)
5456
),
55-
issue_body = vapply (body, function (i) null2na_char (i$body), character (1L)),
57+
issue_body = vapply (
58+
body,
59+
function (i) null2na_char (i$body),
60+
character (1L)
61+
),
5662
closed_by = vapply (
5763
body,
5864
function (i) null2na_char (i$closed_by$login),
@@ -89,9 +95,11 @@ get_issue_reactions <- function (body) {
8995
return (reaction_counts)
9096
}
9197

92-
cm_data_issue_comments_from_gh_api_internal <- function (path, n_per_page = 100) {
98+
cm_data_issue_comments_from_gh_api_internal <- function (path,
99+
n_per_page = 100) {
93100

94101
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
102+
n_per_page <- n_per_page_in_tests (n_per_page)
95103

96104
u_endpoint <-
97105
gh_rest_api_endpoint (path = path, endpoint = "issues/comments")

R/cm-data-gh-prs.R

+62-12
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ gh_prs_qry <- function (org = "ropensci-review-tools",
110110
cm_data_prs_from_gh_api_internal <- function (path, n_per_page = 30L) {
111111

112112
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
113+
n_per_page <- n_per_page_in_tests (n_per_page)
113114

114115
or <- org_repo_from_path (path)
115116
end_cursor <- pr_data <- NULL
@@ -150,8 +151,16 @@ cm_data_prs_from_gh_api_internal <- function (path, n_per_page = 30L) {
150151
paste0 (p, collapse = ",")
151152
}, character (1L))
152153
comments <- lapply (pr_data, function (i) {
153-
created_at <- vapply (i$comments$nodes, function (j) j$createdAt, character (1L))
154-
author <- vapply (i$comments$nodes, function (j) j$author$login, character (1L))
154+
created_at <- vapply (
155+
i$comments$nodes,
156+
function (j) j$createdAt,
157+
character (1L)
158+
)
159+
author <- vapply (
160+
i$comments$nodes,
161+
function (j) j$author$login,
162+
character (1L)
163+
)
155164
body <- vapply (i$comments$nodes, function (j) j$body, character (1L))
156165
data.frame (
157166
author = author,
@@ -160,12 +169,24 @@ cm_data_prs_from_gh_api_internal <- function (path, n_per_page = 30L) {
160169
)
161170
})
162171
closing_issue_refs <- lapply (pr_data, function (i) {
163-
vapply (i$closingIssuesReferences$nodes, function (j) j$number, integer (1L))
172+
vapply (
173+
i$closingIssuesReferences$nodes,
174+
function (j) j$number,
175+
integer (1L)
176+
)
164177
})
165178
reviews <- lapply (pr_data, function (i) {
166-
login <- vapply (i$reviews$nodes, function (j) j$author$login, character (1L))
179+
login <- vapply (
180+
i$reviews$nodes,
181+
function (j) j$author$login,
182+
character (1L)
183+
)
167184
state <- vapply (i$reviews$nodes, function (j) j$state, character (1L))
168-
submitted_at <- vapply (i$reviews$nodes, function (j) null2na_char (j$submittedAt), character (1L))
185+
submitted_at <- vapply (
186+
i$reviews$nodes,
187+
function (j) null2na_char (j$submittedAt),
188+
character (1L)
189+
)
169190
body <- vapply (i$reviews$nodes, function (j) j$body, character (1L))
170191
data.frame (
171192
login = login,
@@ -175,26 +196,55 @@ cm_data_prs_from_gh_api_internal <- function (path, n_per_page = 30L) {
175196
)
176197
})
177198

199+
# A few extra pro-processing ones just to avoid long lines:
200+
user_login <- vapply (pr_data, function (i) i$author$login, character (1L))
201+
merged_by <- vapply (
202+
pr_data,
203+
function (i) null2na_char (i$mergedBy$login),
204+
character (1L)
205+
)
206+
merge_commit <- vapply (
207+
pr_data,
208+
function (i) null2na_char (i$mergeCommit$oid),
209+
character (1L)
210+
)
211+
review_decision <- vapply (
212+
pr_data,
213+
function (i) null2na_char (i$reviewDecision),
214+
character (1L)
215+
)
216+
closed_at <- vapply (
217+
pr_data,
218+
function (i) null2na_char (i$closedAt),
219+
character (1L)
220+
)
221+
changed_files <- vapply (pr_data, function (i) i$changedFiles, integer (1L))
222+
total_comments <- vapply (
223+
pr_data,
224+
function (i) i$totalCommentsCount,
225+
integer (1L)
226+
)
227+
178228
data.frame (
179229
number = vapply (pr_data, function (i) i$number, integer (1L)),
180-
user_login = vapply (pr_data, function (i) i$author$login, character (1L)),
230+
user_login = user_login,
181231
state = vapply (pr_data, function (i) i$state, character (1L)),
182232
merged = vapply (pr_data, function (i) i$merged, logical (1L)),
183-
merged_by = vapply (pr_data, function (i) null2na_char (i$mergedBy$login), character (1L)),
184-
merge_commit = vapply (pr_data, function (i) null2na_char (i$mergeCommit$oid), character (1L)),
233+
merged_by = merged_by,
234+
merge_commit = merge_commit,
185235
closed = vapply (pr_data, function (i) i$closed, logical (1L)),
186236
title = vapply (pr_data, function (i) i$title, character (1L)),
187-
review_decision = vapply (pr_data, function (i) null2na_char (i$reviewDecision), character (1L)),
237+
review_decision = review_decision,
188238
created_at = vapply (pr_data, function (i) i$createdAt, character (1L)),
189-
closed_at = vapply (pr_data, function (i) null2na_char (i$closedAt), character (1L)),
239+
closed_at = closed_at,
190240
updated_at = vapply (pr_data, function (i) i$updatedAt, character (1L)),
191241
num_commits = num_commits,
192242
additions = vapply (pr_data, function (i) i$additions, integer (1L)),
193243
deletions = vapply (pr_data, function (i) i$deletions, integer (1L)),
194-
changed_files = vapply (pr_data, function (i) i$changedFiles, integer (1L)),
244+
changed_files = changed_files,
195245
commit_oids = commit_oids,
196246
closing_issue_refs = I (closing_issue_refs),
197-
total_comments = vapply (pr_data, function (i) i$totalCommentsCount, integer (1L)),
247+
total_comments = total_comments,
198248
participants = participants,
199249
body = vapply (pr_data, function (i) i$body, character (1L)),
200250
comments = I (comments),

R/cm-data-gh-releases.R

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
cm_data_releases_from_gh_api_internal <- function (path, n_per_page = 100L, latest_only = FALSE) {
1+
cm_data_releases_from_gh_api_internal <- function (path,
2+
n_per_page = 100L,
3+
latest_only = FALSE) {
24

35
checkmate::assert_integerish (n_per_page)
46
checkmate::assert_logical (latest_only)
@@ -37,15 +39,19 @@ cm_data_releases_from_gh_api_internal <- function (path, n_per_page = 100L, late
3739

3840
data.frame (
3941
id = vapply (body, function (i) i$id, integer (1L)),
40-
author_login = vapply (body, function (i) i$author$login, character (1L)),
42+
author_login =
43+
vapply (body, function (i) i$author$login, character (1L)),
4144
author_id = vapply (body, function (i) i$author$id, integer (1L)),
4245
tag_name = vapply (body, function (i) i$tag_name, character (1L)),
43-
target_commitish = vapply (body, function (i) i$target_commitish, character (1L)),
46+
target_commitish =
47+
vapply (body, function (i) i$target_commitish, character (1L)),
4448
name = vapply (body, function (i) i$name, character (1L)),
4549
draft = vapply (body, function (i) i$draft, logical (1L)),
4650
prerelease = vapply (body, function (i) i$prerelease, logical (1L)),
4751
created_at = vapply (body, function (i) i$created_at, character (1L)),
48-
published_at = vapply (body, function (i) i$published_at, character (1L))
52+
published_at =
53+
vapply (body, function (i) i$published_at, character (1L))
4954
)
5055
}
51-
cm_data_releases_from_gh_api <- memoise::memoise (cm_data_releases_from_gh_api_internal)
56+
cm_data_releases_from_gh_api <-
57+
memoise::memoise (cm_data_releases_from_gh_api_internal)

R/cm-data-gh-repo.R

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#' Get repository data from GitHub API
22
#'
33
#' @param path Local path to repository
4-
#' @param n_per_page Not used here, but needed so all functions can safely be
5-
#' called with this parameter.
64
#' @noRd
7-
cm_data_repo_from_gh_api_internal <- function (path, n_per_page) {
5+
cm_data_repo_from_gh_api_internal <- function (path) {
86

97
or <- org_repo_from_path (path)
108

R/cm-data-gh-workflow.R

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#' @noRd
44
cm_data_gh_repo_workflow_internal <- function (path, n_per_page = 30L) {
55

6+
n_per_page <- n_per_page_in_tests (n_per_page)
67
or <- org_repo_from_path (path)
78

89
checkmate::assert_integer (n_per_page, lower = 1L)
@@ -31,7 +32,11 @@ cm_data_gh_repo_workflow_internal <- function (path, n_per_page = 30L) {
3132
function (i) null2na_char (i$status),
3233
character (1L)
3334
)
34-
conclusion <- vapply (workflows, function (i) null2na_char (i$conclusion), character (1L))
35+
conclusion <- vapply (
36+
workflows,
37+
function (i) null2na_char (i$conclusion),
38+
character (1L)
39+
)
3540
created <- vapply (workflows, function (i) i$created_at, character (1L))
3641
created <- to_posix (created)
3742

R/cm-data-git.R

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#' Get the full git log from local repository.
22
#'
33
#' @param path Local path to repository
4-
#' @param n_per_page Not used here, but needed so all functions can safely be
5-
#' called with this parameter.
64
#' @noRd
7-
cm_data_gitlog_internal <- function (path, n_per_page) {
5+
cm_data_gitlog_internal <- function (path) {
86

97
cmt <- git2r::commits (repo = path)
108

119
hash <- vapply (cmt, function (i) i$sha, character (1L))
1210
aut_name <- vapply (cmt, function (i) i$author$name, character (1L))
1311
aut_email <- vapply (cmt, function (i) i$author$email, character (1L))
14-
timestamp <- vapply (cmt, function (i) as.character (i$author$when), character (1L))
12+
timestamp <-
13+
vapply (cmt, function (i) as.character (i$author$when), character (1L))
1514
cmt_message <- vapply (cmt, function (i) i$message, character (1L))
1615
cmt_message <- gsub ("\\n$", "", cmt_message)
1716

@@ -29,7 +28,7 @@ cm_data_gitlog_internal <- function (path, n_per_page) {
2928
function (i) gert::git_diff (ref = i, repo = path)
3029
)
3130

32-
files_changed <- lapply (diffs, function (i) i$new)
31+
# files_changed <- lapply (diffs, function (i) i$new)
3332

3433
# bench::marking shows this form is quicker than either:
3534
# `length (grep ("^(\\-|\\+)$", j))` or

R/cm-data.R

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
cm_data <- function (path, n_per_page = 30L) {
1+
cm_data <- function (path) {
22

33
checkmate::assert_directory_exists (path)
4-
checkmate::assert_integerish (n_per_page, lower = 1L, len = 1L)
54

65
data_fns <- get_cm_data_fns ()
76

87
if (all_cm_data_fns_memoised (data_fns, path)) {
98
res <- lapply (data_fns, function (i) {
10-
do.call (i, list (path = path, n_per_page = n_per_page))
9+
do.call (i, list (path = path))
1110
})
1211
} else {
1312
res <- pbapply::pblapply (data_fns, function (i) {
14-
do.call (i, list (path = path, n_per_page = n_per_page))
13+
do.call (i, list (path = path))
1514
})
1615
}
1716
names (res) <- gsub ("^cm\\_data\\_", "", data_fns)

R/cm-metric-cran-downloads.R

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
#' Extract total CRAN downloads for nominated package over period defined by
22
#' `options("repometrics_period")`.
33
#'
4-
#' @param pkg_name Name of package. For packages not on CRAN, the 'cranlogs'
5-
#' API returns download counts of 0.
4+
#' @param path Local path to repository.
65
#' @param end_date The date up to which download counts are to be aggregated.
6+
#' @param n_per_page Not used here, but needed so all functions can safely be
7+
#' called with this parameter.
78
#' @return A single integer counting the number of downloads.
89
#' @noRd
9-
cm_metric_cran_downloads <- function (pkg_name, end_date = Sys.Date ()) {
10+
cm_metric_cran_downloads <- function (path,
11+
end_date = Sys.Date (),
12+
n_per_page) {
1013

11-
checkmate::assert_character (pkg_name, len = 1L)
14+
checkmate::assert_directory_exists (path)
1215
checkmate::assert_date (end_date)
16+
17+
pkg_name <- pkg_name_from_path (path)
18+
1319
period <- get_repometrics_period ()
1420
start_date <- as.Date (end_date - period)
1521
interval <- paste (start_date, sep = ":", end_date)

R/cm-metric-num-ctb.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ cm_metric_num_contributors <- function (path, end_date = Sys.Date ()) {
22

33
log <- git_log_in_period (path, end_date, get_repometrics_period ())
44

5-
# Remove any duplicates of either names or emails, but excluding non-entries:
5+
# Remove any duplicates of either names or emails, but excluding
6+
# non-entries:
67
rm_dup_rows <- function (x) {
78
x <- gsub ("\\s+", "", x)
89
index <- seq_along (x)

R/cm-metrics-change-req.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#' From \url{https://chaoss.community/kb/metrics-model-collaboration-development-index/},
1+
#' From
2+
#' \url{https://chaoss.community/kb/metrics-model-collaboration-development-index/},
23
#' the "Code Commit linked with Change Request" (which is not hyperlinked to
34
#' anywhere else), is defined as "Percentage of new code commits linked with
45
#' change request in last 90 days." The interpretation of "Change Request" is

0 commit comments

Comments
 (0)