Skip to content

Commit c237bd8

Browse files
committed
test 'github_issues_pr_qry' fn for #11
1 parent bae73d9 commit c237bd8

File tree

6 files changed

+280
-4
lines changed

6 files changed

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

R/gh-queries.R

+9-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ github_issues_prs_query <- function (org = NULL, repo = NULL) {
5353

5454
u_base <- "https://api.github.com/repos/"
5555
u_repo <- paste0 (u_base, org, "/", repo, "/")
56-
u_wf <- paste0 (u_repo, "events?per_page=100")
56+
57+
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
58+
u_wf <- paste0 (u_repo, "events?per_page=", ifelse (is_test_env, 2, 100))
5759

5860
body <- NULL
5961
this_url <- u_wf
@@ -67,7 +69,12 @@ github_issues_prs_query <- function (org = NULL, repo = NULL) {
6769

6870
this_body <- httr2::resp_body_json (resp)
6971
body <- c (body, this_body)
70-
this_url <- get_next_link (resp)
72+
73+
if (!is_test_env) {
74+
this_url <- get_next_link (resp)
75+
} else {
76+
this_url <- NULL
77+
}
7178
}
7279

7380
# Extraction function for single fields which may not be present

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

inst/httptest2/redact.R

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ function (resp) {
1414
fixed = TRUE
1515
)
1616

17+
resp <- httptest2::gsub_response (
18+
resp,
19+
"ropensci-review-tools/goodpractice",
20+
"repo/",
21+
fixed = TRUE
22+
)
23+
1724
test_repo <- "ropensci-review-tools/repometrics"
1825
resp <- httptest2::gsub_response (
1926
resp,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
[
2+
{
3+
"id": "43737496856",
4+
"type": "IssueCommentEvent",
5+
"actor": {
6+
"id": 6697851,
7+
"login": "mpadge",
8+
"display_login": "mpadge",
9+
"gravatar_id": "",
10+
"url": "https://api.github.com/users/mpadge",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/6697851?"
12+
},
13+
"repo": {
14+
"id": 50784274,
15+
"name": "repo/",
16+
"url": "ghapi/repo/"
17+
},
18+
"payload": {
19+
"action": "created",
20+
"issue": {
21+
"url": "ghapi/repo//issues/182",
22+
"repository_url": "ghapi/repo/",
23+
"labels_url": "ghapi/repo//issues/182/labels{/name}",
24+
"comments_url": "ghapi/repo//issues/182/comments",
25+
"events_url": "ghapi/repo//issues/182/events",
26+
"html_url": "https://github.com/repo//issues/182",
27+
"id": 2634833618,
28+
"node_id": "I_kwDOAwboEs6dDF7S",
29+
"number": 182,
30+
"title": "rcmdcheck_vignettes_run fails on wanted errors",
31+
"user": {
32+
"login": "valentingar",
33+
"id": 74970146,
34+
"node_id": "MDQ6VXNlcjc0OTcwMTQ2",
35+
"avatar_url": "https://avatars.githubusercontent.com/u/74970146?v=4",
36+
"gravatar_id": "",
37+
"url": "https://api.github.com/users/valentingar",
38+
"html_url": "https://github.com/valentingar",
39+
"followers_url": "https://api.github.com/users/valentingar/followers",
40+
"following_url": "https://api.github.com/users/valentingar/following{/other_user}",
41+
"gists_url": "https://api.github.com/users/valentingar/gists{/gist_id}",
42+
"starred_url": "https://api.github.com/users/valentingar/starred{/owner}{/repo}",
43+
"subscriptions_url": "https://api.github.com/users/valentingar/subscriptions",
44+
"organizations_url": "https://api.github.com/users/valentingar/orgs",
45+
"repos_url": "https://api.github.com/users/valentingar/repos",
46+
"events_url": "https://api.github.com/users/valentingar/events{/privacy}",
47+
"received_events_url": "https://api.github.com/users/valentingar/received_events",
48+
"type": "User",
49+
"user_view_type": "public",
50+
"site_admin": false
51+
},
52+
"labels": [
53+
54+
],
55+
"state": "closed",
56+
"locked": false,
57+
"assignee": null,
58+
"assignees": [
59+
60+
],
61+
"milestone": null,
62+
"comments": 1,
63+
"created_at": "2024-11-05T08:57:19Z",
64+
"updated_at": "2024-11-12T11:33:01Z",
65+
"closed_at": "2024-11-12T11:33:00Z",
66+
"author_association": "NONE",
67+
"active_lock_reason": null,
68+
"body": "**Problem:** \r\nIf you want to demonstrate an error message in the package vignette, by setting the chunk option `error=TRUE`, `rcmdcheck_vignettes_run` still returns a note that the code cannot be run. \r\n\r\n**Expected behaviour:**\r\nIt should recognise the `error = TRUE` comment and not test these chunks.\r\n\r\n**Steps to reproduce:**\r\n- create new package\r\n- add vignette `usethis::use_vignette()`\r\n- add a chunk with option `error=TRUE` and code that causes an error message (e.g. `mod <- lm()`)\r\n- run `devtools::build_vignettes`\r\n- run `goodpractice::gp(checks = \"rcmdcheck_vignettes_run\")`",
69+
"reactions": {
70+
"url": "ghapi/repo//issues/182/reactions",
71+
"total_count": 0,
72+
"+1": 0,
73+
"-1": 0,
74+
"laugh": 0,
75+
"hooray": 0,
76+
"confused": 0,
77+
"heart": 0,
78+
"rocket": 0,
79+
"eyes": 0
80+
},
81+
"timeline_url": "ghapi/repo//issues/182/timeline",
82+
"performed_via_github_app": null,
83+
"state_reason": "not_planned"
84+
},
85+
"comment": {
86+
"url": "ghapi/repo//issues/comments/2470293065",
87+
"html_url": "https://github.com/repo//issues/182#issuecomment-2470293065",
88+
"issue_url": "ghapi/repo//issues/182",
89+
"id": 2470293065,
90+
"node_id": "IC_kwDOAwboEs6TPa5J",
91+
"user": {
92+
"login": "mpadge",
93+
"id": 6697851,
94+
"node_id": "MDQ6VXNlcjY2OTc4NTE=",
95+
"avatar_url": "https://avatars.githubusercontent.com/u/6697851?v=4",
96+
"gravatar_id": "",
97+
"url": "https://api.github.com/users/mpadge",
98+
"html_url": "https://github.com/mpadge",
99+
"followers_url": "https://api.github.com/users/mpadge/followers",
100+
"following_url": "https://api.github.com/users/mpadge/following{/other_user}",
101+
"gists_url": "https://api.github.com/users/mpadge/gists{/gist_id}",
102+
"starred_url": "https://api.github.com/users/mpadge/starred{/owner}{/repo}",
103+
"subscriptions_url": "https://api.github.com/users/mpadge/subscriptions",
104+
"organizations_url": "https://api.github.com/users/mpadge/orgs",
105+
"repos_url": "https://api.github.com/users/mpadge/repos",
106+
"events_url": "https://api.github.com/users/mpadge/events{/privacy}",
107+
"received_events_url": "https://api.github.com/users/mpadge/received_events",
108+
"type": "User",
109+
"user_view_type": "public",
110+
"site_admin": false
111+
},
112+
"created_at": "2024-11-12T11:33:00Z",
113+
"updated_at": "2024-11-12T11:33:00Z",
114+
"author_association": "MEMBER",
115+
"body": "Thanks @valentingar. So i followed all of those steps, but I see this, starting with vignette code to confirm `error = TRUE` chunk:\r\n\r\n``` r\r\nsetwd (\"/<path>/<to>/<pkg>/\")\r\nreadLines (\"vignettes/vignette.Rmd\")\r\n```\r\n\r\n #> [1] \"---\" \r\n #> [2] \"title: \\\"vignette\\\"\" \r\n #> [3] \"output: rmarkdown::html_vignette\" \r\n #> [4] \"vignette: >\" \r\n #> [5] \" %\\\\VignetteIndexEntry{vignette}\" \r\n #> [6] \" %\\\\VignetteEngine{knitr::rmarkdown}\"\r\n #> [7] \" %\\\\VignetteEncoding{UTF-8}\" \r\n #> [8] \"---\" \r\n #> [9] \"\" \r\n #> [10] \"```{r, include = FALSE}\" \r\n #> [11] \"knitr::opts_chunk$set(\" \r\n #> [12] \" collapse = TRUE,\" \r\n #> [13] \" comment = \\\"#>\\\"\" \r\n #> [14] \")\" \r\n #> [15] \"```\" \r\n #> [16] \"\" \r\n #> [17] \"```{r setup}\" \r\n #> [18] \"library(demo)\" \r\n #> [19] \"```\" \r\n #> [20] \"\" \r\n #> [21] \"```{r error, error = TRUE}\" \r\n #> [22] \"stop (\\\"This is an error\\\")\" \r\n #> [23] \"```\"\r\n\r\nThen:\r\n\r\n``` r\r\nlibrary (goodpractice)\r\npackageVersion (\"goodpractice\")\r\n#> [1] '1.0.5.9001'\r\ng <- gp (checks = \"rcmdcheck_vignettes_run\")\r\n#> ℹ Preparing: rcmdcheck\r\ng\r\n#> \r\n#> ♥ Aha! Super package! Keep up the slick work!\r\ng$checks\r\n#> $rcmdcheck_vignettes_run\r\n#> [1] TRUE\r\n```\r\n\r\n<sup>Created on 2024-11-12 with [reprex v2.1.1](https://reprex.tidyverse.org)<\/sup>\r\n\r\nLooks all good to me, but happy to look further if you still see the issue.",
116+
"reactions": {
117+
"url": "ghapi/repo//issues/comments/2470293065/reactions",
118+
"total_count": 0,
119+
"+1": 0,
120+
"-1": 0,
121+
"laugh": 0,
122+
"hooray": 0,
123+
"confused": 0,
124+
"heart": 0,
125+
"rocket": 0,
126+
"eyes": 0
127+
},
128+
"performed_via_github_app": null
129+
}
130+
},
131+
"public": true,
132+
"created_at": "2024-11-12T11:33:03Z",
133+
"org": {
134+
"id": 85607140,
135+
"login": "ropensci-review-tools",
136+
"gravatar_id": "",
137+
"url": "https://api.github.com/orgs/ropensci-review-tools",
138+
"avatar_url": "https://avatars.githubusercontent.com/u/85607140?"
139+
}
140+
},
141+
{
142+
"id": "43737496184",
143+
"type": "IssuesEvent",
144+
"actor": {
145+
"id": 6697851,
146+
"login": "mpadge",
147+
"display_login": "mpadge",
148+
"gravatar_id": "",
149+
"url": "https://api.github.com/users/mpadge",
150+
"avatar_url": "https://avatars.githubusercontent.com/u/6697851?"
151+
},
152+
"repo": {
153+
"id": 50784274,
154+
"name": "repo/",
155+
"url": "ghapi/repo/"
156+
},
157+
"payload": {
158+
"action": "closed",
159+
"issue": {
160+
"url": "ghapi/repo//issues/182",
161+
"repository_url": "ghapi/repo/",
162+
"labels_url": "ghapi/repo//issues/182/labels{/name}",
163+
"comments_url": "ghapi/repo//issues/182/comments",
164+
"events_url": "ghapi/repo//issues/182/events",
165+
"html_url": "https://github.com/repo//issues/182",
166+
"id": 2634833618,
167+
"node_id": "I_kwDOAwboEs6dDF7S",
168+
"number": 182,
169+
"title": "rcmdcheck_vignettes_run fails on wanted errors",
170+
"user": {
171+
"login": "valentingar",
172+
"id": 74970146,
173+
"node_id": "MDQ6VXNlcjc0OTcwMTQ2",
174+
"avatar_url": "https://avatars.githubusercontent.com/u/74970146?v=4",
175+
"gravatar_id": "",
176+
"url": "https://api.github.com/users/valentingar",
177+
"html_url": "https://github.com/valentingar",
178+
"followers_url": "https://api.github.com/users/valentingar/followers",
179+
"following_url": "https://api.github.com/users/valentingar/following{/other_user}",
180+
"gists_url": "https://api.github.com/users/valentingar/gists{/gist_id}",
181+
"starred_url": "https://api.github.com/users/valentingar/starred{/owner}{/repo}",
182+
"subscriptions_url": "https://api.github.com/users/valentingar/subscriptions",
183+
"organizations_url": "https://api.github.com/users/valentingar/orgs",
184+
"repos_url": "https://api.github.com/users/valentingar/repos",
185+
"events_url": "https://api.github.com/users/valentingar/events{/privacy}",
186+
"received_events_url": "https://api.github.com/users/valentingar/received_events",
187+
"type": "User",
188+
"user_view_type": "public",
189+
"site_admin": false
190+
},
191+
"labels": [
192+
193+
],
194+
"state": "closed",
195+
"locked": false,
196+
"assignee": null,
197+
"assignees": [
198+
199+
],
200+
"milestone": null,
201+
"comments": 1,
202+
"created_at": "2024-11-05T08:57:19Z",
203+
"updated_at": "2024-11-12T11:33:01Z",
204+
"closed_at": "2024-11-12T11:33:00Z",
205+
"author_association": "NONE",
206+
"active_lock_reason": null,
207+
"body": "**Problem:** \r\nIf you want to demonstrate an error message in the package vignette, by setting the chunk option `error=TRUE`, `rcmdcheck_vignettes_run` still returns a note that the code cannot be run. \r\n\r\n**Expected behaviour:**\r\nIt should recognise the `error = TRUE` comment and not test these chunks.\r\n\r\n**Steps to reproduce:**\r\n- create new package\r\n- add vignette `usethis::use_vignette()`\r\n- add a chunk with option `error=TRUE` and code that causes an error message (e.g. `mod <- lm()`)\r\n- run `devtools::build_vignettes`\r\n- run `goodpractice::gp(checks = \"rcmdcheck_vignettes_run\")`",
208+
"reactions": {
209+
"url": "ghapi/repo//issues/182/reactions",
210+
"total_count": 0,
211+
"+1": 0,
212+
"-1": 0,
213+
"laugh": 0,
214+
"hooray": 0,
215+
"confused": 0,
216+
"heart": 0,
217+
"rocket": 0,
218+
"eyes": 0
219+
},
220+
"timeline_url": "ghapi/repo//issues/182/timeline",
221+
"performed_via_github_app": null,
222+
"state_reason": "not_planned"
223+
}
224+
},
225+
"public": true,
226+
"created_at": "2024-11-12T11:33:01Z",
227+
"org": {
228+
"id": 85607140,
229+
"login": "ropensci-review-tools",
230+
"gravatar_id": "",
231+
"url": "https://api.github.com/orgs/ropensci-review-tools",
232+
"avatar_url": "https://avatars.githubusercontent.com/u/85607140?"
233+
}
234+
}
235+
]

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

+27
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,30 @@ test_that ("chaoss has CI external", {
3737
c ("name", "id", "sha", "title", "status", "conclusion", "created")
3838
)
3939
})
40+
41+
test_that ("chaoss external commits in prs", {
42+
43+
# This tests this internal function called by "prop_commits_in_prs". The
44+
# latter function ultimately returns nothing, so this test is needed to
45+
# confirm the intermediate data structure.
46+
Sys.setenv ("REPOMETRICS_TESTS" = "true")
47+
48+
org <- "ropensci-review-tools"
49+
repo <- "goodpractice"
50+
51+
dat <- with_mock_dir (
52+
"gh_pr_qry",
53+
github_issues_prs_query (org, repo)
54+
)
55+
56+
expect_s3_class (dat, "data.frame")
57+
expect_equal (nrow (dat), 2L) # 2 hard-coded in 'gh-queries.R' for test env
58+
expect_equal (ncol (dat), 13L)
59+
nms <- c (
60+
"id", "type", "login", "action", "number", "commits",
61+
"num_comments", "num_review_comments", "additions", "deletions",
62+
"changed_files", "created_at", "merged_at"
63+
)
64+
expect_equal (names (dat), nms)
65+
expect_true (all (c ("created", "closed") %in% dat$action))
66+
})

0 commit comments

Comments
 (0)