# Self-managed GitHub and GitLab

> Connect GitHub Enterprise Server, self-managed GitLab, or your own GitHub App or GitLab application — creating the app, the instance URL, webhooks versus polling, testing delivery, and switching back.

Source: https://docs.sofiaspace.uz/integrations/github-gitlab-self-managed/

By default, Sofia Space connects to **github.com** and **gitlab.com** through Sofia Space's own GitHub App and GitLab application. Use **your own app** instead when:

- your code is on **GitHub Enterprise Server** or a **self-managed GitLab** instance, or
- your security team wants the integration to run under an app your organization owns and can review.

Once your own app is set up, connecting, linking commits and pull/merge requests to tasks, and disconnecting work exactly as described in [GitHub and GitLab](https://docs.sofiaspace.uz/integrations/github-gitlab.md).

**Who can do this:** Org Admins. **Where:** **Settings → Integrations → Code hosting**, then **Use your own app** on the GitHub or GitLab row. Available on every plan. You also need admin rights on the GitHub organization or GitLab instance (or group) where the app is created.

## Before you start: how events reach Sofia Space

Sofia Space learns about new commits and pull/merge requests in one of two ways. You choose under **How events reach Sofia Space**:

| Delivery | Choose it when | How fast |
| --- | --- | --- |
| **Webhooks — my server is reachable from the Git host** | Your Git server can send HTTPS requests out to Sofia Space. | Seconds. A daily check also catches anything a webhook missed. |
| **Polling — no inbound access to my server** | Your Git server can't send webhooks out, for example because of a firewall. | Sofia Space checks every 5 minutes. **Sync now** checks straight away. |

Either way, Sofia Space must be able to reach your Git server's address over **HTTPS** to read repositories and pull/merge requests.

## Set up your own GitHub App

1. In **Settings → Integrations → Code hosting**, choose **Use your own app** on the **GitHub** row.
2. Enter the **GitHub instance URL** — your GitHub Enterprise Server address, such as `https://github.acme.com`. Leave it empty for github.com.
3. Choose the delivery: **Webhooks** or **Polling**.
4. Create the app, in one of two ways:

**Let Sofia Space create it (recommended):**

1. Under **Create the GitHub App for me**, optionally enter the **GitHub organization** that should own the app. Leave it empty to create it under your personal account.
2. Choose **Create on GitHub**.
3. GitHub opens with a ready-made app: the right permissions, events and URLs. Confirm it there.
4. GitHub hands the credentials straight back. You'll see **GitHub App "{slug}" created and saved. You can now install it.**

The app asks only for **read** access to repository contents, metadata and pull requests, and listens for push and pull request events. It can't push code or change anything. You can rename it on GitHub afterwards.

**Or enter an existing app**, under **or enter an existing app**:

1. In GitHub, create a GitHub App. Use the **Callback / setup URL** and **Webhook URL** shown on the Sofia Space screen.
2. Give it read-only access to **Contents**, **Metadata** and **Pull requests**, and subscribe it to **Push** and **Pull request** events.
3. Back in Sofia Space, enter its **App ID**, **App slug**, **Private key (PEM)** and **Webhook secret**.
4. Choose **Save app**.

Then choose **Connect GitHub** and install the app on the repositories you want, as in [GitHub and GitLab](https://docs.sofiaspace.uz/integrations/github-gitlab.md).

## Set up your own GitLab application

1. In **Settings → Integrations → Code hosting**, choose **Use your own app** on the **GitLab** row.
2. Enter the **GitLab instance URL**, such as `https://gitlab.acme.com`. Leave it empty for gitlab.com.
3. Choose the delivery: **Webhooks** or **Polling**.
4. In GitLab, go to **Admin Area** (or your group) → **Applications** → **New application**.
5. Use the **Callback / setup URL** from the Sofia Space screen as the redirect URI, and grant the **`api`** scope.
6. Copy the **Application ID** and **Secret** from GitLab into Sofia Space.
7. Choose **Save app**.

Then choose **Connect GitLab**, sign in to your GitLab, and pick the group to connect. Every project in that group gets a webhook automatically (unless you chose polling).

### Self-managed GitLab blocks local webhooks by default

If your GitLab instance and Sofia Space are on the same private network, GitLab refuses to send webhooks there until an instance admin allows it: **Admin Area → Settings → Network → Outbound requests → Allow requests to the local network from webhooks and integrations**. Without it, deliveries fail silently. If you can't change this setting, choose **Polling**.

## Test webhook delivery

After saving, the GitHub or GitLab row shows your app (for example **App {slug} (id {id})** or **Application {clientId}**) and its delivery. Choose **Test webhook delivery**. Sofia Space asks the Git host to send a test event and shows whether it arrived. If it didn't, check the webhook URL in your app, your firewall, and — for GitLab — the local-network setting above, or switch to **Polling**.

## Change or remove your own app

- **Edit your app** changes the instance URL, delivery or credentials. Secret fields can be left empty: **Leave empty to keep the stored one.**
- **Switch back to Sofia Space's app** returns to the default app. Connections made through your own app must be connected again afterwards.

## Self-hosted Sofia Space

If Sofia Space itself is installed on your own servers, the **Code hosting** card may say **Runs through Sofia Space cloud**, and let you choose how webhooks arrive:

- **straight to this server**, if your Git host can reach your Sofia Space server, or
- **relayed via Sofia Space cloud (no inbound access needed)**, if it can't.

If the card says **No GitHub app is configured on this deployment yet** (or GitLab), use **Use your own app** as above. See [Self-hosting](https://docs.sofiaspace.uz/reference/self-hosting.md).

## Troubleshooting

**"Provider URLs must be https".** Enter the instance URL with `https://`.

**The instance URL is refused as internal.** On Sofia Space cloud, the address must be reachable on the public internet; private network addresses aren't accepted.

**Commits don't appear.** Make sure the task key (such as `WEB-142`) is in the commit message or the pull/merge request's title or description — branch names aren't read. Then choose **Sync now**.

**A connection shows Needs reconnect.** Its access expired or was revoked on the Git host. Disconnect it and connect again.

## What you can't do

- You can't connect Bitbucket or Azure DevOps.
- You can't use one app for both GitHub and GitLab; each has its own.
- You can't pick individual GitLab projects — you connect a group.
- Branch names are never read for task keys.

## Related

- [GitHub and GitLab](https://docs.sofiaspace.uz/integrations/github-gitlab.md)
- [Self-hosting](https://docs.sofiaspace.uz/reference/self-hosting.md)
