Implement Forgejo platform provider using Gitea SDK#5
Merged
Conversation
Replaces the 20 "not yet implemented" stubs in internal/platform/forgejo/forgejo.go with real implementations backed by the code.gitea.io/sdk/gitea client. This subsumes the work in PR #3 (claude/forgejo-client-integration-...), which built a parallel internal/forgejo/ package against the older single-platform layout. With main now exposing a platform-agnostic Provider abstraction, the new code is wired directly into that interface and returns platform.* types so callers stay platform-neutral. Highlights: - Lazy-initialised gitea client so New() does not perform a server version probe at construction time (preserves existing unit-test contract that allowed unreachable URLs). - HTTP-status-to-platform.Err* mapping via translateError so callers can use errors.Is(err, platform.ErrNotFound) etc. - ID-based Provider methods (AddTeamMember/AddCollaborator/...) resolve ID -> username/owner via GetUserByID / GetRepoByID before calling the username-keyed Gitea endpoints. - forgejo_test.go: drop the obsolete "not yet implemented" assertion test and replace it with httptest-backed checks for the error translation paths.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements the complete Forgejo platform provider by integrating the Gitea SDK, replacing all placeholder "not yet implemented" methods with functional implementations.
Summary
The Forgejo provider now fully implements the
platform.Providerinterface by leveraging thecode.gitea.io/sdk/giteaclient library. All provider methods across repositories, users, organizations, teams, collaborators, and branches are now functional.Key Changes
sdk()method that lazily initializes the Gitea client usingsync.Onceto avoid blocking on network availability during provider constructiontranslateError()function that maps Gitea SDK errors and HTTP status codes to platform-specific sentinel errors (ErrNotFound,ErrUnauthorized,ErrForbidden,ErrAlreadyExists,ErrRateLimited,ErrUnavailable)toRepository(),toUser(),toOrganization(),toTeam()toAccessMode()andtoPlatformPermission()for permission mappingGetRepository(),GetRepositoryByID(),CreateRepositoryFromTemplate(), andDeleteRepository()GetAuthenticatedUser(),GetUser(), andGetUserByEmail()with email matching logicGetOrganization(),CreateOrganization(), andDeleteOrganization()CreateTeam(),DeleteTeam(),AddTeamMember(),RemoveTeamMember(),AddTeamRepository(), andRemoveTeamRepository()AddCollaborator()andRemoveCollaborator()ProtectBranch()andGetLatestCommit()httptestto verify error translation behaviorNotable Implementation Details
NewClient()may return both a usable client and anErrUnknownVersionerror; the implementation tolerates this caseGetUserByEmail()performs case-insensitive email matching since the Gitea search API doesn't guarantee exact matcheshttps://claude.ai/code/session_01TMo5LrrvEyEc3JfxbvPts6