---
title: "Gitea"
description: "API v1 with limit instead of per_page, empty strings and nulls where fields are missing, and Codeberg or any Forgejo instance through baseURL."
canonical_url: "https://forges.agntn.dev/platforms/gitea"
---
# Gitea

> API v1 with limit instead of per_page, empty strings and nulls where fields are missing, and Codeberg or any Forgejo instance through baseURL.

<platform-facts platform="gitea">



</platform-facts>

## Address it

```ts
import { createProvider, resolveToken } from "@agntn/forges";

const connect = (baseURL?: string) =>
  createProvider("gitea", {
    baseURL,
    ...(resolveToken("gitea", { baseURL }) ? {} : { token: "" }),
  });

const gitea = await connect(); // gitea.com
const codeberg = await connect("https://codeberg.org");
const forgejo = await connect("https://forgejo.example.com");
```

`/api/v1` is added when the base URL lacks it. Forgejo is a Gitea fork with the same API, so Codeberg and every Forgejo instance go through this provider. The token chain reads `GITEA_TOKEN`, then the `tea` config file for the host. `tea` has no command that prints the token, so the CLI step is skipped.

## What it reads

<table>
<thead>
  <tr>
    <th>
      Resource
    </th>
    
    <th>
      Endpoint
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      repos
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo
      </code>
      
      , <code>
        GET /users/:owner/repos
      </code>
      
      , <code>
        GET …/tags
      </code>
      
      , <code>
        GET …/git/trees/:sha
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      issues
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/issues
      </code>
      
      , <code>
        POST …/issues
      </code>
      
      , <code>
        PATCH …/issues/:index
      </code>
      
       after a read, <code>
        …/issues/:index/comments
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      pull requests
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/pulls
      </code>
      
      , <code>
        …/pulls/:index/files
      </code>
      
      , <code>
        …/commits/:sha/status
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      pull request search
    </td>
    
    <td>
      <code>
        GET /repos/issues/search?type=pulls
      </code>
      
      , <code>
        …/repos/:owner/:repo/issues
      </code>
      
       for one repository
    </td>
  </tr>
  
  <tr>
    <td>
      issue and pull request edits
    </td>
    
    <td>
      <code>
        PATCH /repos/:owner/:repo/pulls/:index
      </code>
      
      , <code>
        POST …/issues/:index/labels
      </code>
      
      , <code>
        DELETE …/labels/:id
      </code>
      
      , after a read
    </td>
  </tr>
  
  <tr>
    <td>
      pull request merges
    </td>
    
    <td>
      <code>
        POST /repos/:owner/:repo/pulls/:index/merge
      </code>
      
      , then a read of the pull request
    </td>
  </tr>
  
  <tr>
    <td>
      commits
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/commits
      </code>
      
      , <code>
        …/git/commits/:sha
      </code>
      
      , <code>
        …/compare/:base...:head
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      commit checks
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/commits/:ref/status
      </code>
      
      , <code>
        …/git/commits/:ref
      </code>
      
       when that comes back empty
    </td>
  </tr>
  
  <tr>
    <td>
      CI runs
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/actions/runs
      </code>
      
      , <code>
        …/actions/workflows/:workflow/runs
      </code>
      
      , <code>
        …/actions/runs/:run/jobs
      </code>
      
      , <code>
        …/actions/jobs/:job_id/logs
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      releases
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/releases
      </code>
      
      , <code>
        …/releases/tags/:tag
      </code>
      
      , <code>
        POST …/releases
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      release edits
    </td>
    
    <td>
      <code>
        PATCH /repos/:owner/:repo/releases/:id
      </code>
      
      , after the tag read
    </td>
  </tr>
  
  <tr>
    <td>
      reactions
    </td>
    
    <td>
      <code>
        GET …/issues/:index/reactions
      </code>
      
      , <code>
        …/issues/comments/:id/reactions
      </code>
      
       next to a read of the issue and the comment
    </td>
  </tr>
  
  <tr>
    <td>
      timeline events
    </td>
    
    <td>
      <code>
        GET …/issues/:index/timeline
      </code>
      
       for issues and pull requests alike
    </td>
  </tr>
  
  <tr>
    <td>
      threads
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/pulls/:index/reviews
      </code>
      
      , <code>
        …/reviews/:id/comments
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      templates
    </td>
    
    <td>
      <code>
        GET /repos/:owner/:repo/contents/.gitea/…
      </code>
      
      , <code>
        .github/…
      </code>
    </td>
  </tr>
</tbody>
</table>

