> ## Documentation Index
> Fetch the complete documentation index at: https://sourcebot-brendan-scim-user-provisioning.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Linking code from Gitea

Sourcebot can sync code from Gitea Cloud, and self-hosted.

If you're not familiar with Sourcebot [connections](/docs/connections/indexing-your-code), please read that overview first.

## Examples

<AccordionGroup>
  <Accordion title="Sync individual repos">
    ```json theme={null}
    {
        "type": "gitea",
        "repos": [
            "sourcebot-dev/sourcebot",
            "getsentry/sentry",
            "torvalds/linux"
        ]
    }
    ```
  </Accordion>

  <Accordion title="Sync all repos in a organization">
    ```json theme={null}
    {
        "type": "gitea",
        "orgs": [
            "sourcebot-dev",
            "getsentry",
            "vercel"
        ]
    }
    ```
  </Accordion>

  <Accordion title="Sync all repos owned by a user">
    ```json theme={null}
    {
        "type": "gitea",
        "users": [
            "torvalds",
            "ggerganov"
        ]
    }
    ```
  </Accordion>

  <Accordion title="Exclude repos from syncing">
    ```json theme={null}
    {
        "type": "gitea",
        // Include all repos in my-org...
        "orgs": [
            "my-org"
        ],
        // ...except:
        "exclude": {
            // repos that are archived
            "archived": true,
            // repos that are forks
            "forks": true,
            // repos that match these glob patterns
            "repos": [
                "my-org/repo1",
                "my-org/repo2",
                "my-org/sub-org-1/**",
                "my-org/sub-org-*/**"
            ]
        }
    }
    ```
  </Accordion>
</AccordionGroup>

## Authenticating with Gitea

In order to index private repositories, you'll need to generate a Gitea access token. Generate a Gitea access token [here](http://gitea.com/user/settings/applications). At minimum, you'll need to select the `read:repository` scope. `read:user` and `read:organization` are required for the `user` and `org` fields of your config file:

<img src="https://mintcdn.com/sourcebot-brendan-scim-user-provisioning/-UyOnlbiaerOAUnR/images/gitea_pat_creation.png?fit=max&auto=format&n=-UyOnlbiaerOAUnR&q=85&s=2de77dd8b6e4572c4475e4ba823a16c1" alt="Gitea Access token creation" width="2034" height="1686" data-path="images/gitea_pat_creation.png" />

