Title: feat: Gitea and Forgejo git provider for Coder Agents · Issue #32588 · coder/coder · GitHub
Open Graph Title: feat: Gitea and Forgejo git provider for Coder Agents · Issue #32588 · coder/coder
X Title: feat: Gitea and Forgejo git provider for Coder Agents · Issue #32588 · coder/coder
Description: gitprovider.New implements GitHub and GitLab. The gitea external auth type is accepted but returns no provider, so Coder Agents chats whose repository is hosted on Gitea or Forgejo get no diff viewer or pull request status (Config.Git() ...
Open Graph Description: gitprovider.New implements GitHub and GitLab. The gitea external auth type is accepted but returns no provider, so Coder Agents chats whose repository is hosted on Gitea or Forgejo get no diff view...
X Description: gitprovider.New implements GitHub and GitLab. The gitea external auth type is accepted but returns no provider, so Coder Agents chats whose repository is hosted on Gitea or Forgejo get no diff view...
Opengraph URL: https://github.com/coder/coder/issues/32588
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"feat: Gitea and Forgejo git provider for Coder Agents","articleBody":"`gitprovider.New` implements GitHub and GitLab. The `gitea` external auth type is accepted but returns no provider, so Coder Agents chats whose repository is hosted on Gitea or Forgejo get no diff viewer or pull request status (`Config.Git()` documents Gitea as \"not implemented yet\", and #28141 / #32116 already plan for \"the release that adds a provider\").\n\nI've implemented a provider for the existing `gitea` type that covers both Gitea and Forgejo, and I'm volunteering to see it through review and maintenance. I'm moving a real project's agent workflow, hosted on a self-hosted Forgejo, onto Coder Agents, so this will get production use as well as testing against test instances.\n\n**Proposal:** add a Gitea and Forgejo provider for Coder Agents. The full implementation is up as **draft PR #32591** so you can review the approach and the assumptions below before I mark it ready. It builds on two small, independent fixes that are ready for review now: #32589 (Gitea external auth defaults) and #32590 (pull request URL parsing in the Agents UI).\n\n@coder/community-triage\n\n## Design\n\n- One `giteaProvider` in `coderd/externalauth/gitprovider/gitea.go`, registered in `New` for `\"gitea\"`. Plain `net/http`, modeled on `github.go`. I avoided `code.gitea.io/sdk/gitea` because its client calls `/version` at construction time.\n- Forgejo is a fork of Gitea and keeps the same `/api/v1` REST API for everything this interface needs, so a single implementation handles both. Following the lesson from Renovate (which split Gitea and Forgejo into two platforms and later merged them back, renovatebot/renovate#45825), the provider stays a single implementation. Where the servers differ, it uses requests that behave correctly on both instead of detecting the server type or version.\n- Method mapping:\n - `FetchPullRequestStatus`: `GET /repos/{o}/{r}/pulls/{n}` (title, state, merged, draft, head/base, additions/deletions/changed_files, user) and `GET /repos/{o}/{r}/pulls/{n}/reviews`, mapped to `Approved` / `ChangesRequested` / `ReviewerCount` using each reviewer's latest review: dismissed reviews count as decisive but not approving, and approvals Gitea marks stale still count, as on GitHub. Commit count from `GET .../pulls/{n}/commits` (Gitea does not return it on the PR object).\n - `ResolveBranchPullRequest`: `GET /pulls?state=open&head=\u003cbranch>`. Forgejo filters by head server-side; Gitea ignores the parameter, so results are always filtered client-side on `head.ref` and `head.repo` (excluding forks), scanning at most 10 pages of 50. No server type or version detection is needed.\n - `FetchPullRequestDiff`: `GET /repos/{o}/{r}/pulls/{n}.diff`, bounded by `MaxDiffSize`.\n - `FetchBranchDiff`: `GET /repos/{o}/{r}/compare/{base}...{head}?output=diff`. Gitea 1.27 and later return a raw diff. Forgejo and older Gitea return JSON for this request and have no other token-authenticated way to get a branch diff (I tested the web compare page; it rejects API tokens), so the provider returns an error wrapping `errors.ErrUnsupported` and the diff appears once a PR is opened.\n - URL helpers: `/pulls/{n}` (not `/pull/`), HTTPS and SSH origins including custom ports (`ssh://git@host:2222/o/r.git`), and instances behind a subpath.\n- `site/src/pages/AgentsPage/utils/pullRequest.ts` only accepts `/pull/\u003cn>`; extend it to accept `/pulls/\u003cn>`.\n- Docs: add a Gitea and Forgejo section to `docs/coder-agents/platform-controls/git-providers.md` with known limitations.\n\n## Differences from the GitHub and GitLab providers\n\nThese are deliberate, and each is documented under Known limitations in `git-providers.md`:\n\n| Area | Behavior | Reason |\n|---|---|---|\n| Branch diff before a PR | Gitea 1.27+ only; others return `errors.ErrUnsupported` | Verified on Forgejo 15/16 and Gitea 1.26: no token-authenticated raw branch diff. I plan a separate Forgejo PR adding `output=diff` to its compare API, which this provider already sends. |\n| Branch to PR lookup on Gitea | Scans at most 500 open PRs | Gitea has no head filter; bounds API cost. Forgejo filters server-side. |\n| Stale approvals | Count unless dismissed | Matches GitHub and the Gitea UI. Gitea's \"dismiss stale approvals\" setting marks them dismissed. |\n| Response caching | None (3 requests per refresh) | Same as GitLab. |\n| Token revocation on unlink | Not available | Gitea and Forgejo advertise no revocation endpoint. This is in external auth, not the provider, and is out of scope here; noting it for transparency. |\n\n## PR stack\n\nOpened: #32589 (1), #32590 (2), and #32591 (3, draft).\n\n1. `fix(coderd/externalauth)`: derive the Gitea API base URL from the auth URL host (it is always `https://gitea.com/api/v1` today, so self-hosted instances call gitea.com), and remove a stray space from the default `\" write:repository\"` scope. Small and independent; opened alongside this issue.\n2. `fix(site/src/pages/AgentsPage/utils)`: accept Gitea's `/pulls/\u003cn>` URLs in the fallback pull request URL parser. Small and independent; opened alongside this issue.\n3. `feat(coderd/externalauth)`: the provider, unit tests, registration, and docs, stacked on PR 1. Opened as a draft so you can steer the assumptions below first. It is about 1,050 lines, slightly over the ~1,000 guideline; roughly half is tests. I can split the docs into a follow-up if you prefer.\n4. Optional: recorded integration tests (go-vcr), following the GitLab precedent (#25653), recorded against throwaway public repositories on test instances.\n\n## Assumptions I made (happy to change any of them)\n\nThe implementation is written and tested (PR 3 is open as a draft so you can see it), but these choices are yours to make. Tell me if you'd prefer otherwise and I'll rework it:\n\n- **One `gitea` provider covers Forgejo.** I reused the existing `gitea` external auth type rather than adding a `forgejo` type, because Forgejo serves the same API for everything the provider needs.\n- **Branch diff gap uses `errors.ErrUnsupported`.** On servers that can't produce a branch diff, `FetchBranchDiff` wraps the standard sentinel recommended in `.claude/docs/GO.md` rather than adding a new error type.\n- **Chat handler and UI are unchanged.** On those servers the Agents Git panel shows the generic red \"Failed to get chat diff\" error until a PR is opened, the same rendering any provider diff error gets today. A neutral \"diff available after a pull request is opened\" state would be a nicer follow-up, but I left that design to you.\n- **No `stale_at` reset for parked `gitea` rows.** #28141 and #32116 plan a reset \"when a provider implementation ships.\" PR 3 doesn't include one, since #32116 is still open; I can add it to whichever PR lands second.\n- **Coordination with #32388.** That open PR renames `checkRateLimitError` and adds `ErrTokenRejected`. If it lands first I'll rebase and return `ErrTokenRejected` on 401 so Gitea users get the reconnect button.\n\n## Testing\n\nBefore opening any PR I ran the provider against live Forgejo 15.0.12, Forgejo 16.0.7, Gitea 28.4.0, Gitea 1.27.3, and Gitea 1.26.4, covering PR status and review mapping, branch resolution including a fork with the same branch name, diffs, private repositories, and failure cases (no token, user without access, revoked token, token without repository scope, missing PR or branch, unreachable server). The external auth OAuth flow was tested end to end with Coder's default Gitea scopes. I also ran the same checks on my production Forgejo (15.0.10) with the OAuth token Coder stored, on throwaway repositories (one check, a token without the repository scope, was covered only on the test instances), and ran a Coder Agents chat end to end against test instances and production: the agent pushed a branch through external auth, and the PR status and diff appeared in the Agents UI. Output and screenshots are attached to each PR.\n\nAI disclosure: this work is AI-assisted (Claude Code) per `contributing/AI_CONTRIBUTING.md`. I have reviewed, tested, and am accountable for all changes, and each PR will include manual verification output.\n\n","author":{"url":"https://github.com/jtperry","@type":"Person","name":"jtperry"},"datePublished":"2026-11-22T19:43:16Z","url":"https://github.com/coder/coder/issues/32588"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d0413072-c069-f020-5a6c-f3c366402e32 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F1C:11C492:674EE:8E481:6B044C7C |
| html-safe-nonce | 8c5b988505d15faa482456e1258825477201ff87eafeac1794da2f75037376ef |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjFDOjExQzQ5Mjo2NzRFRTo4RTQ4MTo2QjA0NEM3QyIsInZpc2l0b3JfaWQiOiI4MTg2ODQyNTg0Mzk2ODc2OTI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a3f7ffafc5df33db6fbb4624541681ff11cef6f4368d77de979630211ba0fae8 |
| hovercard-subject-tag | issue:6546881029 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/coder/coder/32588/issue_layout |
| twitter:image | https://opengraph.githubassets.com/38d1aaf70de41ec11e492ee3a6ad14b988ca093bd5e095ecc7635d031631c7cb/coder/coder/issues/32588 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/38d1aaf70de41ec11e492ee3a6ad14b988ca093bd5e095ecc7635d031631c7cb/coder/coder/issues/32588 |
| og:image:alt | gitprovider.New implements GitHub and GitLab. The gitea external auth type is accepted but returns no provider, so Coder Agents chats whose repository is hosted on Gitea or Forgejo get no diff view... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jtperry |
| hostname | github.com |
| expected-hostname | github.com |
| None | 002aa6b95ffa730b0aec436a5c383f536ad677284e60056037fb120afe37b730 |
| turbo-cache-control | no-preview |
| go-import | github.com/coder/coder git https://github.com/coder/coder.git |
| octolytics-dimension-user_id | 95932066 |
| octolytics-dimension-user_login | coder |
| octolytics-dimension-repository_id | 440752086 |
| octolytics-dimension-repository_nwo | coder/coder |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 440752086 |
| octolytics-dimension-repository_network_root_nwo | coder/coder |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 059f24c781e3a0d7df3f27a97da0e93fab06ae39 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width