GitHub
Connect Code Search to GitHub to index your GitHub repositories.
Prerequisites
Section titled “Prerequisites”- A GitHub account
- Access to repositories you want to index
- A Personal Access Token (PAT) or GitHub App
Creating a Personal Access Token
Section titled “Creating a Personal Access Token”-
Go to GitHub Settings → Developer Settings → Personal Access Tokens → Tokens (classic)
-
Give your token a descriptive name (e.g., “Code Search”)
-
Set an expiration (or “No expiration” for long-term use)
-
Select these scopes:
repo- Full control of private repositoriesread:org- Read organization membership (optional, for org repos)
-
Click Generate token
-
Copy the token immediately - you won’t be able to see it again!
Adding the Connection
Section titled “Adding the Connection”Via Web UI
Section titled “Via Web UI”- Open the Code Search web UI
- Go to Connections → Add Connection
- Fill in:
- Name:
GitHub(or any descriptive name) - Type:
GitHub - URL:
https://api.github.com - Token: Your Personal Access Token
- Name:
- Click Test Connection to verify
- Click Create
Via API
Section titled “Via API”curl -X POST "http://localhost:8080/api/v1/connections" \ -H "Content-Type: application/json" \ -d '{ "name": "GitHub", "type": "github", "url": "https://api.github.com", "token": "ghp_xxxxxxxxxxxx" }'Via Configuration File
Section titled “Via Configuration File”Add code hosts to your config.yaml:
codehosts: # The key is the connection name github: type: github token: "$CS_GITHUB_TOKEN" # Environment variable reference exclude_archived: true # Skip archived repos during syncWith environment variable:
export CS_GITHUB_TOKEN="ghp_xxxxxxxxxxxx"You can define multiple GitHub connections with different names:
codehosts: # Personal GitHub account github-personal: type: github token: "$CS_GITHUB_PERSONAL_TOKEN" exclude_archived: true
# Organization with different token github-work: type: github token: "$CS_GITHUB_WORK_TOKEN" exclude_archived: trueSyncing Repositories
Section titled “Syncing Repositories”After adding the connection:
- Click Sync on the connection card
- Code Search will discover your repositories
- Repositories are automatically queued for indexing
Filtering Repositories
Section titled “Filtering Repositories”You can exclude archived repositories:
codehosts: github: type: github token: "$CS_GITHUB_TOKEN" exclude_archived: true # Skip archived repos during syncToken Scopes
Section titled “Token Scopes”Minimum Required Scopes
Section titled “Minimum Required Scopes”| Scope | Purpose |
|---|---|
repo | Access to repositories (public and private) |
Optional Scopes
Section titled “Optional Scopes”| Scope | Purpose |
|---|---|
read:org | Access organization repositories |
read:user | Access user profile information |
workflow | Access GitHub Actions workflows |
Fine-Grained Tokens (Beta)
Section titled “Fine-Grained Tokens (Beta)”GitHub also supports fine-grained personal access tokens with more specific permissions:
-
Go to GitHub Settings → Developer Settings → Personal Access Tokens → Fine-grained tokens
-
Set repository access:
- All repositories or
- Only select repositories
-
Set permissions:
- Contents: Read-only (required)
- Metadata: Read-only (required)
GitHub Apps
Section titled “GitHub Apps”For organization-wide access, consider using a GitHub App:
- Create a GitHub App in your organization settings
- Grant it repository permissions
- Install the app on desired repositories
- Use the app’s private key for authentication
Rate Limits
Section titled “Rate Limits”GitHub API has rate limits:
| Authentication | Limit |
|---|---|
| Personal Access Token | 5,000 requests/hour |
| GitHub App | 15,000 requests/hour |
Code Search respects rate limits and will automatically slow down when approaching limits.
Troubleshooting
Section titled “Troubleshooting”Authentication failed
Section titled “Authentication failed”401 Unauthorized: Bad credentials- Verify the token is correct
- Check the token hasn’t expired
- Ensure the token has required scopes
Repository not found
Section titled “Repository not found”404 Not Found: Repository not found- Verify you have access to the repository
- Check the token has
reposcope - For organization repos, ensure you have org membership
Rate limit exceeded
Section titled “Rate limit exceeded”403 Forbidden: API rate limit exceeded- Wait for the rate limit to reset (check
X-RateLimit-Resetheader) - Use a GitHub App for higher rate limits
- Reduce sync frequency
Sync not discovering repos
Section titled “Sync not discovering repos”- Verify
read:orgscope for organization repositories - Check repository visibility settings
- Ensure the token owner has access to the repositories
Next Steps
Section titled “Next Steps”- GitHub Enterprise - For GitHub Enterprise Server
- Repositories - Managing synced repositories
- Configuration - Connection settings