aiwg
Version:
Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo
173 lines • 5.02 kB
TypeScript
/**
* GitHubAPIStub provides mock GitHub API functionality for testing.
*
* Simulates GitHub API interactions without making real network requests.
* Supports configurable responses, error injection, rate limiting, and request tracking.
*
* @example
* ```typescript
* const github = new GitHubAPIStub();
*
* // Create a mock issue
* const issue = await github.createIssue('Bug: Fix login', 'Login not working');
*
* // Configure custom response
* github.setResponse('/repos/owner/repo/issues', 'GET', { issues: [] });
*
* // Inject error for testing
* github.injectError('/repos/owner/repo/pulls', new Error('API Error'));
*
* // Check request history
* const requests = github.getRequestHistory();
* ```
*/
export interface GitHubResponse {
data: any;
status: number;
headers: Record<string, string>;
}
export interface Issue {
number: number;
title: string;
body: string;
state: 'open' | 'closed';
labels: Label[];
createdAt: string;
updatedAt: string;
}
export interface PullRequest {
number: number;
title: string;
head: string;
base: string;
state: 'open' | 'closed' | 'merged';
createdAt: string;
updatedAt?: string;
}
export interface Label {
name: string;
color: string;
description?: string;
}
export interface Request {
endpoint: string;
method: string;
body?: any;
timestamp: number;
}
export interface IssueListOptions {
state?: 'open' | 'closed' | 'all';
labels?: string[];
page?: number;
per_page?: number;
}
export declare class GitHubAPIStub {
private responses;
private requestHistory;
private issues;
private pullRequests;
private issueCounter;
private prCounter;
private rateLimitRemaining;
private rateLimitReset;
private injectedErrors;
/**
* Set a custom response for a specific endpoint and method.
*
* @param endpoint - API endpoint path
* @param method - HTTP method (GET, POST, PUT, DELETE, etc.)
* @param response - Response data
* @param statusCode - HTTP status code (default: 200)
*/
setResponse(endpoint: string, method: string, response: any, statusCode?: number): void;
/**
* Configure rate limit for testing rate limit handling.
*
* @param remaining - Number of requests remaining
* @param resetTime - Unix timestamp when rate limit resets (default: 1 hour from now)
*/
setRateLimit(remaining: number, resetTime?: number): void;
/**
* Make a simulated API request.
*
* @param endpoint - API endpoint path
* @param method - HTTP method
* @param body - Request body (optional)
* @returns GitHub API response
*/
request(endpoint: string, method: string, body?: any): Promise<GitHubResponse>;
/**
* Create a new issue.
*
* @param title - Issue title
* @param body - Issue body (optional)
* @param labels - Label names to apply (optional)
* @returns Created issue
*/
createIssue(title: string, body?: string, labels?: string[]): Promise<Issue>;
/**
* Get an issue by number.
*
* @param number - Issue number
* @returns Issue data
* @throws Error if issue not found
*/
getIssue(number: number): Promise<Issue>;
/**
* List issues with optional filtering.
*
* @param options - Filter options
* @returns Array of issues
*/
listIssues(options?: IssueListOptions): Promise<Issue[]>;
/**
* Create a new pull request.
*
* @param title - PR title
* @param head - Head branch name
* @param base - Base branch name
* @returns Created pull request
*/
createPullRequest(title: string, head: string, base: string): Promise<PullRequest>;
/**
* Add labels to an issue.
*
* @param issueNumber - Issue number
* @param labels - Label names to add
* @throws Error if issue not found
*/
addLabel(issueNumber: number, labels: string[]): Promise<void>;
/**
* Reset the stub to initial state.
* Clears all issues, pull requests, responses, and request history.
*/
reset(): void;
/**
* Get the history of all requests made to the stub.
*
* @returns Array of requests in chronological order
*/
getRequestHistory(): Request[];
/**
* Inject an error for a specific endpoint.
* The next request to this endpoint will throw the specified error.
*
* @param endpoint - API endpoint path
* @param error - Error to throw
*/
injectError(endpoint: string, error: Error): void;
/**
* Inject a rate limit error.
* Sets rate limit to 0, causing subsequent requests to return 403.
*/
injectRateLimitError(): void;
/**
* Generate a unique key for response mapping.
*/
private getResponseKey;
/**
* Generate rate limit headers.
*/
private getRateLimitHeaders;
}
//# sourceMappingURL=github-stub.d.ts.map