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

add cli output to main data fn #53

Merged
merged 5 commits into from
Dec 6, 2024
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.2.037
Version: 0.1.2.042
Authors@R:
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
5 changes: 5 additions & 0 deletions R/repometrics-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
#' @export
repometrics_data <- function (path, step_days = 1L, num_cores = -1L) {

cli::cli_alert_info ("Extracting package statistics ...")

Check warning on line 15 in R/repometrics-data.R

View check run for this annotation

Codecov / codecov/patch

R/repometrics-data.R#L15

Added line #L15 was not covered by tests
pkgstats <- repo_pkgstats_history (
path,
step_days = step_days,
num_cores = num_cores
)
cli::cli_alert_success ("Done!")

Check warning on line 21 in R/repometrics-data.R

View check run for this annotation

Codecov / codecov/patch

R/repometrics-data.R#L21

Added line #L21 was not covered by tests

cli::cli_alert_info ("Extracting GitHub data ...")

Check warning on line 23 in R/repometrics-data.R

View check run for this annotation

Codecov / codecov/patch

R/repometrics-data.R#L23

Added line #L23 was not covered by tests
cm <- cm_data (path)
cm$contributors <- get_all_contribs (cm$contribs_from_log, cm$contribs_from_gh_api)
cli::cli_alert_success ("Done!")

Check warning on line 26 in R/repometrics-data.R

View check run for this annotation

Codecov / codecov/patch

R/repometrics-data.R#L26

Added line #L26 was not covered by tests

list (pkgstats = pkgstats, cm = cm)
}
22 changes: 17 additions & 5 deletions R/utils-path-pkg-manipulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,26 @@ pkg_gh_url_from_path <- function (path) {
checkmate::assert_file_exists (desc)

desc <- read.dcf (desc)
ret <- NULL
if ("URL" %in% colnames (desc)) {
url <- strsplit (unname (desc [, "URL"]), "\\n|,") [[1]]
url <- NULL
strip_url <- function (url) {
url <- strsplit (unname (url), "\\n|,") [[1]]
url <- gsub ("^[[:space:]]*", "", url)
url <- gsub ("[[:space:]].*$", "", url)
ret <- grep ("github\\.com", url, value = TRUE)
grep ("github\\.com", url, value = TRUE)
}
if ("URL" %in% colnames (desc)) {
url <- strip_url (desc [, "URL"])
}
if (length (url) == 0L && "BugReports" %in% colnames (desc)) {
url <- strip_url (desc [, "BugReports"])
url <- gsub ("\\/issues(\\/?)$", "", url)
}
# No url listed in DESC, try git remote:
if (length (url) == 0L) {
remotes <- gert::git_remote_list (path)
url <- grep ("github\\.com", remotes$url, value = TRUE)
}
return (ret)
return (url)
}

org_repo_from_path <- function (path) {
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/ropensci-review-tools/repometrics",
"issueTracker": "https://github.com/ropensci-review-tools/repometrics/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.1.2.037",
"version": "0.1.2.042",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-cm-metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test_that ("cm metric has CI internal", { # R/cm-metric-has-ci.R
expect_false (org_repo_from_path (path))

writeLines (desc [-i], desc_path)
expect_null (pkg_gh_url_from_path (path))
expect_length (pkg_gh_url_from_path (path), 0L)
expect_false (org_repo_from_path (path))

fs::dir_delete (path)
Expand Down
35 changes: 35 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,38 @@ test_that ("author matches", { # R/cm-metric-cran-downloads.R
expect_true ("mpadge" %in% ctbs_log$gh_handle)
expect_true ("hfrick" %in% ctbs_log$gh_handle)
})

test_that ("url from path", {

path <- generate_test_pkg ()
url <- pkg_gh_url_from_path (path)
url_in_desc <- "https://github.com/ropensci-review-tools/goodpractice"
expect_equal (url, url_in_desc)

# Rm URL from desc:
desc_path <- fs::dir_ls (path, regexp = "DESCRIPTION", type = "file")
desc <- brio::readLines (desc_path)
url_line <- grep ("^URL", desc, value = TRUE)
desc <- desc [-grep ("^URL", desc)]
writeLines (desc, desc_path)
expect_length (pkg_gh_url_from_path (path), 0L)

url_line <- gsub ("^URL", "BugReports", url_line)
url_line <- paste0 (url_line, "/issues")
desc <- c (desc, url_line)
writeLines (desc, desc_path)
url <- pkg_gh_url_from_path (path)
expect_equal (url, url_in_desc)
# Then remove again:
desc <- desc [-length (desc)]
writeLines (desc, desc_path)
expect_length (pkg_gh_url_from_path (path), 0L)

# Add git remote:
gert::git_remote_add ("https://not.a.url", repo = path)
expect_length (pkg_gh_url_from_path (path), 0L)
gert::git_remote_set_url (url_in_desc, remote = "origin", repo = path)
expect_equal (pkg_gh_url_from_path (path), url_in_desc)

fs::dir_delete (path)
})
Loading