---
title: "GitHub"
description: "REST v3 for everything except review threads, which need GraphQL for their resolved flag. GitHub Enterprise works through baseURL."
canonical_url: "https://forges.agntn.dev/platforms/github"
---
# GitHub

> REST v3 for everything except review threads, which need GraphQL for their resolved flag. GitHub Enterprise works through baseURL.

<platform-facts platform="github">



</platform-facts>

## Address it

```ts
import { createProvider } from "@agntn/forges";

const github = await createProvider("github"); // GH_TOKEN, GITHUB_TOKEN, then gh auth token
const enterprise = await createProvider("github", { baseURL: "https://github.example.com/api/v3" });
```

`baseURL` is taken as given, so spell out `/api/v3` for Enterprise. The token chain asks `gh` for the host in `baseURL`, not for github.com.

## What it reads

<table>
<thead>
  <tr>
    <th>
      Resource
    </th>
    
    <th>
      Endpoint
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      repos
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo
      </code>
      
      , <code>
        GET /orgs/:owner/repos
      </code>
      
      , <code>
        GET /users/:owner/repos
      </code>
      
      , <code>
        GET /user/repos
      </code>
      
       for the viewer, <code>
        GET …/tags
      </code>
      
      , <code>
        GET …/git/trees/:sha
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      issues
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/issues
      </code>
      
      , <code>
        GET /search/issues
      </code>
      
      , <code>
        POST /repos/:owner/:repo/issues
      </code>
      
      , <code>
        PATCH …/issues/:number
      </code>
      
      , <code>
        …/issues/:number/comments
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      pull requests
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/pulls
      </code>
      
      , <code>
        …/pulls/:number/files
      </code>
      
      , <code>
        …/commits/:sha/check-runs
      </code>
      
      , <code>
        …/commits/:sha/status
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      issue and pull request edits
    </td>
    
    <td>
      <code>
        PATCH …/pulls/:number
      </code>
      
      , <code>
        POST
      </code>
      
      /<code>
        DELETE …/issues/:number/assignees
      </code>
      
      , <code>
        POST …/issues/:number/labels
      </code>
      
      , <code>
        DELETE …/labels/:name
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      pull request merges
    </td>
    
    <td>
      <code>
        PUT …/pulls/:number/merge
      </code>
      
      , then a read of the pull request
    </td>
  </tr>
  
  <tr>
    <td>
      commits
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/commits
      </code>
      
      , <code>
        …/commits/:sha
      </code>
      
      , <code>
        …/compare/:base...:head
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      commit checks
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/commits/:ref
      </code>
      
       for the SHA, then <code>
        …/commits/:sha/status
      </code>
      
      , <code>
        …/commits/:sha/check-runs
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      CI runs
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/actions/runs
      </code>
      
      , <code>
        …/actions/workflows/:workflow/runs
      </code>
      
      , <code>
        …/actions/runs/:id/jobs
      </code>
      
      , <code>
        …/actions/jobs/:id
      </code>
      
      , <code>
        …/actions/jobs/:id/logs
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      jobs that never started
    </td>
    
    <td>
      <code>
        GET …/check-runs/:id/annotations
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      releases
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/releases
      </code>
      
      , <code>
        …/releases/tags/:tag
      </code>
      
      , <code>
        POST …/releases
      </code>
      
      , <code>
        PATCH …/releases/:id
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      reactions
    </td>
    
    <td>
      <code>
        GET …/issues/:number/reactions
      </code>
      
      , <code>
        …/issues/comments/:id/reactions
      </code>
      
       next to a read of the issue and the comment
    </td>
  </tr>
  
  <tr>
    <td>
      issue types and fields
    </td>
    
    <td>
      <code>
        GET …/issue-types
      </code>
      
      , <code>
        GET /orgs/:owner/issue-fields
      </code>
      
      , both in <code>
        POST …/issues
      </code>
      
      , <code>
        PATCH
      </code>
      
       type, <code>
        POST
      </code>
      
      /<code>
        DELETE …/issue-field-values
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      timeline events
    </td>
    
    <td>
      <code>
        GET …/issues/:number/timeline
      </code>
      
       for issues and pull requests alike
    </td>
  </tr>
  
  <tr>
    <td>
      sub-issues
    </td>
    
    <td>
      <code>
        GET
      </code>
      
      /<code>
        POST …/issues/:number/sub_issues
      </code>
      
      , <code>
        DELETE …/issues/:number/sub_issue
      </code>
      
      , next to a read of the parent and, for a write, of the child
    </td>
  </tr>
  
  <tr>
    <td>
      threads
    </td>
    
    <td>
      GraphQL <code>
        reviewThreads
      </code>
      
      , REST <code>
        POST …/pulls/:number/comments/:id/replies
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      templates
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/contents/.github/…
      </code>
      
      , then <code>
        :owner/.github
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      code
    </td>
    
    <td>
      <code>
        GET /search/code
      </code>
    </td>
  </tr>
</tbody>
</table>

Pagination reads the `Link` header, and `nextCursor` carries its `rel="next"` URL.

## What comes back

`Repository.parent` from `parent`, `viewerPermission` from `permissions` when the token has any. `merge` from the `allow_*_merge` flags, `squash_merge_commit_title`, `squash_merge_commit_message` and `delete_branch_on_merge`, which GitHub returns only with push access and never on a list, so anything less is `null`. With pull requests off, `methods` is empty, push access or not. `Issue` from `/issues` with pull requests filtered out by the missing `pull_request` key. `PullRequest.mergeable` is `null` while GitHub is still computing it, which it does lazily, so the first read after a push often says `null`. `Commit.filesComplete` is `true` when GitHub confirms a complete file list, collected up to its cap of 3 000 files.

Templates: repository files first, then the owner's `.github` repository with `scope: "owner"` and `inherited: true`. Issue and pull request overrides resolve on their own. A host without the `x-github-enterprise-version` header that is not github.com is treated as repository scope only.

## Gotchas

- Review threads need a token. GraphQL has no anonymous access and REST has no resolved flag, so there is no anonymous thread list to be had.
- Anonymous reads share sixty requests an hour per address. A 403 with a rate limit header is a `RateLimitError` with `retryAfter`, not a `PermissionError`.
- `/issues` returns pull requests too. Filtered out here. Search returns both, and `pullRequests.search` keeps the ones with `pull_request`.
- Code search: `incomplete` goes true on a search timeout, when scope enforcement drops a stray row, or past the cap of 1 000 results.
- Issue search keeps GitHub's qualifier syntax. `label:bug is:open` works here and is plain text on GitLab and Gitea.
- `releases/tags/:tag` serves published releases only. A draft is found by walking the newest releases, five pages of a hundred, and a draft older than that is a `NotFoundError` by tag.

## Where it lives

`src/providers/github.ts`. Also the template for a new provider. Copy it, do not start from scratch.


## Sitemap

See the full [sitemap](https://forges.agntn.dev/sitemap.md) for all pages.
