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

issues linked to change request metric for #11 #22

Merged
merged 6 commits into from
Nov 14, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test full 'externa_prop_commits' fn for #11
mpadge committed Nov 14, 2024
commit f42faf038703bd7e4bed55ac53b40753bb5e4124
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.1.013
Version: 0.1.1.014
Authors@R:
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
@@ -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.1.013",
"version": "0.1.1.014",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
24 changes: 24 additions & 0 deletions tests/testthat/test-chaoss-metrics-external.R
Original file line number Diff line number Diff line change
@@ -64,3 +64,27 @@ test_that ("chaoss external commits in prs", {
expect_equal (names (dat), nms)
expect_true (all (c ("created", "closed") %in% dat$action))
})

test_that ("chaoss external prop commits in change req", {

Sys.setenv ("REPOMETRICS_TESTS" = "true")
pkg <- system.file ("extdata", "testpkg.zip", package = "repometrics")
flist <- unzip (pkg, exdir = fs::path_temp ())
path <- fs::path_dir (flist [1])

desc_path <- fs::dir_ls (path, type = "file", regexp = "DESCRIPTION$")
url <- "https://github.com/ropensci-review-tools/goodpractice"
desc <- c (
readLines (desc_path),
paste0 ("URL: ", url)
)
writeLines (desc, desc_path)

end_date <- as.Date ("2024-01-01")
prop_commits <- with_mock_dir ("gh_pr_qry", {
prop_commits_in_change_req (path = path, end_date = end_date)
})
expect_identical (prop_commits, 0.)

fs::dir_delete (path)
})

Unchanged files with check annotations Beta

body <- c (body, this_body)
if (!is_test_env) {
this_url <- get_next_link (resp)

Check warning on line 74 in R/gh-queries.R

Codecov / codecov/patch

R/gh-queries.R#L74

Added line #L74 was not covered by tests
} else {
this_url <- NULL
}
vapply (body, function (i) {
ret <- naval
if (field1 %in% names (i$payload)) {
if (field2 %in% names (i$payload [[field1]])) {
ret <- i$payload [[field1]] [[field2]]

Check warning on line 99 in R/gh-queries.R

Codecov / codecov/patch

R/gh-queries.R#L98-L99

Added lines #L98 - L99 were not covered by tests
}
}
ifelse (is.null (ret), naval, ret)
add_token_to_req <- function (req) {
if (!nzchar (Sys.getenv ("GITHUB_WORKFLOW"))) {
tok <- get_gh_token ()
headers <- list (Authorization = paste0 ("Bearer ", tok))
req <- httr2::req_headers (req, "Authorization" = headers)

Check warning on line 153 in R/gh-queries.R

Codecov / codecov/patch

R/gh-queries.R#L151-L153

Added lines #L151 - L153 were not covered by tests
}
return (req)
#' @noRd
get_next_link <- function (resp) {
link <- httr2::resp_headers (resp)$link

Check warning on line 164 in R/gh-queries.R

Codecov / codecov/patch

R/gh-queries.R#L164

Added line #L164 was not covered by tests
next_url <- NULL

Check warning on line 166 in R/gh-queries.R

Codecov / codecov/patch

R/gh-queries.R#L166

Added line #L166 was not covered by tests
if (!is.null (link)) {
next_ptn <- "rel\\=\\\"next"
if (grepl (next_ptn, link)) {

Check warning on line 170 in R/gh-queries.R

Codecov / codecov/patch

R/gh-queries.R#L168-L170

Added lines #L168 - L170 were not covered by tests
# "next" is always first; where there are multiples, "prev" comes
# after "next"
ptn <- "<([^>]+)>"
next_url <- regmatches (link, regexpr (ptn, link))
next_url <- gsub ("<|>", "", next_url)
if (!grepl ("after", next_url)) {
cli::cli_abort ("Pagination link in GitHub Rest API malformed: [{next_url}]")

Check warning on line 177 in R/gh-queries.R

Codecov / codecov/patch

R/gh-queries.R#L173-L177

Added lines #L173 - L177 were not covered by tests
}
}
}
return (next_url)

Check warning on line 182 in R/gh-queries.R

Codecov / codecov/patch

R/gh-queries.R#L182

Added line #L182 was not covered by tests
}