Skip to content

Commit dada43c

Browse files
authored
Merge pull request #28 from ropensci-review-tools/comments
add 'issue_comments_from_gh_api' for #23
2 parents 5860706 + 8a27c9f commit dada43c

File tree

6 files changed

+223
-47
lines changed

6 files changed

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

R/cm-data-gh-issues.R

+52
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,55 @@ get_issue_reactions <- function (body) {
8686

8787
return (reaction_counts)
8888
}
89+
90+
issue_comments_from_gh_api <- function (path, n_per_page = 100) {
91+
92+
is_test_env <- Sys.getenv ("REPOMETRICS_TESTS") == "true"
93+
94+
u_endpoint <-
95+
gh_rest_api_endpoint (path = path, endpoint = "issues/comments")
96+
97+
req0 <- req <- httr2::request (u_endpoint) |>
98+
httr2::req_url_query (per_page = n_per_page) |>
99+
add_gh_token_to_req ()
100+
101+
body <- NULL
102+
next_page <- 1
103+
104+
while (!is.null (next_page)) {
105+
106+
resp <- httr2::req_perform (req)
107+
httr2::resp_check_status (resp)
108+
109+
body <- c (body, httr2::resp_body_json (resp))
110+
111+
next_page <- gh_next_page (resp)
112+
if (is_test_env) {
113+
next_page <- NULL
114+
}
115+
116+
req <- httr2::req_url_query (req0, page = next_page)
117+
}
118+
119+
issue_url <- vapply (body, function (i) i$issue_url, character (1L))
120+
comment_url <- vapply (body, function (i) i$html_url, character (1L))
121+
comment_id <- vapply (body, function (i) i$id, double (1L))
122+
issue_number <- as.integer (basename (issue_url))
123+
user_login <- vapply (body, function (i) i$user$login, character (1L))
124+
user_id <- vapply (body, function (i) i$user$id, integer (1L))
125+
created_at <- vapply (body, function (i) i$created_at, character (1L))
126+
updated_at <- vapply (body, function (i) i$updated_at, character (1L))
127+
issue_body <- vapply (body, function (i) i$body, character (1L))
128+
129+
data.frame (
130+
issue_url = issue_url,
131+
issue_number = issue_number,
132+
comment_url = comment_url,
133+
comment_id = comment_id,
134+
user_login = user_login,
135+
user_id = user_id,
136+
created_at = created_at,
137+
updated_a = updated_at,
138+
issue_body = issue_body
139+
)
140+
}

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.050",
11+
"version": "0.1.1.054",
1212
"programmingLanguage": {
1313
"@type": "ComputerLanguage",
1414
"name": "R",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[
2+
{
3+
"url": "ghrepos/repo//issues/comments/190879177",
4+
"html_url": "https://github.com/repo//issues/7#issuecomment-190879177",
5+
"issue_url": "ghrepos/repo//issues/7",
6+
"id": 190879177,
7+
"node_id": "MDEyOklzc3VlQ29tbWVudDE5MDg3OTE3Nw==",
8+
"user": {
9+
"login": "gaborcsardi",
10+
"id": 660288,
11+
"node_id": "MDQ6VXNlcjY2MDI4OA==",
12+
"avatar_url": "https://avatars.githubusercontent.com/u/660288?v=4",
13+
"gravatar_id": "",
14+
"url": "ghusers/gaborcsardi",
15+
"html_url": "https://github.com/gaborcsardi",
16+
"followers_url": "ghusers/gaborcsardi/followers",
17+
"following_url": "ghusers/gaborcsardi/following{/other_user}",
18+
"gists_url": "ghusers/gaborcsardi/gists{/gist_id}",
19+
"starred_url": "ghusers/gaborcsardi/starred{/owner}{/repo}",
20+
"subscriptions_url": "ghusers/gaborcsardi/subscriptions",
21+
"organizations_url": "ghusers/gaborcsardi/orgs",
22+
"repos_url": "ghusers/gaborcsardi/repos",
23+
"events_url": "ghusers/gaborcsardi/events{/privacy}",
24+
"received_events_url": "ghusers/gaborcsardi/received_events",
25+
"type": "User",
26+
"user_view_type": "public",
27+
"site_admin": false
28+
},
29+
"created_at": "2016-03-01T20:00:57Z",
30+
"updated_at": "2016-03-01T20:00:57Z",
31+
"author_association": "COLLABORATOR",
32+
"body": "Hi! This is very much work in progress. `gp()` will be eventually exported. I do the development in `devtools`, and then it does not matter if it is not exported.\n\nI'll export it in a sec, but again, this package is not very useful currently, and most things, including `gp()` will change.\n",
33+
"reactions": {
34+
"url": "ghrepos/repo//issues/comments/190879177/reactions",
35+
"total_count": 0,
36+
"+1": 0,
37+
"-1": 0,
38+
"laugh": 0,
39+
"hooray": 0,
40+
"confused": 0,
41+
"heart": 0,
42+
"rocket": 0,
43+
"eyes": 0
44+
},
45+
"performed_via_github_app": null
46+
},
47+
{
48+
"url": "ghrepos/repo//issues/comments/190879265",
49+
"html_url": "https://github.com/repo//issues/7#issuecomment-190879265",
50+
"issue_url": "ghrepos/repo//issues/7",
51+
"id": 190879265,
52+
"node_id": "MDEyOklzc3VlQ29tbWVudDE5MDg3OTI2NQ==",
53+
"user": {
54+
"login": "gaborcsardi",
55+
"id": 660288,
56+
"node_id": "MDQ6VXNlcjY2MDI4OA==",
57+
"avatar_url": "https://avatars.githubusercontent.com/u/660288?v=4",
58+
"gravatar_id": "",
59+
"url": "ghusers/gaborcsardi",
60+
"html_url": "https://github.com/gaborcsardi",
61+
"followers_url": "ghusers/gaborcsardi/followers",
62+
"following_url": "ghusers/gaborcsardi/following{/other_user}",
63+
"gists_url": "ghusers/gaborcsardi/gists{/gist_id}",
64+
"starred_url": "ghusers/gaborcsardi/starred{/owner}{/repo}",
65+
"subscriptions_url": "ghusers/gaborcsardi/subscriptions",
66+
"organizations_url": "ghusers/gaborcsardi/orgs",
67+
"repos_url": "ghusers/gaborcsardi/repos",
68+
"events_url": "ghusers/gaborcsardi/events{/privacy}",
69+
"received_events_url": "ghusers/gaborcsardi/received_events",
70+
"type": "User",
71+
"user_view_type": "public",
72+
"site_admin": false
73+
},
74+
"created_at": "2016-03-01T20:01:18Z",
75+
"updated_at": "2016-03-01T20:01:18Z",
76+
"author_association": "COLLABORATOR",
77+
"body": "Exported `gp` in 5d377d299ead9adda9aa84541828f87dc97b1e00\n",
78+
"reactions": {
79+
"url": "ghrepos/repo//issues/comments/190879265/reactions",
80+
"total_count": 0,
81+
"+1": 0,
82+
"-1": 0,
83+
"laugh": 0,
84+
"hooray": 0,
85+
"confused": 0,
86+
"heart": 0,
87+
"rocket": 0,
88+
"eyes": 0
89+
},
90+
"performed_via_github_app": null
91+
}
92+
]

tests/testthat/test-cm-data-git.R

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
test_that ("cm data git", {
2+
3+
path <- generate_test_pkg ()
4+
5+
log <- cm_data_gitlog (path)
6+
7+
expect_s3_class (log, "data.frame")
8+
expect_equal (ncol (log), 10L)
9+
nms <- c (
10+
"hash", "aut_name", "aut_email", "timestamp", "message",
11+
"nfiles_changed", "lines_added", "lines_removed", "whitespace_added",
12+
"whitespace_removed"
13+
)
14+
expect_equal (names (log), nms)
15+
16+
char_nms <- nms [c (1:3, 5)]
17+
int_nms <- nms [6:10]
18+
for (n in names (log)) {
19+
type <- ifelse (n %in% char_nms, "character", "integer")
20+
if (n == "timestamp") {
21+
expect_s3_class (log [[n]], "POSIXct")
22+
} else {
23+
expect_type (log [[n]], type)
24+
}
25+
}
26+
27+
fs::dir_delete (path)
28+
})
29+
30+
test_that ("cm data dependencies", {
31+
32+
path <- generate_test_pkg ()
33+
deps <- cm_data_dependencies (path)
34+
fs::dir_delete (path)
35+
36+
expect_s3_class (deps, "data.frame")
37+
expect_equal (nrow (deps), 1L)
38+
expect_equal (ncol (deps), 3L)
39+
nms <- c ("name", "type", "version")
40+
expect_equal (names (deps), nms)
41+
for (n in names (deps)) {
42+
expect_type (deps [[n]], "character")
43+
}
44+
})

tests/testthat/test-cm-data.R tests/testthat/test-cm-data-github.R

+33-45
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
test_that ("cm data git", {
2-
3-
path <- generate_test_pkg ()
4-
5-
log <- cm_data_gitlog (path)
6-
7-
expect_s3_class (log, "data.frame")
8-
expect_equal (ncol (log), 10L)
9-
nms <- c (
10-
"hash", "aut_name", "aut_email", "timestamp", "message",
11-
"nfiles_changed", "lines_added", "lines_removed", "whitespace_added",
12-
"whitespace_removed"
13-
)
14-
expect_equal (names (log), nms)
15-
16-
char_nms <- nms [c (1:3, 5)]
17-
int_nms <- nms [6:10]
18-
for (n in names (log)) {
19-
type <- ifelse (n %in% char_nms, "character", "integer")
20-
if (n == "timestamp") {
21-
expect_s3_class (log [[n]], "POSIXct")
22-
} else {
23-
expect_type (log [[n]], type)
24-
}
25-
}
26-
27-
fs::dir_delete (path)
28-
})
29-
301
test_that ("cm data gh contribs", {
312

323
Sys.setenv ("REPOMETRICS_TESTS" = "true")
@@ -91,22 +62,6 @@ test_that ("cm data gh repo", {
9162
}
9263
})
9364

94-
test_that ("cm data dependencies", {
95-
96-
path <- generate_test_pkg ()
97-
deps <- cm_data_dependencies (path)
98-
fs::dir_delete (path)
99-
100-
expect_s3_class (deps, "data.frame")
101-
expect_equal (nrow (deps), 1L)
102-
expect_equal (ncol (deps), 3L)
103-
nms <- c ("name", "type", "version")
104-
expect_equal (names (deps), nms)
105-
for (n in names (deps)) {
106-
expect_type (deps [[n]], "character")
107-
}
108-
})
109-
11065
test_that ("cm data gh issues", {
11166

11267
Sys.setenv ("REPOMETRICS_TESTS" = "true")
@@ -143,3 +98,36 @@ test_that ("cm data gh issues", {
14398
expect_type (issues [[n]], type)
14499
}
145100
})
101+
102+
test_that ("cm data gh issue commentss", {
103+
104+
Sys.setenv ("REPOMETRICS_TESTS" = "true")
105+
106+
path <- generate_test_pkg ()
107+
cmts <- with_mock_dir ("gh_api_issue_cmts", {
108+
issue_comments_from_gh_api (path, n_per_page = 2L)
109+
})
110+
111+
fs::dir_delete (path)
112+
113+
expect_s3_class (cmts, "data.frame")
114+
expect_equal (nrow (cmts), 2L)
115+
expect_equal (ncol (cmts), 9L)
116+
nms <- c (
117+
"issue_url", "issue_number", "comment_url", "comment_id", "user_login",
118+
"user_id", "created_at", "updated_a", "issue_body"
119+
)
120+
expect_equal (names (cmts), nms)
121+
122+
int_index <- c (2, 6)
123+
char_index <- seq_along (nms) [-int_index]
124+
int_nms <- nms [int_index]
125+
char_nms <- nms [char_index]
126+
for (n in names (cmts)) {
127+
type <- ifelse (n %in% char_nms, "character", "integer")
128+
if (n == "comment_id") {
129+
type <- "double"
130+
}
131+
expect_type (cmts [[n]], type)
132+
}
133+
})

0 commit comments

Comments
 (0)