> ## Documentation Index
> Fetch the complete documentation index at: https://docs.demomatic.tech/llms.txt
> Use this file to discover all available pages before exploring further.

# GitHub Integration

> Automatically regenerate demo videos when a pull request is opened or merged in your GitHub repository.

The Demomatic GitHub integration watches your repository for pull request activity and triggers demo regeneration automatically. Use it to keep your demos up to date as your product evolves — without manually re-running generation after every code change.

## How it works

<Steps>
  <Step title="Install the GitHub App">
    Connect Demomatic to your GitHub account by installing the GitHub App on the repositories you want to watch.
  </Step>

  <Step title="Enable self-heal on a video">
    Mark individual videos with `self_heal_on_pr: true`. When a pull request event matches a connected repository, Demomatic regenerates those videos.
  </Step>

  <Step title="GitHub sends webhooks">
    When you open or merge a pull request, GitHub sends a webhook to Demomatic. Demomatic processes the event and queues demo regeneration jobs for matching videos.
  </Step>
</Steps>

## Install the GitHub App

Navigate to the GitHub begin-install endpoint while authenticated. Demomatic creates a short-lived install intent and redirects you to GitHub's app installation page:

```
GET /integrations/github/begin-install
```

After you approve the installation on GitHub, GitHub redirects back to Demomatic, which links the installed repositories to your account and redirects you to your settings page.

<Info>
  You must be signed in to your Demomatic account before initiating the install. The install intent expires after 15 minutes.
</Info>

## Enable auto-regeneration on a video

After installing the GitHub App, mark the videos you want to auto-update when a PR is opened or merged. Set `self_heal_on_pr` to `true` on the video:

```bash theme={null}
curl -X PUT https://api.demomatic.tech/videos/456 \
  -H "Authorization: Bearer dm_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{ "self_heal_on_pr": true }'
```

Only videos with `self_heal_on_pr: true` are included in GitHub-triggered regeneration runs.

## Webhook events handled

Demomatic processes the following GitHub webhook events:

| Event                       | What Demomatic does                                                                                   |
| --------------------------- | ----------------------------------------------------------------------------------------------------- |
| `pull_request`              | Triggers demo regeneration for matching videos when a PR is opened or merged.                         |
| `installation`              | Removes linked repositories when the GitHub App is uninstalled from an account.                       |
| `installation_repositories` | Adds or removes repository links when repositories are added to or removed from the app installation. |

## Disconnect the GitHub integration

You can disconnect the GitHub App at any time. Use either endpoint:

**DELETE with query parameter:**

```bash theme={null}
curl -X DELETE "https://api.demomatic.tech/integrations/github/install?domain_id=42" \
  -H "Authorization: Bearer dm_your_key_here"
```

**POST with request body:**

```bash theme={null}
curl -X POST https://api.demomatic.tech/integrations/github/disconnect \
  -H "Authorization: Bearer dm_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{ "domain_id": 42 }'
```

Both endpoints require a `domain_id` to scope the request to the correct account. Disconnecting removes the GitHub integration for the entire account associated with that domain.

<Warning>
  Disconnecting the GitHub integration stops all PR-triggered regeneration for your account. Videos with `self_heal_on_pr: true` will no longer update automatically until you reconnect.
</Warning>
