Class GitHubClient

Main entry point for the GitHub REST API client.

const gh = new GitHubClient({ token: 'ghp_myPersonalAccessToken' });

const me = await gh.currentUser();
const user = await gh.user('octocat');
const repos = await gh.user('octocat').repos({ sort: 'updated' });
const org = await gh.org('github');
const repo = await gh.repo('octocat', 'Hello-World');
const prs = await gh.repo('octocat', 'Hello-World').pullRequests({ state: 'open' });
const commits = await gh.repo('octocat', 'Hello-World').commits({ per_page: 10 });
const results = await gh.searchRepos({ q: 'language:typescript stars:>1000' });

Constructors

Methods

  • Fetches the authenticated user's profile.

    GET /user

    Returns Promise<GitHubUser>

    The authenticated user object

    const me = await gh.currentUser();
    console.log(me.login); // 'octocat'
  • Subscribes to a client event.

    Type Parameters

    • K extends "request"

    Parameters

    Returns this

    gh.on('request', (event) => {
    console.log(`${event.method} ${event.url}${event.durationMs}ms`);
    if (event.error) console.error('Request failed:', event.error);
    });
  • Returns an OrganizationResource for a given GitHub organization, providing access to organization data and its repositories.

    The returned resource can be awaited directly to fetch organization info, or chained to access nested resources.

    Parameters

    • name: string

      The organization's login name (e.g., 'github')

    Returns OrganizationResource

    A chainable organization resource

    const org   = await gh.org('github');
    const repos = await gh.org('github').repos({ type: 'public' });
    const prs = await gh.org('github').repo('linguist').pullRequests({ state: 'open' });
  • Returns a RepositoryResource for a given owner and repository name.

    Shortcut that works for both user repositories and organization repositories.

    Parameters

    • owner: string

      The owner login (user or organization)

    • name: string

      The repository name

    Returns RepositoryResource

    A chainable repository resource

    const repo  = await gh.repo('octocat', 'Hello-World');
    const prs = await gh.repo('octocat', 'Hello-World').pullRequests();
  • Returns a UserResource for a given GitHub login, providing access to user data and their repositories.

    The returned resource can be awaited directly to fetch user info, or chained to access nested resources.

    Parameters

    • login: string

      The user's login name (e.g., 'octocat')

    Returns UserResource

    A chainable user resource

    const user  = await gh.user('octocat');
    const repos = await gh.user('octocat').repos({ sort: 'updated' });
    const pr = await gh.user('octocat').repo('Hello-World').pullRequest(1).files();