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

  • Adds a collaborator to this repository.

    PUT /repos/{owner}/{repo}/collaborators/{username}

    Sends an invitation if the user is not yet a collaborator, or updates their permission level if they already are. Returns void in both cases.

    Parameters

    • username: string

      The GitHub login of the user to add

    • Optionaldata: AddCollaboratorData

      Optional permission level (defaults to 'push')

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<void>

    If the user is not found or access is denied

    await gh.repo('octocat', 'Hello-World').addCollaborator('hubot');
    await gh.repo('octocat', 'Hello-World').addCollaborator('hubot', { permission: 'maintain' });
  • Fetches a specific branch by name.

    GET /repos/{owner}/{repo}/branches/{branch}

    Parameters

    • name: string

      The branch name (e.g., 'main')

    • Optionalsignal: AbortSignal

    Returns Promise<GitHubBranch>

    The branch object

  • Cancels a workflow run in progress.

    POST /repos/{owner}/{repo}/actions/runs/{run_id}/cancel

    Parameters

    • runId: number

      The workflow run ID to cancel

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<void>

    If the run is not found or cannot be cancelled

    await gh.repo('octocat', 'Hello-World').cancelWorkflowRun(12345);
    
  • Fetches contributors to this repository.

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

    Parameters

    • Optionalparams: PaginationParams & { anon?: boolean }

      Optional filters: anon, per_page, page

    • Optionalsignal: AbortSignal

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

  • Creates a draft security advisory in this repository.

    POST /repos/{owner}/{repo}/security-advisories

    Parameters

    • data: CreateAdvisoryData

      Advisory data. summary and description are required.

    • Optionalsignal: AbortSignal

    Returns Promise<GitHubRepositoryAdvisory>

    The created advisory draft

    const advisory = await gh.repo('octocat', 'Hello-World').createAdvisory({
    summary: 'Remote code execution via crafted input',
    description: 'A vulnerability in...',
    severity: 'critical',
    });
  • 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

    • Optionalsignal: AbortSignal

    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 an issue in this repository.

    POST /repos/{owner}/{repo}/issues

    Parameters

    • data: CreateIssueData

      Issue data. title is required.

    • Optionalsignal: AbortSignal

    Returns Promise<GitHubIssue>

    The created issue

    const issue = await gh.repo('octocat', 'Hello-World').createIssue({
    title: 'Found a bug',
    body: 'Steps to reproduce...',
    labels: ['bug'],
    });
  • Creates a label in this repository.

    POST /repos/{owner}/{repo}/labels

    Parameters

    • data: CreateLabelData

      Label data: name and color are required

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<GitHubLabel>

    The created label

    If a label with that name already exists

    const label = await gh.repo('octocat', 'Hello-World').createLabel({ name: 'enhancement', color: '84b6eb' });
    
  • Creates a milestone in this repository.

    POST /repos/{owner}/{repo}/milestones

    Parameters

    • data: CreateMilestoneData

      Milestone data: title is required

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<GitHubMilestone>

    The created milestone

    const ms = await gh.repo('octocat', 'Hello-World').createMilestone({ title: 'v2.0', due_on: '2025-12-31T00:00:00Z' });
    
  • Creates a new release.

    POST /repos/{owner}/{repo}/releases

    Parameters

    • data: CreateReleaseData

      Release data: tag_name (required), name, body, draft, prerelease, target_commitish

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<GitHubRelease>

    The created release

    If the tag already has a release or access is denied

    const release = await gh.repo('octocat', 'Hello-World').createRelease({
    tag_name: 'v1.2.0',
    name: 'v1.2.0',
    body: '## Changelog\n- Fix bug #42',
    });
  • Creates a webhook on this repository.

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

    Parameters

    • data: CreateWebhookData

      Webhook configuration. config.url is required.

    • Optionalsignal: AbortSignal

    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 label.

    DELETE /repos/{owner}/{repo}/labels/{name}

    Parameters

    • name: string

      The label name to delete

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<void>

    If the label is not found

    await gh.repo('octocat', 'Hello-World').deleteLabel('wontfix');
    
  • Deletes a milestone.

    DELETE /repos/{owner}/{repo}/milestones/{milestone_number}

    Parameters

    • milestoneNumber: number

      The milestone number to delete

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<void>

    If the milestone is not found

    await gh.repo('octocat', 'Hello-World').deleteMilestone(1);
    
  • Deletes a release.

    DELETE /repos/{owner}/{repo}/releases/{release_id}

    Parameters

    • releaseId: number

      The release ID to delete

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<void>

    If the release is not found or access is denied

    await gh.repo('octocat', 'Hello-World').deleteRelease(1);
    
  • Deletes a webhook from this repository.

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

    Parameters

    • hookId: number

      The webhook ID to delete

    • Optionalsignal: AbortSignal

    Returns Promise<void>

    await gh.repo('octocat', 'Hello-World').deleteWebhook(1);
    
  • Fetches a git tree for this repository.

    GET /repos/{owner}/{repo}/git/trees/{tree_sha}

    The treeSha parameter accepts a tree SHA, a branch name, or a tag name.

    Parameters

    • treeSha: string

      Tree SHA, branch name (e.g. 'main'), or tag name

    • Optionalparams: GitTreeParams

      Optional: recursive: '1' to fetch the full tree recursively

    • Optionalsignal: AbortSignal

    Returns Promise<GitHubTree>

    The tree object with its entries

    // Get the tree of the 'main' branch
    const tree = await gh.repo('octocat', 'Hello-World').gitTree('main');

    // Get the full recursive tree for a specific SHA
    const fullTree = await gh.repo('octocat', 'Hello-World').gitTree('abc123', { recursive: '1' });
    console.log(fullTree.tree.map(item => item.path));
  • 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 a single label by name.

    GET /repos/{owner}/{repo}/labels/{name}

    Parameters

    • name: string

      The label name

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<GitHubLabel>

    The label object

    If the label is not found

    const label = await gh.repo('octocat', 'Hello-World').label('bug');
    
  • Returns the programming languages used in the repository and the number of bytes of code written in each language.

    GET /repos/{owner}/{repo}/languages

    Parameters

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<RepoLanguages>

    Object mapping language names to byte counts

    If the repository is not found or access is denied

    const langs = await gh.repo('facebook', 'react').languages();
    // { JavaScript: 1234567, TypeScript: 89012 }
  • Fetches a single milestone by number.

    GET /repos/{owner}/{repo}/milestones/{milestone_number}

    Parameters

    • milestoneNumber: number

      The milestone number

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<GitHubMilestone>

    The milestone object

    If the milestone is not found

    const milestone = await gh.repo('octocat', 'Hello-World').milestone(1);
    
  • Fetches the raw text content of multiple files in this repository.

    Uses Accept: application/vnd.github.raw+json for each file request.

    Files are fetched concurrently. If an individual file request fails, that file is omitted from the returned record and the remaining files are still returned.

    Parameters

    • filePaths: string[]

      Paths to the files (e.g., ['README.md', 'src/index.ts'])

    • Optionalparams: ContentParams

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

    • Optionalsignal: AbortSignal

    Returns Promise<Record<string, string>>

    A record mapping each fetched file path to its raw content

  • 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)

    • Optionalsignal: AbortSignal

    Returns Promise<string>

    The raw file content as a string

  • Fetches a single release by its numeric ID.

    GET /repos/{owner}/{repo}/releases/{release_id}

    Parameters

    • releaseId: number

      The release ID

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<GitHubRelease>

    The release object

    If the release is not found or access is denied

    const release = await gh.repo('octocat', 'Hello-World').release(1);
    
  • Removes a collaborator from this repository.

    DELETE /repos/{owner}/{repo}/collaborators/{username}

    Parameters

    • username: string

      The GitHub login of the user to remove

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<void>

    If the user is not found or access is denied

    await gh.repo('octocat', 'Hello-World').removeCollaborator('hubot');
    
  • Fetches a single repository security advisory by its GHSA ID.

    GET /repos/{owner}/{repo}/security-advisories/{ghsa_id}

    Parameters

    • ghsaId: string

      The GHSA identifier (e.g., 'GHSA-xxxx-xxxx-xxxx')

    • Optionalsignal: AbortSignal

    Returns Promise<GitHubRepositoryAdvisory>

    The repository advisory object

  • Fetches the repository topics.

    GET /repos/{owner}/{repo}/topics

    Parameters

    • Optionalsignal: AbortSignal

    Returns Promise<string[]>

    An array of topic strings

  • Triggers a workflow dispatch event.

    POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches

    Parameters

    • workflowId: string | number

      The workflow ID (number) or file name (e.g., 'ci.yml')

    • data: TriggerWorkflowData

      Dispatch data: ref is required; inputs are optional

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<void>

    If the workflow is not found or ref is invalid

    await gh.repo('octocat', 'Hello-World').triggerWorkflow('ci.yml', { ref: 'main' });
    await gh.repo('octocat', 'Hello-World').triggerWorkflow('ci.yml', { ref: 'main', inputs: { environment: 'staging' } });
  • Updates a label.

    PATCH /repos/{owner}/{repo}/labels/{name}

    Parameters

    • name: string

      The current label name

    • data: UpdateLabelData

      Fields to update: name, color, description

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<GitHubLabel>

    The updated label

    If the label is not found

    await gh.repo('octocat', 'Hello-World').updateLabel('bug', { color: 'ee0701' });
    
  • Updates a milestone.

    PATCH /repos/{owner}/{repo}/milestones/{milestone_number}

    Parameters

    • milestoneNumber: number

      The milestone number to update

    • data: UpdateMilestoneData

      Fields to update: title, state, description, due_on

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<GitHubMilestone>

    The updated milestone

    If the milestone is not found

    await gh.repo('octocat', 'Hello-World').updateMilestone(1, { state: 'closed' });
    
  • Updates an existing release.

    PATCH /repos/{owner}/{repo}/releases/{release_id}

    Parameters

    • releaseId: number

      The release ID to update

    • data: UpdateReleaseData

      Fields to update: tag_name, name, body, draft, prerelease

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<GitHubRelease>

    The updated release

    If the release is not found or access is denied

    await gh.repo('octocat', 'Hello-World').updateRelease(1, { draft: false });
    
  • Updates an existing webhook on this repository.

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

    Parameters

    • hookId: number

      The webhook ID

    • data: UpdateWebhookData

      Fields to update

    • Optionalsignal: AbortSignal

    Returns Promise<GitHubWebhook>

    The updated webhook

    const hook = await gh.repo('octocat', 'Hello-World').updateWebhook(1, {
    active: false,
    add_events: ['issues'],
    });
  • Fetches a single workflow run by its ID.

    GET /repos/{owner}/{repo}/actions/runs/{run_id}

    Parameters

    • runId: number

      The workflow run ID

    • Optionalsignal: AbortSignal

      Optional AbortSignal to cancel the request

    Returns Promise<GitHubWorkflowRun>

    The workflow run object

    If the run is not found

    const run = await gh.repo('octocat', 'Hello-World').workflowRun(12345);
    
  • Lists workflow runs for this repository.

    GET /repos/{owner}/{repo}/actions/runs

    Returns the raw GitHub Actions response envelope including total_count and the workflow_runs array. Use params.per_page to limit how many runs are fetched (default GitHub: 30, max: 100).

    Parameters

    • Optionalparams: WorkflowRunsParams

      Optional filters: branch, event, status, actor, created, per_page, page

    • Optionalsignal: AbortSignal

    Returns Promise<GitHubWorkflowRunsResponse>

    Response envelope with total_count and workflow_runs

    const { total_count, workflow_runs } = await gh.repo('octocat', 'Hello-World').workflowRuns({ per_page: 10 });
    const lastRun = workflow_runs[0];
    console.log(lastRun.conclusion); // 'success' | 'failure' | null ...