bambuddy/backend/app/services/git_providers
maziggy 306b9ba7fd Accept Forgejo tokens scoped to a single repository (#2775)
ForgejoBackend.test_connection asked GET /user who the token belonged to
before asking whether the token could reach the repository, and treated a 403
there as fatal. A Forgejo v15 repository-scoped token may only carry
read/write on issues and repositories, so it 403s on /user -- and was rejected
despite reaching its own repository fine, which is all a backup needs: the push
path uses the Contents API and restore reads commits, trees and blobs, all
under /repos/{owner}/{repo}. That /user call was the only one in the whole
provider layer.

The probe stays, because a 401 from it is genuinely conclusive and names a bad
token before the repo call has to guess -- Forgejo v15+ hides a private repo
behind 404 rather than 403, so the repo call cannot always tell those apart.
Every other status now falls through to the repo check.

Two additions keep the messages as sharp as before: the repo call's own 401 is
mapped to "Invalid access token" instead of a generic API error, and the 404
names write:repository and the scoped-to-another-repository case, mentioning a
possibly-invalid token only when /user did not confirm the identity.

The token hint under the field was one shared string reading "fine-grained
token with Contents read/write" -- GitHub's advice, shown to Gitea, Forgejo and
GitLab users too. It is now per provider via PROVIDER_TOKEN_HINT_I18N_KEY,
following the existing repo-URL placeholder map, translated in all 13 locales.

Tests pin the repository-scoped token connecting, a transient /user status not
blocking the repo call, both 404 wordings, and the repo-call 401; a frontend
test switches providers and asserts the hint follows.
2026-08-06 12:08:36 +02:00
..
__init__.py feat(backup): Extend Backup to other Git providers (#1160) 2026-05-03 08:12:36 +02:00
base.py fix(backup): halve the provider round-trips, and stop losing commit metadata (#2656) 2026-08-04 08:57:34 -04:00
factory.py feat(backup): Extend Backup to other Git providers (#1160) 2026-05-03 08:12:36 +02:00
forgejo.py Accept Forgejo tokens scoped to a single repository (#2775) 2026-08-06 12:08:36 +02:00
gitea.py fix(backup): stop Gitea's tree pager failing open on a missing total_count (#2656) 2026-08-04 08:57:34 -04:00
github.py fix(backup): halve the provider round-trips, and stop losing commit metadata (#2656) 2026-08-04 08:57:34 -04:00
gitlab.py fix(backup): halve the provider round-trips, and stop losing commit metadata (#2656) 2026-08-04 08:57:34 -04:00