MCPcopy Create free account
hub / github.com/github/gh-aw / logRateLimitFromResponse

Function logRateLimitFromResponse

actions/setup/js/github_rate_limit_logger.cjs:90–117  ·  view source on GitHub ↗

* Log GitHub API rate-limit information extracted from a REST response's * headers. Call this immediately after any `github.rest.*.*()` call to * record the current rate-limit state without an extra API round-trip. * * @param {{ headers?: Record }} response - The git

(response, operation)

Source from the content-addressed store, hash-verified

88 * @param {string} operation - Human-readable description of the operation (e.g. "issues.listComments")
89 */
90function logRateLimitFromResponse(response, operation) {
91 const headers = response?.headers;
92 if (!headers) return;
93
94 const limit = headers["x-ratelimit-limit"];
95 const remaining = headers["x-ratelimit-remaining"];
96 const reset = headers["x-ratelimit-reset"];
97 const used = headers["x-ratelimit-used"];
98 const resource = headers["x-ratelimit-resource"];
99
100 // Skip if no rate-limit headers are present (e.g. GraphQL responses)
101 if (!limit && !remaining && !reset) return;
102
103 /** @type {Record<string, unknown>} */
104 const entry = {
105 timestamp: new Date().toISOString(),
106 source: "response_headers",
107 operation,
108 };
109
110 if (resource) entry.resource = resource;
111 if (limit !== undefined) entry.limit = parseInt(limit, 10);
112 if (remaining !== undefined) entry.remaining = parseInt(remaining, 10);
113 if (used !== undefined) entry.used = parseInt(used, 10);
114 if (reset) entry.reset = parseResetTimestamp(reset);
115
116 appendEntry(entry);
117}
118
119/**
120 * Fetch the current GitHub API rate-limit information via the rate-limit API

Callers 3

wrapperFunction · 0.85
checkRateLimitHeadroomFunction · 0.85

Calls 2

parseResetTimestampFunction · 0.85
appendEntryFunction · 0.85

Tested by

no test coverage detected