dependabit / github-client/src / GitHubClient
Class: GitHubClient
Defined in: packages/github-client/src/client.ts:83
Thin wrapper around Octokit that adds proactive rate-limit checking.
Remarks
This class is intentionally minimal — it exposes the underlying Octokit instance via GitHubClient.getOctokit so callers can use the full Octokit API without re-implementing every method.
Rate-limit state is cached per-instance; create one GitHubClient per GitHub token and reuse it to benefit from the cache.
Use When
Making authenticated GitHub API calls from the monitor or action packages where you need integrated rate-limit protection.
Avoid When
You need a full Octokit feature set with plugins (e.g., pagination, throttling) — instantiate Octokit directly and pass it to GitHubClient via the constructor is not possible; use the separate RateLimitHandler for advanced budget management.
Pitfalls
- Primary vs. secondary rate limits:
checkRateLimitonly checks the primary REST API rate limit. GitHub also enforces secondary (abuse) rate limits on burst patterns (many requests in a short window). A 403 withRetry-Afterheader indicates a secondary limit — this class does not handle that automatically. - Rate limit cache:
getLastRateLimitCheckreturns a potentially stale value; it is updated only whengetRateLimitorcheckRateLimitis called. Do not use it as a real-time indicator.
Example
import { GitHubClient } from '@dependabit/github-client';
const client = new GitHubClient({ auth: process.env.GITHUB_TOKEN });
const octokit = client.getOctokit();
const { data } = await octokit.rest.repos.get({ owner: 'my-org', repo: 'my-repo' });Constructors
Constructor
new GitHubClient(config?): GitHubClient;Defined in: packages/github-client/src/client.ts:89
Parameters
| Parameter | Type |
|---|---|
config | GitHubClientConfig |
Returns
GitHubClient
Methods
checkRateLimit()
checkRateLimit(): Promise<void>;Defined in: packages/github-client/src/client.ts:118
Check rate limit and throw if exceeded; log a warning when remaining is low.
Returns
Promise<void>
getLastRateLimitCheck()
getLastRateLimitCheck(): RateLimitInfo | undefined;Defined in: packages/github-client/src/client.ts:157
Get last known rate limit info (cached)
Returns
RateLimitInfo | undefined
getOctokit()
getOctokit(): Octokit & {
paginate: PaginateInterface;
} & paginateGraphQLInterface & Api & {
retry: {
retryRequest: (error, retries, retryAfter) => RequestError;
};
};Defined in: packages/github-client/src/client.ts:150
Get the underlying Octokit instance
Returns
Octokit & { paginate: PaginateInterface; } & paginateGraphQLInterface & Api & { retry: { retryRequest: (error, retries, retryAfter) => RequestError; }; }
getRateLimit()
getRateLimit(): Promise<RateLimitInfo>;Defined in: packages/github-client/src/client.ts:100
Get current rate limit status
Returns
Promise<RateLimitInfo>
withRateLimit()
withRateLimit<T>(fn): Promise<T>;Defined in: packages/github-client/src/client.ts:142
Execute a request with rate limit checking
Type Parameters
| Type Parameter |
|---|
T |
Parameters
| Parameter | Type |
|---|---|
fn | () => Promise<T> |
Returns
Promise<T>