PR/Code Review

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).

    1. Go to Settings > Developer settings > Personal access tokens > Fine-grained tokens
    2. Click Generate new token
    3. Configure:
    SettingValue
    Token nameopenclaw-review
    Expiration90 days (or your preference)
    Repository accessOnly select repositories
    PermissionsPull requests: Read & Write
    Contents: Read
    Commit statuses: Read & Write
    1. Click Generate token and copy it immediately.
    Terminal
    export GITHUB_TOKEN=ghp_your_token_here

    Token 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.

    openclaw.config.yaml

    Set Up the Webhook

    Webhooks notify OpenClaw when a PR is opened or updated.

    1. Go to your repo: Settings > Webhooks > Add webhook
    2. Configure:
    FieldValue
    Payload URLhttps://your-gateway.example.com/webhooks/github
    Content typeapplication/json
    SecretGenerate a random string and save it
    EventsSelect "Pull requests"
    1. Add the webhook secret to your config:
    openclaw.config.yaml

    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.

    Terminal
    openclaw code-review test-connection --repo my-app
    Connection Test

    Trigger a Test Review

    Open a test PR (or use an existing one) to see the full review flow.

    Terminal
    openclaw code-review run --repo my-app --pr 42
    Test Review

    You can connect multiple repositories in a single config. Each repo can have its own rules.

    Multiple repos

    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.

    Knowledge Check

    Why does OpenClaw use fine-grained tokens instead of classic personal access tokens?