Class RepositoryResource

Represents a GitHub repository resource with chainable async methods.

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

// Await directly to get repository info
const repo = await gh.org('github').repo('linguist');

// Get pull requests
const prs = await gh.org('github').repo('linguist').pullRequests({ state: 'open' });

// Navigate into a specific pull request
const files = await gh.org('github').repo('linguist').pullRequest(42).files();

// Get commits
const commits = await gh.org('github').repo('linguist').commits({ per_page: 10 });

// Get raw file content
const content = await gh.org('github').repo('linguist').raw('README.md');

Implements

Methods

  • Fetches contributors to this repository.

    GET /repos/{owner}/{repo}/contributors

    Parameters

    • Optionalparams: PaginationParams & { anon?: boolean }

      Optional filters: anon, per_page, page

    Returns Promise<
        GitHubPagedResponse<
            {
                avatar_url?: string;
                contributions: number;
                html_url?: string;
                id?: number;
                login?: string;
            },
        >,
    >

  • Creates a fork of this repository.

    POST /repos/{owner}/{repo}/forks

    Note: Forking is asynchronous on GitHub's side. The returned repository may not be fully ready immediately after this call returns.

    Parameters

    • Optionaldata: CreateForkData

      Optional: target organization, custom name, default-branch-only flag

    Returns Promise<GitHubRepository>

    The newly created fork

    // Fork into authenticated user's account
    const fork = await gh.repo('octocat', 'Hello-World').createFork();

    // Fork into an organization with a custom name
    const fork = await gh.repo('octocat', 'Hello-World').createFork({
    organization: 'my-org',
    name: 'hello-world-fork',
    });
  • Creates a webhook on this repository.

    POST /repos/{owner}/{repo}/hooks

    Parameters

    Returns Promise<GitHubWebhook>

    The created webhook

    const hook = await gh.repo('octocat', 'Hello-World').createWebhook({
    config: { url: 'https://example.com/webhook', content_type: 'json', secret: 'mysecret' },
    events: ['push', 'pull_request'],
    });
  • Deletes a webhook from this repository.

    DELETE /repos/{owner}/{repo}/hooks/{hook_id}

    Parameters

    • hookId: number

      The webhook ID to delete

    Returns Promise<void>

    await gh.repo('octocat', 'Hello-World').deleteWebhook(1);
    
  • Returns an IssueResource for a given issue number.

    The returned resource can be awaited directly to fetch issue info, or chained to access sub-resources (comments).

    Parameters

    • issueNumber: number

      The issue number within the repository

    Returns IssueResource

    A chainable issue resource

    const issue    = await gh.repo('octocat', 'Hello-World').issue(1);
    const comments = await gh.repo('octocat', 'Hello-World').issue(1).comments();
  • Fetches the raw text content of a file in this repository.

    Uses Accept: application/vnd.github.raw+json.

    GET /repos/{owner}/{repo}/contents/{filePath}

    Parameters

    • filePath: string

      Path to the file (e.g., 'src/index.ts')

    • Optionalparams: ContentParams

      Optional: ref (branch, tag, or commit SHA)

    Returns Promise<string>

    The raw file content as a string