Skip to content

Commit

Permalink
fix rest api calls for code contribs for #42
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Oct 11, 2024
1 parent 8006af3 commit 868db03
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 41 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: allcontributors
Title: Acknowledge all Contributors to a Project
Version: 0.2.0.003
Version: 0.2.0.005
Authors@R: c(
person("Mark", "Padgham", , "mark.padgham@email.com", role = c("aut", "cre")),
person("Chris", "Hartgerink", role = "aut")
Expand Down
30 changes: 16 additions & 14 deletions R/github.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,33 +133,35 @@ get_gh_code_contributors <- function (org, repo, alphabetical = FALSE) {
"/contributors"
)

per_page <- 100L
pagenum <- 1L
params <- list (per_page = per_page, page = pagenum)
make_req <- function (u, tok, per_page = 100L, page_num = 1L) {

req <- httr2::request (u)
if (nchar (tok) > 0L) {
headers <- list (Authorization = paste0 ("Bearer ", tok))
req <- httr2::req_headers (req, "Authorization" = headers)
req <- httr2::request (u)
if (nchar (tok) > 0L) {
headers <- list (Authorization = paste0 ("Bearer ", tok))
req <- httr2::req_headers (req, "Authorization" = headers)
}
req <- httr2::req_url_query (req, per_page = per_page, page_num = page_num)
httr2::req_method (req, "GET")
}
req <- httr2::req_body_json (req, params)
req <- httr2::req_method (req, "GET")

per_page <- 100L
page_num <- 1L
req <- make_req (u, tok, per_page = per_page, page_num = page_num)

resp <- httr2::req_perform (req)
httr2::resp_check_status (resp)

x <- httr2::resp_body_json (resp, simplifyVector = TRUE)

res <- x
while (length (x) == per_page) {
params$page <- params$page + 1L
req <- httr2::req_body_json (req, params)

while (nrow (x) == per_page) {
page_num <- page_num + 1L
req <- make_req (u, tok, per_page = per_page, page_num = page_num)
resp <- httr2::req_perform (req)
httr2::resp_check_status (resp)

x <- httr2::resp_body_json (resp, simplifyVector = TRUE)
res <- c (res, x)
res <- rbind (res, x)
}

index <- seq_len (nrow (res))
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"codeRepository": "https://github.com/ropenscilabs/allcontributors",
"issueTracker": "https://github.com/ropenscilabs/allcontributors/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.2.0.003",
"version": "0.2.0.005",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@

]
},
"stateReason": null,
"stateReason": "COMPLETED",
"url": "https://github.com/hypertidy/geodist/issues/17",
"participants": {
"pageInfo": {
Expand Down Expand Up @@ -899,7 +899,7 @@
"createdAt": "2020-04-16T15:37:00Z",
"author": {
"login": "Robinlovelace",
"avatarUrl": "https://avatars.githubusercontent.com/u/1825120?u=461318c239e721dc40668e4b0ce6cc47731328ac&v=4"
"avatarUrl": "https://avatars.githubusercontent.com/u/1825120?u=4b78d134ed1814b0677455f45d932b3b4a6ba3a5&v=4"
},
"title": "Thanks",
"labels": {
Expand All @@ -918,7 +918,7 @@
{
"node": {
"login": "Robinlovelace",
"avatarUrl": "https://avatars.githubusercontent.com/u/1825120?u=461318c239e721dc40668e4b0ce6cc47731328ac&v=4"
"avatarUrl": "https://avatars.githubusercontent.com/u/1825120?u=4b78d134ed1814b0677455f45d932b3b4a6ba3a5&v=4"
}
},
{
Expand Down Expand Up @@ -1147,7 +1147,7 @@

]
},
"stateReason": null,
"stateReason": "COMPLETED",
"url": "https://github.com/hypertidy/geodist/issues/31",
"participants": {
"pageInfo": {
Expand Down Expand Up @@ -1203,7 +1203,7 @@
"createdAt": "2021-02-02T20:09:15Z",
"author": {
"login": "Robinlovelace",
"avatarUrl": "https://avatars.githubusercontent.com/u/1825120?u=461318c239e721dc40668e4b0ce6cc47731328ac&v=4"
"avatarUrl": "https://avatars.githubusercontent.com/u/1825120?u=4b78d134ed1814b0677455f45d932b3b4a6ba3a5&v=4"
},
"title": "Updated version of package fails when y coordinate is called ymax",
"labels": {
Expand All @@ -1222,7 +1222,7 @@
{
"node": {
"login": "Robinlovelace",
"avatarUrl": "https://avatars.githubusercontent.com/u/1825120?u=461318c239e721dc40668e4b0ce6cc47731328ac&v=4"
"avatarUrl": "https://avatars.githubusercontent.com/u/1825120?u=4b78d134ed1814b0677455f45d932b3b4a6ba3a5&v=4"
}
},
{
Expand Down
42 changes: 24 additions & 18 deletions tests/testthat/getcontribs/api.github.com/rate_limit-38c41e.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,81 @@
"resources": {
"core": {
"limit": 5000,
"used": 3,
"remaining": 4997,
"reset": 1715772798
"used": 13,
"remaining": 4987,
"reset": 1728649167
},
"search": {
"limit": 30,
"used": 0,
"remaining": 30,
"reset": 1715772607
"reset": 1728646714
},
"graphql": {
"limit": 5000,
"used": 4,
"remaining": 4996,
"reset": 1715772831
"used": 47,
"remaining": 4953,
"reset": 1728648382
},
"integration_manifest": {
"limit": 5000,
"used": 0,
"remaining": 5000,
"reset": 1715776147
"reset": 1728650254
},
"source_import": {
"limit": 100,
"used": 0,
"remaining": 100,
"reset": 1715772607
"reset": 1728646714
},
"code_scanning_upload": {
"limit": 1000,
"used": 0,
"remaining": 1000,
"reset": 1715776147
"reset": 1728650254
},
"actions_runner_registration": {
"limit": 10000,
"used": 0,
"remaining": 10000,
"reset": 1715776147
"reset": 1728650254
},
"scim": {
"limit": 15000,
"used": 0,
"remaining": 15000,
"reset": 1715776147
"reset": 1728650254
},
"dependency_snapshots": {
"limit": 100,
"used": 0,
"remaining": 100,
"reset": 1715772607
"reset": 1728646714
},
"audit_log": {
"limit": 1750,
"used": 0,
"remaining": 1750,
"reset": 1715776147
"reset": 1728650254
},
"audit_log_streaming": {
"limit": 15,
"used": 0,
"remaining": 15,
"reset": 1728650254
},
"code_search": {
"limit": 10,
"used": 0,
"remaining": 10,
"reset": 1715772607
"reset": 1728646714
}
},
"rate": {
"limit": 5000,
"used": 3,
"remaining": 4997,
"reset": 1715772798
"used": 13,
"remaining": 4987,
"reset": 1728649167
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"received_events_url": "https://api.github.com/users/mpadge/received_events",
"type": "User",
"site_admin": false,
"contributions": 215
"contributions": 225
},
{
"login": "mdsumner",
Expand Down

0 comments on commit 868db03

Please sign in to comment.