Skip to content

Commit

Permalink
Merge pull request #53 from ropensci-review-tools/tidy
Browse files Browse the repository at this point in the history
add cli output to main data fn
  • Loading branch information
mpadge authored Dec 6, 2024
2 parents 169d970 + b43c32e commit b3a70d8
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
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 ...")
pkgstats <- repo_pkgstats_history (
path,
step_days = step_days,
num_cores = num_cores
)
cli::cli_alert_success ("Done!")

cli::cli_alert_info ("Extracting GitHub data ...")
cm <- cm_data (path)
cm$contributors <- get_all_contribs (cm$contribs_from_log, cm$contribs_from_gh_api)
cli::cli_alert_success ("Done!")

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)
})

0 comments on commit b3a70d8

Please sign in to comment.