Skip to content

Commit 176204a

Browse files
committed
more increase of test coverage for has_ci chaoss metric #11
1 parent b72b142 commit 176204a

7 files changed

+34
-43
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: githist
22
Title: Code analyses traced along the 'git' history of a package
3-
Version: 0.1.0.048
3+
Version: 0.1.0.049
44
Authors@R:
55
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-2172-5265"))

R/chaoss-metrics-external.R

+2-13
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,9 @@ cran_downloads <- function (pkg_name, end_date = Sys.Date ()) {
2828

2929
has_gh_ci_tests <- function (path) {
3030

31-
url <- pkg_gh_url_from_path (path)
32-
if (length (url) == 0L) {
33-
return (FALSE)
34-
}
31+
or <- org_repo_from_path (path)
3532

36-
url_parts <- strsplit (url, "\\/") [[1]]
37-
i <- which (url_parts == "github.com")
38-
if (length (i) == 0L || i > (length (url_parts) + 2L)) {
39-
return (FALSE)
40-
}
41-
org <- url_parts [i + 1L]
42-
repo <- url_parts [i + 2L]
43-
44-
ci_data <- github_repo_workflow_query (org, repo)
33+
ci_data <- github_repo_workflow_query (or [1], or [2])
4534
h <- gert::git_log (repo = path, max = 1e6)
4635
any (ci_data$sha %in% h$commit)
4736
}

R/gh-queries.R

-27
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
github_repo_files_query <- function (org = NULL, repo = NULL) {
2-
3-
q <- paste0 ("{
4-
repository(owner:\"", org, "\", name:\"", repo, "\") {
5-
object(expression: \"HEAD:\") {
6-
... on Tree {
7-
entries {
8-
name
9-
type
10-
mode
11-
object {
12-
... on Commit {
13-
oid
14-
committedDate
15-
}
16-
... on Blob {
17-
byteSize
18-
isBinary
19-
}
20-
}
21-
}
22-
}
23-
}
24-
}
25-
}")
26-
}
27-
281
#' Retrieve latest GitHub workflow results from Rest API
292
#'
303
#' This uses default of 30 most recent results.

R/utils.R

+18
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ pkg_gh_url_from_path <- function (path) {
6666
return (ret)
6767
}
6868

69+
org_repo_from_path <- function (path) {
70+
71+
url <- pkg_gh_url_from_path (path)
72+
if (length (url) == 0L) {
73+
return (FALSE)
74+
}
75+
76+
url_parts <- strsplit (url, "\\/") [[1]]
77+
i <- which (url_parts == "github.com")
78+
if (length (i) == 0L || i > (length (url_parts) + 2L)) {
79+
return (FALSE)
80+
}
81+
org <- url_parts [i + 1L]
82+
repo <- url_parts [i + 2L]
83+
84+
c (org, repo)
85+
}
86+
6987
filter_git_hist <- function (h, n, step_days) {
7088
if (!is.null (n)) {
7189
h <- h [seq_len (n), ]

codemeta.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"codeRepository": "https://github.com/ropensci-review-tools/githist",
99
"issueTracker": "https://github.com/ropensci-review-tools/githist/issues",
1010
"license": "https://spdx.org/licenses/GPL-3.0",
11-
"version": "0.1.0.048",
11+
"version": "0.1.0.049",
1212
"programmingLanguage": {
1313
"@type": "ComputerLanguage",
1414
"name": "R",

tests/testthat/test-chaoss-metrics-external.R

+8
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ test_that ("chaoss has CI external", {
2828
"gh_workflow",
2929
github_repo_workflow_query (org, repo, n = 2L)
3030
)
31+
32+
expect_s3_class (ci_data, "data.frame")
33+
expect_equal (nrow (ci_data), 2L)
34+
expect_equal (ncol (ci_data), 7L)
35+
expect_equal (
36+
names (ci_data),
37+
c ("name", "id", "sha", "title", "status", "conclusion", "created")
38+
)
3139
})

tests/testthat/test-chaoss-metrics-internal.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ test_that ("chaoss has CI internal", {
2727
url <- "https://github.com/my/pkg"
2828
desc <- c (
2929
readLines (desc_path),
30-
paste0 ("URL: ", url),
30+
paste0 ("URL: ", url)
3131
)
3232
writeLines (desc, desc_path)
3333

3434
expect_identical (url, pkg_gh_url_from_path (path))
3535

36+
org_repo <- org_repo_from_path (path)
37+
expect_identical (org_repo, c ("my", "pkg"))
38+
3639
fs::dir_delete (path)
3740
})

0 commit comments

Comments
 (0)