Class UserResource

Represents a GitHub user resource with chainable async methods.

Implements PromiseLike<GitHubUser> so it can be awaited directly to fetch user info, while also exposing sub-resource methods.

// Await directly to get user info
const user = await gh.user('octocat');

// Get the user's public repositories
const repos = await gh.user('octocat').repos({ sort: 'updated' });

// Navigate into a specific repository
const prs = await gh.user('octocat').repo('Hello-World').pullRequests();

Implements

Methods

  • Returns the repositories this user committed to, with commit counts, using the GitHub GraphQL API.

    POST https://api.github.com/graphql

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<RepoContribution[]>

    Array of repositories with their commit contribution counts

    const contribs = await gh.user('octocat').commitContributionsByRepo();
    // [{ repository: { nameWithOwner: 'octocat/Hello-World', url: '...' }, totalCount: 42 }, ...]
  • Fetches the contribution calendar for this user using the GitHub GraphQL API.

    Returns the same data that powers GitHub's annual contribution map (the green squares heatmap on a user's profile), including a count and color per day.

    Requires a token with the read:user scope.

    POST https://api.github.com/graphql

    Parameters

    • Optionalparams: ContributionMapParams

      Optional from / to ISO 8601 DateTime strings. When omitted, GitHub defaults to the past year.

    • Optionalsignal: AbortSignal

    Returns Promise<ContributionCalendar>

    The contribution calendar with weekly buckets of daily counts

    const calendar = await gh.user('octocat').contributionMap();
    console.log(calendar.totalContributions);

    const days = calendar.weeks.flatMap(w => w.contributionDays);
    // [{ date: '2024-01-01', contributionCount: 3, color: '#216e39' }, ...]

    // Specific date range
    const q1 = await gh.user('octocat').contributionMap({
    from: '2024-01-01T00:00:00Z',
    to: '2024-03-31T23:59:59Z',
    });
  • Returns the repositories this user opened issues in, with issue counts, using the GitHub GraphQL API.

    POST https://api.github.com/graphql

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<RepoContribution[]>

    Array of repositories with their issue contribution counts

    const contribs = await gh.user('octocat').issueContributionsByRepo();
    
  • Returns the pinned items (repositories and gists) on this user's GitHub profile, using the GitHub GraphQL API.

    Returns up to 6 items, matching what GitHub shows on a user's profile page.

    POST https://api.github.com/graphql

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<PinnedItem[]>

    Array of pinned items — each is either a PinnedRepository or a PinnedGist

    const pinned = await gh.user('octocat').pinnedItems();
    for (const item of pinned) {
    if ('nameWithOwner' in item) {
    console.log(item.nameWithOwner, item.stargazerCount); // repository
    } else {
    console.log(item.name); // gist
    }
    }
  • Lists public events performed by this user.

    GET /users/{username}/events/public

    Parameters

    • Optionalparams: EventsParams

      Optional pagination: per_page, page

    • Optionalsignal: AbortSignal

    Returns Promise<GitHubPagedResponse<GitHubEvent>>

    A paged response of public events

  • Returns the repositories this user opened pull requests in, with PR counts, using the GitHub GraphQL API.

    POST https://api.github.com/graphql

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<RepoContribution[]>

    Array of repositories with their pull request contribution counts

    const contribs = await gh.user('octocat').pullRequestContributionsByRepo();
    
  • Returns a RepositoryResource for a given repository under this user, providing access to all repository sub-resources.

    Parameters

    • name: string

      The repository name

    Returns RepositoryResource

    A chainable repository resource

    const repo    = await gh.user('octocat').repo('Hello-World');
    const content = await gh.user('octocat').repo('Hello-World').raw('README.md');
  • Lists the social accounts configured on this user's GitHub profile.

    GET /users/{username}/social_accounts

    Parameters

    • Optionalsignal: AbortSignal

    Returns Promise<SocialAccount[]>

    Array of social accounts with provider and url fields

    const accounts = await gh.user('ElJijuna').socialAccounts();
    // [{ provider: 'linkedin', url: 'https://...' }, { provider: 'npm', url: 'https://...' }]