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

# Gitea plugin

> Git hosting on Gitea, Forgejo and Codeberg (gitea.com or any self-hosted instance): repositories, branches and protections, commits and statuses, files, tags and releases, issues, comments, labels, milestones and time tracking, pull requests and reviews, wikis, projects, Actions (runs, jobs, artifacts, secrets, variables, runners, workflows), packages, organizations and teams, users, keys, notifications and site admin, plus signed webhooks for pushes, issues, pull requests, reviews and releases (530 operations).

Use **Gitea** through Corsair: one client, typed API calls, and incoming webhooks.

Gitea is self-hosted, so each account stores two things: an access token
and the `instance_url` of the site it belongs to (`https://gitea.com`,
`https://codeberg.org` or your own `https://git.example.com`, with or
without `/api/v1`). Forgejo and Codeberg serve the same API v1, so the
plugin works there too. A route an older or forked server lacks answers
404 `page not found`, and a body field it doesn't know is ignored rather
than refused: the stale-edit check `content_version` on `issues.update`
and `pulls.update` only works on servers that include go-gitea/gitea#37035. Create the token at
`<instance>/user/settings/applications` with the scopes you need
(read:/write: repository, issue, organization, user, notification,
package, misc, and admin for the site-admin routes); it is sent as
`Authorization: token <token>`. SDK users can pass `instanceUrl` in the
plugin options instead of storing it; with a stored token it must match the
stored instance (the token is never sent to another host), else pass `key`
too.

* **Repository routes** take `owner` and `repo`. Branches, refs, tags and
  file paths keep their slashes (`feature/login`, `docs/README.md`).
* **Lists** page with `page` (1-based) and `limit`; the plugin sends 50
  when `limit` is left out. Gitea clamps `limit` to the instance's
  MAX\_RESPONSE\_ITEMS (50 unless an admin lowered it), so a short page doesn't
  mean the list ended. Paged lists return `{ items, next_page }`, with
  `next_page` set while a page has entries: step `page` until it is null.
* **Files.** `contents.get` returns a file's metadata and base64 content;
  `contents.raw`, `contents.media`, `repos.downloadArchive` and the Actions
  log and artifact downloads return the bytes as a file. Diffs, patches,
  signing keys and rendered markdown come back as `{ text }`.
* **Risk.** Every delete is `destructive`, as are site-admin changes to
  users and organizations, merging a pull request, moving a branch to another
  commit (`branches.setCommit`), applying a patch, transfers, renaming an
  organization and overwriting Actions secrets. `admin.*` needs a site-admin
  token.
* **Webhooks.** Register one with `webhooks.create` (or `orgs.hooks.create`,
  `user.hooks.create`, `admin.hooks.create`) using `type: gitea` and a
  `config.secret`, point it at your Corsair webhook URL, and give the plugin
  the same secret as `webhookSecret` (or store it as the account's webhook
  signature). Deliveries are checked against `X-Gitea-Signature` (HMAC-SHA256
  of the body) and routed by `X-Gitea-Event-Type` to `push`, `refCreated`,
  `refDeleted`, `fork`, `issues`, `issueComment`, `pullRequest`,
  `pullRequestReview`, `release`, `wiki`, `repository`, `status`,
  `workflowRun`, `workflowJob` and `package`.
* Not wrapped: four routes the swagger marks deprecated (each has a
  replacement), and `users.tokens` list, create and delete, which Gitea only
  accepts with the account password (BasicAuth), not a token.

**What you get:**

* 530 typed API operations
* 15 incoming webhook event types

## Setup

**1. Install**

```bash npm theme={null}
npm install corsair @corsair-dev/gitea better-sqlite3
npm install --save-dev @types/better-sqlite3
```

```bash yarn theme={null}
yarn add corsair @corsair-dev/gitea better-sqlite3
yarn add --dev @types/better-sqlite3
```

```bash pnpm theme={null}
pnpm install corsair @corsair-dev/gitea better-sqlite3
pnpm install --save-dev @types/better-sqlite3
```

```bash bun theme={null}
bun add corsair @corsair-dev/gitea better-sqlite3
bun add --dev @types/better-sqlite3
```

**2. Add the plugin**

```ts corsair.ts theme={null}
import Database from 'better-sqlite3';
import { createCorsair } from 'corsair';
import { gitea } from '@corsair-dev/gitea';

export const corsair = createCorsair({
	plugins: [
		gitea(),
	],
	database: new Database('corsair.db'),
	kek: process.env.CORSAIR_KEK!,
	multiTenancy: true,
	hub: {
		projectApiKey: process.env.CORSAIR_API_KEY!,
		signingSecret: process.env.CORSAIR_SIGNING_SECRET!,
	},
});
```

With `multiTenancy: true`, scope calls with `corsair.withTenant(id)`. See [Quick start](https://docs.corsair.dev/quick-start.md) for KEK + Hub keys, and [Multi-tenancy](https://docs.corsair.dev/concepts/multi-tenancy.md) for account isolation.

**3. Choose authentication**

> [tab] API Key (Recommended)
>
> Store the Gitea API key before the first call: `pnpm corsair setup --plugin=gitea --tenant=acme api_key=<your-key>` (leave out `--tenant` without `multiTenancy`), or pass it as `key` in the plugin options. With Hub, each tenant enters their own key on the connect page. See [API key auth](https://docs.corsair.dev/concepts/api-key).
>
> ```ts theme={null}
> gitea()
> ```
>
> More: [API Key](https://docs.corsair.dev/concepts/api-key)

**4. Connect a tenant**

Mint a connect link and send the tenant to it. Hub hosts the page and delivers the result to your app — see [Connect / OAuth](https://docs.corsair.dev/management/connect).

```ts theme={null}
const { connectUrl } = await corsair.manage.connect.createLink({
	plugin: 'gitea',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**Get a repository**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.gitea.api.repos.get({ owner: 'gitea', repo: 'tea' });
```

**Create an issue**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.gitea.api.issues.create({
	owner: 'gitea',
	repo: 'tea',
	title: 'Release notes cover the breaking change',
	body: 'The 2.0 migration guide does not mention the renamed config keys.',
});
```

See the full list on the [API](https://docs.corsair.dev/plugins/gitea/api.md) page.

## Webhooks

This plugin registers **15** webhook event types. Configure the provider to POST to your Corsair HTTP handler, then use `webhookHooks` on the plugin factory.

See [Webhooks](https://docs.corsair.dev/plugins/gitea/webhooks.md) for every event path and payload shape, and [Webhooks concept](https://docs.corsair.dev/concepts/webhooks.md) for routing.

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/gitea/api.md)
>
> Every `gitea.api.*` operation with input and output types.

> [card] [Webhooks](https://docs.corsair.dev/plugins/gitea/webhooks.md)
>
> Event paths, payloads, and `webhookHooks` examples.

> [card] [Connect / OAuth](https://docs.corsair.dev/management/connect)
>
> createLink, Hub delivery, and tenant connect flows.

> [card] [Use with agents](https://docs.corsair.dev/mcp-adapters/mcp-adapters)
>
> Expose this plugin's operations as MCP tools.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.