Lesson 2 of 5
Connecting Your Repository
Estimated time: 7 minutes
Connecting Your Repository
In this lesson, you'll connect OpenClaw to your GitHub or GitLab repository so it can receive webhook events for new pull requests and post review comments back.
Prerequisites
Connection Architecture
Your Repository OpenClaw Review Output
┌──────────────┐ ┌──────────┐ ┌──────────────────┐
│ PR Opened │──webhook──>│ Gateway │ │ Inline comments │
│ PR Updated │ │ │──review───>│ Status check │
│ PR Synced │ │ Fetches │ │ Summary comment │
└──────────────┘ │ diff via │ └──────────────────┘
│ API │
└──────────┘
OpenClaw needs two things: a webhook to know when PRs are opened, and API access to read the diff and post comments.
Create an Access Token
OpenClaw needs API access to read PR diffs and post review comments.
Create a fine-grained personal access token (recommended over classic tokens).
- Go to Settings > Developer settings > Personal access tokens > Fine-grained tokens
- Click Generate new token
- Configure:
| Setting | Value |
|---|---|
| Token name | openclaw-review |
| Expiration | 90 days (or your preference) |
| Repository access | Only select repositories |
| Permissions | Pull requests: Read & Write |
| Contents: Read | |
| Commit statuses: Read & Write |
- Click Generate token and copy it immediately.
export GITHUB_TOKEN=ghp_your_token_hereToken Security
Never commit your token to the repository. Store it in your environment variables or a secrets manager. OpenClaw reads it from GITHUB_TOKEN in your environment.
Configure the Repository Connection
Add your repository to OpenClaw's configuration.
Set Up the Webhook
Webhooks notify OpenClaw when a PR is opened or updated.
- Go to your repo: Settings > Webhooks > Add webhook
- Configure:
| Field | Value |
|---|---|
| Payload URL | https://your-gateway.example.com/webhooks/github |
| Content type | application/json |
| Secret | Generate a random string and save it |
| Events | Select "Pull requests" |
- Add the webhook secret to your config:
Testing Webhooks Locally
During development, use a tunneling service to expose your local Gateway:
openclaw tunnel start --port 3100
This gives you a public URL you can use as the webhook payload URL while testing.
Test the Connection
Verify everything is wired up correctly.
openclaw code-review test-connection --repo my-appTrigger a Test Review
Open a test PR (or use an existing one) to see the full review flow.
openclaw code-review run --repo my-app --pr 42You can connect multiple repositories in a single config. Each repo can have its own rules.
For organizations, a GitHub App is more secure than a personal access token because it has scoped permissions and doesn't tie access to an individual account. See the GitHub Apps documentation for setup instructions. OpenClaw supports both authentication methods.
Why does OpenClaw use fine-grained tokens instead of classic personal access tokens?