Link a Repository
Step-by-step guide to connecting a GitHub repository to your CodeSpar agent, including prerequisites, auto-webhook configuration, and verification.
Link a Repository
Connect a GitHub repository to your CodeSpar agent so it can monitor builds, review PRs, execute tasks, and orchestrate deploys.
Prerequisites
Before linking a repository, ensure:
GITHUB_TOKENis configured with at leastreposcope- Your CodeSpar instance is running and accessible
- At least one channel is connected (Slack, Discord, WhatsApp, or Telegram)
GitHub Token Scopes
| Scope | Required | Purpose |
|---|---|---|
repo | Yes | Read/write access to repository code, PRs, and issues |
admin:repo_hook | Recommended | Auto-configure webhooks when linking (without this, webhooks must be set up manually) |
workflow | Optional | Trigger and manage GitHub Actions workflows |
To create a token:
- Go to GitHub Settings > Developer Settings > Personal Access Tokens
- Click "Generate new token (classic)"
- Select the scopes listed above
- Copy the token and set it as
GITHUB_TOKENin your environment
Link via Chat Command
The simplest way to link a repository is via the @codespar link command from any connected channel.
Using owner/repo format
Using full URL
Expected Output
If auto-webhook is not available (missing WEBHOOK_BASE_URL or insufficient permissions):
Link via API
You can also link a repository programmatically via the REST API:
Response
Auto-Webhook Configuration
When WEBHOOK_BASE_URL is set and GITHUB_TOKEN has admin:repo_hook scope, CodeSpar automatically creates a GitHub webhook on the linked repository.
What Gets Configured
| Setting | Value |
|---|---|
| Payload URL | {WEBHOOK_BASE_URL}/webhooks/github |
| Content type | application/json |
| Events | push, pull_request, workflow_run |
| Active | true |
Manual Webhook Setup
If auto-configuration is not available, set up the webhook manually:
- Go to your repository on GitHub
- Navigate to Settings > Webhooks > Add webhook
- Configure as follows:
Verification
After linking, verify everything is working:
Check Status
Expected output:
Check Project Link via API
Test Webhook
Push a commit or open a PR on the linked repository. You should receive a notification in your connected channels (at L1+ autonomy).
If no notification arrives:
- Check the webhook delivery status in GitHub (Settings > Webhooks > Recent Deliveries)
- Verify
WEBHOOK_BASE_URLis publicly accessible - Check CodeSpar logs for webhook processing errors
Unlinking
To remove the repository link:
This removes the project link and the GitHub webhook (if it was auto-configured).
Troubleshooting
"Repository not found or insufficient permissions"
- Verify
GITHUB_TOKENhasreposcope - Confirm the repository exists and your token has access
- For private repos, ensure the token owner has at least read access
"Agent already has a linked project"
- Each agent can link to one repository at a time
- Unlink the current repo first:
@codespar unlink
Webhook not delivering
- Check GitHub webhook delivery logs for errors
- Verify
WEBHOOK_BASE_URLis reachable from the internet - Ensure the URL does not have a trailing slash
- Test connectivity:
curl https://your-instance.com/webhooks/github
Next Steps
- Review Pull Requests — Set up automated PR review
- Deploy Pipeline — Configure deployment orchestration
- Webhook API — Webhook processing details