# Connect your code

Connecting your code links a repository to a database in DBGorilla.
DBGorilla calls a database a component, and you link repositories one component
at a time.

A linked GitHub repository supports two operations: pull request reviews that
check the component's live database, and **Generate a PR**, which turns a
recommendation into a pull request.  A linked GitLab project supports merge
request reviews.

## Turn it on

For a GitHub repository, there are three steps:

1. Install the DBGorilla GitHub App on your GitHub account or organization.
2. Connect that installation to your DBGorilla workspace from
   **Admin › Integrations**.
3. Open the component, go to its **Settings** tab, and add the repository under
   **GitHub Repositories**.

[GitHub pull request reviews](/docs/integrations/github-pull-request-reviews/)
walks through each step.

For GitLab, a bot user and its tokens take the place of the App.
[GitLab merge request reviews](/docs/integrations/gitlab-merge-request-reviews/)
covers connecting a group, choosing projects, and linking each project under
**GitLab Projects** on the component's **Settings** tab.

## What the connection is used for

### Pull request reviews

Once the App or GitLab group is connected, reviews use the pull request diff.
Linking the repository to a component adds that component's schema, query
traffic and query plans to each review.
[Pull request reviews](/docs/integrations/pull-request-reviews/) shows what a
review contains.

### Generate a PR

**Generate a PR** on a recommendation pushes the change to a branch in the
linked GitHub repository and opens a pull request as `dbgorilla[bot]`.  You
review and merge it.

The button requires a GitHub repository linked to the component.  Until one is
linked, the button remains greyed out with the tooltip "Connect a GitHub
repository to this component first."

To generate pull requests for a component, link only GitHub repositories to it,
all from the same GitHub App installation.

[Generate a PR](/docs/using-dbgorilla/generate-a-pr/) covers using it.

## What the GitHub App can access

The App asks GitHub for these permissions on the repositories where it is
installed:

- **Contents**: write.  Generate a PR uses this permission to push its branch
  and commit.
- **Pull requests** and **Issues**: write.  Reviews use these permissions to post
  and update comments, and Generate a PR uses the pull requests permission to
  open its pull request.
- **Commit statuses**: write.  Reviews use this permission to publish the
  **DBGorilla Review** status.
- **Metadata**: read.

The App receives one webhook event, `pull_request`.

When you install it, GitHub lets you choose all repositories in the account or
only selected repositories.  DBGorilla can link only repositories covered by
that installation.

To stop using the connection,
[Turn it off](/docs/integrations/github-pull-request-reviews/#turn-it-off)
explains what uninstalling the App, disconnecting the installation and removing
a repository each do.

## Related

- [GitHub pull request reviews](/docs/integrations/github-pull-request-reviews/): every step of the GitHub setup.
- [GitLab merge request reviews](/docs/integrations/gitlab-merge-request-reviews/): the GitLab setup and its tokens.
- [Generate a PR](/docs/using-dbgorilla/generate-a-pr/): turning a recommendation into a pull request.
- [Security FAQ](/docs/security/faq/): security questions about DBGorilla, including pull requests.