Pagination uses `limit`, not `per_page`, and reads the `Link` header.

## What comes back

Fields Gitea leaves out come back empty rather than undefined: `company` is `""`, counts per file on a commit are `null`. Every review comment is its own `Thread` with one comment, because the API has no parent id on review comments. `isOutdated` is always `false`. Pull request checks are the commit statuses of the head SHA.

`merge` comes from `allow_merge_commits`, `allow_squash_merge`, `allow_rebase` and `default_merge_style`, even on an anonymous read. With pull requests off, every flag is `false` and `methods` is empty.

Templates are repository scope only. There is no owner inheritance to claim, so none is claimed.

## Gotchas

- `commits.list` rejects the `path` filter on Gitea. That API ignores `limit` when `path` is set and would hand you the whole history. Forgejo paginates the filter. `ref`, `since` and `until` work on both.
- `commits.compare` gets no file list for the range and no count of what head lacks. `files`, `behindBy`, `mergeBaseSha` and `status` are `null`, and the whole range arrives newest first in one response, so it is reversed and paged locally.
- Code search does not exist. `code.search` is a `ForgesError` with status 501 and a sentence.
- Sub-issues don't exist either. `listSubIssues`, `addSubIssue` and `removeSubIssue` are a 501 on Gitea and Forgejo.
- Same for issue types and fields. `getFields` is a 501. So is a write that names one.
- `pullRequests.searchGlobal` and `issues.searchGlobal` without an `owner` work on gitea.com, but Codeberg answers them with a 500. Pass an `owner` there.
- gitea.com filters `searchGlobal` by `author`. Forgejo drops `created_by` on the search route without a word, so a page with anyone else's item on it is a 501.
- Both drop a label name they don't know and return the rows unfiltered, and the search route matches any of several labels, not all of them. `issues.searchGlobal` keeps only rows with every label and answers an empty page when the filter was dropped, see [issue search](https://forges.agntn.dev/guide/issues#search-across-repositories).
- Discussion comments arrive as one response, so the page you asked for is cut locally. A comment's reactions too.
- A commit mentioning an issue gets a `commit_ref` entry, but `listEvents` calls it `commit`, not `referenced`. That's a reference in disguise, so use `kinds: ["referenced", "commit"]` to catch both.
- Reactions on an issue or pull request page without a `Link` header, and the server may hand back fewer rows than `limit` asked for. `x-total-count` decides whether there's more.
- Older Forgejo responses keep an Actions run's branch only inside the webhook payload. It is read from there when the top level field is missing.
- `ciRuns.list` with `workflow` takes Gitea's own route from 1.27 and Forgejo's `workflow_id` filter from 15. Which one is decided by `GET /version`, read once. Anything older answers 501 instead of quietly listing every run.
- Forgejo hands over a run's jobs as a bare array. It shrugs at `limit` and `page`, so the page is cut locally. Skinny rows too: no steps, no times, and no URL before Forgejo 17. Name and state survive. That's enough to spot the red one.
- Forgejo 16, so Codeberg too, has no route for one job. Just its log. So `readJobLog` skips ahead and reads it top to bottom, like GitLab. The first line names the job. Near the end sits `🏁  Job succeeded` or `🏁  Job failed`. Why not split at the `⭐ Run` lines? Two real jobs printed them only around checkout. The whole build would land under it. A cancelled job gets no banner, so it stays `in_progress`. A job no runner took has no log at all. That's a `NotFoundError` there, not `started: false`. Forgejo 17 adds the job route with steps, and the failing step goes first again.
- Combined statuses on Forgejo paginate without a `Link` header. The next page is probed only when the current one is full.
- Forgejo answers a ref that doesn't exist with a 200 and no statuses. A commit nobody built looks exactly the same. So an empty `commits.listChecks` reads the ref once more. A typo becomes `NotFoundError`, not a quiet "no CI yet". gitea.com says 404 on its own.
- Reviews paginate without a `Link` header on Gitea and Forgejo alike. `x-total-count` says how many there are, and thread listing walks the reviews by that count.
- Ask for 100 rows and you get 50. Both cap `limit` at the server's maximum, and some lists skip `Link` on top of that. So is a short page the end? `max_response_items` from `/settings/api` says how big a page really is, read once per provider. If the host won't say, an empty page gets the last word. Reactions, reviews and Actions jobs page that way. Tags and runs go through `forges`, which counts its own pages.

## Where it lives

`src/providers/gitea.ts`.


## Sitemap

See the full [sitemap](https://forges.agntn.dev/sitemap.md) for all pages.
