Skip to content

Commit ed8d470

Browse files
committed
pass through verbose and add docs
1 parent 5d59b00 commit ed8d470

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ You can inspect which fields are available for a type `G<:GitHubType` by calling
6969

7070
GitHub.jl implements a bunch of methods that make REST requests to GitHub's API. The below sections list these methods (note that a return type of `Tuple{Vector{T}, Dict}` means the result is [paginated](#pagination)).
7171

72+
These methods all accept keyword arguments which control how the request is made to github:
73+
74+
- `max_retries::Int=5`: how many retries to attempt in requesting the resources. Retries are only made for idempotent requests ("GET", "HEAD", "OPTIONS", "TRACE", "PUT", "DELETE") and delays respect GitHub [rate limit headers](https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#checking-the-status-of-your-rate-limit).
75+
- `verbose::Bool=true`: whether or not to log retries as Info level logs
76+
7277
#### Users and Organizations
7378

7479
| method | return type | documentation |

src/utils/requests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ end
242242
function github_request(api::GitHubAPI, request_method::String, endpoint;
243243
auth = AnonymousAuth(), handle_error = true,
244244
headers = Dict(), params = Dict(), allowredirects = true,
245-
max_retries = 5)
245+
max_retries = 5, verbose = true)
246246
authenticate_headers!(headers, auth)
247247
params = github2json(params)
248248
api_endpoint = api_uri(api, endpoint)
249249
_headers = convert(Dict{String, String}, headers)
250250
!haskey(_headers, "User-Agent") && (_headers["User-Agent"] = "GitHub-jl")
251251

252-
r = with_retries(method = request_method, max_retries = max_retries) do
252+
r = with_retries(; method = request_method, max_retries, verbose) do
253253
if request_method == "GET"
254254
return HTTP.request(request_method, URIs.URI(api_endpoint, query = params), _headers;
255255
redirect = allowredirects, status_exception = false,
@@ -303,20 +303,20 @@ end
303303
extract_page_url(link) = match(r"<.*?>", link).match[2:end-1]
304304

305305
function github_paged_get(api, endpoint; page_limit = Inf, start_page = "", handle_error = true,
306-
auth = AnonymousAuth(), headers = Dict(), params = Dict(), max_retries = 5, options...)
306+
auth = AnonymousAuth(), headers = Dict(), params = Dict(), max_retries = 5, verbose = true, options...)
307307
authenticate_headers!(headers, auth)
308308
_headers = convert(Dict{String, String}, headers)
309309
!haskey(_headers, "User-Agent") && (_headers["User-Agent"] = "GitHub-jl")
310310

311311
# Helper function to make a get request with retries
312312
function make_request_with_retries(url, headers)
313-
return with_retries(method = "GET", max_retries = max_retries) do
313+
return with_retries(; method = "GET", max_retries, verbose) do
314314
HTTP.request("GET", url, headers; status_exception = false, retry = false)
315315
end
316316
end
317317

318318
if isempty(start_page)
319-
r = gh_get(api, endpoint; handle_error = handle_error, headers = _headers, params = params, auth=auth, max_retries=max_retries, options...)
319+
r = gh_get(api, endpoint; handle_error, headers = _headers, params, auth, max_retries, verbose, options...)
320320
else
321321
@assert isempty(params) "`start_page` kwarg is incompatible with `params` kwarg"
322322
r = make_request_with_retries(start_page, _headers)

0 commit comments

Comments
 (0)