Skip to main content
Sourcebot can sync code from GitHub.com, GitHub Enterprise Server, and GitHub Enterprise Cloud. If you’re not familiar with Sourcebot connections, please read that overview first.

Examples

Authenticating with GitHub

In order to index private repositories, you’ll need to authenticate with GitHub. Sourcebot supports the following mechanisms of authenticating a GitHub connection:
1

Register a new GitHub App

Register a new GitHub App and provide it with the following permissions:
  • “Contents” repository permissions (read)
  • “Metadata” repository permissions (read)
  • “Members” organization permissions (read)
  • “Email addresses” account permissions (read)
The pull request tools also need the “Pull requests” and “Issues” repository permissions (read).This can be the same GitHub App you’ve registered and configured as an external identity provider
2

Install the GitHub App

Install the GitHub App into the GitHub orgs that you want Sourcebot to be aware of. Sourcebot will only be able to index repos from orgs with the GitHub App installed.
3

Create a private key for the GitHub App

Create a private key for the GitHub App.
4

Define the GitHub App config in Sourcebot

Create a new apps object in the Sourcebot config file. The private key you created in the previous step must be passed in as a token.
5

You're done!

That’s it! Sourcebot will now use this GitHub App to authenticate when pulling repos for this connection.
1

Create PAT

Create a new fine-grained PAT here. Select the resource owner and the repositories that you want Sourcebot to have access to.Next, under “Repository permissions”, select permissions Contents and Metadata with access Read-only. The permissions should look like the following:GitHub PAT ScopeThe pull request tools also need permissions Pull requests and Issues with access Read-only.GitHub docs
2

Pass PAT into Sourcebot

Next, provide the PAT via a token which is referenced in the token field in the connection config object.The most common mechanism of doing this is defining an environment variable that holds the PAT:
3

You're done!

That’s it! Sourcebot will now use this PAT to authenticate when pulling repos for this connection.
1

Create PAT

Create a new PAT here and make sure you select the repo scope:GitHub PAT ScopeThe repo scope also covers the permissions for pull request tools.GitHub docs
2

Pass PAT into Sourcebot

Next, provide the PAT via a token which is referenced in the token field in the connection config object.The most common mechanism of doing this is defining an environment variable that holds the PAT:
3

You're done!

That’s it! Sourcebot will now use this PAT to authenticate when pulling repos for this connection.

Permissions for pull request tools

The pull request tools, get_commit_pull_requests and get_pull_request, read pull requests and their linked issues from GitHub. They are available in Ask Sourcebot and on the MCP server. They use the credential of the repo’s connection, which is your GitHub App or your personal access token, and never the account of the person who asks. Grant the credential these repository permissions, in addition to the ones for syncing code: How you grant them depends on the credential:
  • GitHub App: add both permissions under Repository permissions in the app’s settings. Adding permissions to an existing GitHub App does not take effect right away. An owner of each organization where the app is installed must approve the new permissions first.
  • Fine-grained personal access token: select Pull requests and Issues with access Read-only.
  • Personal access token (classic): no change is needed. The repo scope already covers both.
The tools count against the same GitHub rate limit as syncing, because they use the same credential. To leave room for syncing, the tools stop calling GitHub when less than 20% of the credential’s hourly limit for REST API requests is left. Until the limit resets, they return a codeHostRateLimited error that says how long to wait. A connection without a credential, such as one that syncs public repos only, still works for pull requests. The tools then call GitHub anonymously, within GitHub’s rate limit for anonymous requests. Linked issues need a credential, so get_pull_request reports them as unavailable.
The pull request tools support GitHub Enterprise Server, but they have not been tested against a live GitHub Enterprise Server instance. A GitHub Enterprise Server instance without TLS cannot use a GitHub App. Authenticate its connection with a personal access token instead.

Connecting to a custom GitHub host

To connect to a GitHub host other than github.com, provide the url property to your config:

Schema reference

schemas/v3/github.json

See also