Next, provide the access token via an environment variable [token](/docs/configuration/config-file#tokens) which is referenced in the `token` property:

<Tabs>
  <Tab title="Environment Variable">
    1. Add the `token` property to your connection config:

    ```json theme={null}
    {
        "type": "gitea",
        "token": {
            // note: this env var can be named anything. It
            // doesn't need to be `GITEA_TOKEN`.
            "env": "GITEA_TOKEN"
        },
        // At least one of the following is required to specify which repos to sync:
        "repos": ["my-org/myRepo"],
        // "orgs": ["my-org"],
        // "users": ["my-user"]
    }
    ```

    2. Pass this environment variable each time you run Sourcebot:

    ```bash theme={null}
    docker run \
        -e GITEA_TOKEN=<PAT> \
        /* additional args */ \
        ghcr.io/sourcebot-dev/sourcebot:latest
    ```
  </Tab>
</Tabs>

## Connecting to a custom Gitea

To connect to a custom Gitea deployment, provide the `url` property to your config:

```json theme={null}
{
    "type": "gitea",
    "url": "https://gitea.example.com",
    // At least one of the following is required to specify which repos to sync:
    "repos": ["my-org/myRepo"],
    // "orgs": ["my-org"],
    // "users": ["my-user"]
}
```

## Schema reference

<Accordion title="Reference">
  [schemas/v3/gitea.json](https://github.com/sourcebot-dev/sourcebot/blob/main/schemas/v3/gitea.json)

  ```json theme={null}
  {
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "title": "GiteaConnectionConfig",
    "properties": {
      "type": {
        "const": "gitea",
        "description": "Gitea Configuration"
      },
      "token": {
        "description": "A Personal Access Token (PAT).",
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "env": {
                "type": "string",
                "description": "The name of the environment variable that contains the token."
              }
            },
            "required": [
              "env"
            ],
            "additionalProperties": false
          },
          {
            "type": "object",
            "properties": {
              "googleCloudSecret": {
                "type": "string",
                "description": "The resource name of a Google Cloud secret. Must be in the format `projects/<project-id>/secrets/<secret-name>/versions/<version-id>`. See https://cloud.google.com/secret-manager/docs/creating-and-accessing-secrets"
              }
            },
            "required": [
              "googleCloudSecret"
            ],
            "additionalProperties": false
          }
        ]
      },
      "url": {
        "type": "string",
        "format": "url",
        "default": "https://gitea.com",
        "description": "The URL of the Gitea host. Defaults to https://gitea.com",
        "examples": [
          "https://gitea.com",
          "https://gitea.example.com"
        ],
        "pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$"
      },
      "orgs": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "examples": [
          [
            "my-org-name"
          ]
        ],
        "description": "List of organizations to sync with. All repositories in the organization visible to the provided `token` (if any) will be synced, unless explicitly defined in the `exclude` property. If a `token` is provided, it must have the read:organization scope."
      },
      "repos": {
        "type": "array",
        "items": {
          "type": "string",
          "pattern": "^[\\w.-]+\\/[\\w.-]+$"
        },
        "description": "List of individual repositories to sync with. Expected to be formatted as '{orgName}/{repoName}' or '{userName}/{repoName}'."
      },
      "users": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "examples": [
          [
            "username-1",
            "username-2"
          ]
        ],
        "description": "List of users to sync with. All repositories that the user owns will be synced, unless explicitly defined in the `exclude` property. If a `token` is provided, it must have the read:user scope."
      },
      "exclude": {
        "type": "object",
        "properties": {
          "forks": {
            "type": "boolean",
            "default": false,
            "description": "Exclude forked repositories from syncing."
          },
          "archived": {
            "type": "boolean",
            "default": false,
            "description": "Exclude archived repositories from syncing."
          },
          "repos": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "default": [],
            "description": "List of individual repositories to exclude from syncing. Glob patterns are supported."
          }
        },
        "additionalProperties": false
      },
      "revisions": {
        "type": "object",
        "description": "The revisions (branches, tags) that should be included when indexing. The default branch (HEAD) is always indexed. A maximum of 64 revisions can be indexed, with any additional revisions being ignored.",
        "properties": {
          "branches": {
            "type": "array",
            "description": "List of branches to include when indexing. For a given repo, only the branches that exist on the repo's remote *and* match at least one of the provided `branches` will be indexed. The default branch (HEAD) is always indexed. Glob patterns are supported. A maximum of 64 branches can be indexed, with any additional branches being ignored.",
            "items": {
              "type": "string"
            },
            "examples": [
              [
                "main",
                "release/*"
              ],
              [
                "**"
              ]
            ],
            "default": []
          },
          "tags": {
            "type": "array",
            "description": "List of tags to include when indexing. For a given repo, only the tags that exist on the repo's remote *and* match at least one of the provided `tags` will be indexed. Glob patterns are supported. A maximum of 64 tags can be indexed, with any additional tags being ignored.",
            "items": {
              "type": "string"
            },
            "examples": [
              [
                "latest",
                "v2.*.*"
              ],
              [
                "**"
              ]
            ],
            "default": []
          }
        },
        "additionalProperties": false
      },
      "enforcePermissions": {
        "type": "boolean",
        "description": "Controls whether repository permissions are enforced for this connection. When `PERMISSION_SYNC_ENABLED` is false, this setting has no effect. Defaults to the value of `PERMISSION_SYNC_ENABLED`. See https://docs.sourcebot.dev/docs/features/permission-syncing"
      },
      "enforcePermissionsForPublicRepos": {
        "type": "boolean",
        "default": false,
        "description": "Controls whether repository permissions are enforced for public repositories in this connection. When true, public repositories are only visible to users with a linked account for this connection's code host. When false, public repositories are visible to all users. Has no effect when enforcePermissions is false. Defaults to false. See https://docs.sourcebot.dev/docs/features/permission-syncing"
      }
    },
    "required": [
      "type"
    ],
    "additionalProperties": false
  }
  ```
</Accordion>
