Skip to content

Commit b3a70d8

Browse files
authored
Merge pull request #53 from ropensci-review-tools/tidy
add cli output to main data fn
2 parents 169d970 + b43c32e commit b3a70d8

6 files changed

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

R/repometrics-data.R

+5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212
#' @export
1313
repometrics_data <- function (path, step_days = 1L, num_cores = -1L) {
1414

15+
cli::cli_alert_info ("Extracting package statistics ...")
1516
pkgstats <- repo_pkgstats_history (
1617
path,
1718
step_days = step_days,
1819
num_cores = num_cores
1920
)
21+
cli::cli_alert_success ("Done!")
22+
23+
cli::cli_alert_info ("Extracting GitHub data ...")
2024
cm <- cm_data (path)
2125
cm$contributors <- get_all_contribs (cm$contribs_from_log, cm$contribs_from_gh_api)
26+
cli::cli_alert_success ("Done!")
2227

2328
list (pkgstats = pkgstats, cm = cm)
2429
}

R/utils-path-pkg-manipulation.R

+17-5
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,26 @@ pkg_gh_url_from_path <- function (path) {
1111
checkmate::assert_file_exists (desc)
1212

1313
desc <- read.dcf (desc)
14-
ret <- NULL
15-
if ("URL" %in% colnames (desc)) {
16-
url <- strsplit (unname (desc [, "URL"]), "\\n|,") [[1]]
14+
url <- NULL
15+
strip_url <- function (url) {
16+
url <- strsplit (unname (url), "\\n|,") [[1]]
1717
url <- gsub ("^[[:space:]]*", "", url)
1818
url <- gsub ("[[:space:]].*$", "", url)
19-
ret <- grep ("github\\.com", url, value = TRUE)
19+
grep ("github\\.com", url, value = TRUE)
20+
}
21+
if ("URL" %in% colnames (desc)) {
22+
url <- strip_url (desc [, "URL"])
23+
}
24+
if (length (url) == 0L && "BugReports" %in% colnames (desc)) {
25+
url <- strip_url (desc [, "BugReports"])
26+
url <- gsub ("\\/issues(\\/?)$", "", url)
27+
}
28+
# No url listed in DESC, try git remote:
29+
if (length (url) == 0L) {
30+
remotes <- gert::git_remote_list (path)
31+
url <- grep ("github\\.com", remotes$url, value = TRUE)
2032
}
21-
return (ret)
33+
return (url)
2234
}
2335

2436
org_repo_from_path <- function (path) {

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

tests/testthat/test-cm-metrics.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ test_that ("cm metric has CI internal", { # R/cm-metric-has-ci.R
6969
expect_false (org_repo_from_path (path))
7070

7171
writeLines (desc [-i], desc_path)
72-
expect_null (pkg_gh_url_from_path (path))
72+
expect_length (pkg_gh_url_from_path (path), 0L)
7373
expect_false (org_repo_from_path (path))
7474

7575
fs::dir_delete (path)

tests/testthat/test-utils.R

+35
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,38 @@ test_that ("author matches", { # R/cm-metric-cran-downloads.R
3030
expect_true ("mpadge" %in% ctbs_log$gh_handle)
3131
expect_true ("hfrick" %in% ctbs_log$gh_handle)
3232
})
33+
34+
test_that ("url from path", {
35+
36+
path <- generate_test_pkg ()
37+
url <- pkg_gh_url_from_path (path)
38+
url_in_desc <- "https://github.com/ropensci-review-tools/goodpractice"
39+
expect_equal (url, url_in_desc)
40+
41+
# Rm URL from desc:
42+
desc_path <- fs::dir_ls (path, regexp = "DESCRIPTION", type = "file")
43+
desc <- brio::readLines (desc_path)
44+
url_line <- grep ("^URL", desc, value = TRUE)
45+
desc <- desc [-grep ("^URL", desc)]
46+
writeLines (desc, desc_path)
47+
expect_length (pkg_gh_url_from_path (path), 0L)
48+
49+
url_line <- gsub ("^URL", "BugReports", url_line)
50+
url_line <- paste0 (url_line, "/issues")
51+
desc <- c (desc, url_line)
52+
writeLines (desc, desc_path)
53+
url <- pkg_gh_url_from_path (path)
54+
expect_equal (url, url_in_desc)
55+
# Then remove again:
56+
desc <- desc [-length (desc)]
57+
writeLines (desc, desc_path)
58+
expect_length (pkg_gh_url_from_path (path), 0L)
59+
60+
# Add git remote:
61+
gert::git_remote_add ("https://not.a.url", repo = path)
62+
expect_length (pkg_gh_url_from_path (path), 0L)
63+
gert::git_remote_set_url (url_in_desc, remote = "origin", repo = path)
64+
expect_equal (pkg_gh_url_from_path (path), url_in_desc)
65+
66+
fs::dir_delete (path)
67+
})

0 commit comments

Comments
 (0)