Skip to content

Implement Forgejo platform provider using Gitea SDK#5

Merged
bloboss merged 1 commit into
mainfrom
claude/fix-forgejo-ci-cd-96fuc
May 10, 2026
Merged

Implement Forgejo platform provider using Gitea SDK#5
bloboss merged 1 commit into
mainfrom
claude/fix-forgejo-ci-cd-96fuc

Conversation

@bloboss

@bloboss bloboss commented May 10, 2026

Copy link
Copy Markdown
Owner

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.Provider interface by leveraging the code.gitea.io/sdk/gitea client library. All provider methods across repositories, users, organizations, teams, collaborators, and branches are now functional.

Key Changes

  • Lazy SDK initialization: Added sdk() method that lazily initializes the Gitea client using sync.Once to avoid blocking on network availability during provider construction
  • Error translation: Implemented translateError() function that maps Gitea SDK errors and HTTP status codes to platform-specific sentinel errors (ErrNotFound, ErrUnauthorized, ErrForbidden, ErrAlreadyExists, ErrRateLimited, ErrUnavailable)
  • Type conversions: Added helper functions to convert between Gitea SDK types and platform types:
    • toRepository(), toUser(), toOrganization(), toTeam()
    • toAccessMode() and toPlatformPermission() for permission mapping
  • Repository operations: Implemented GetRepository(), GetRepositoryByID(), CreateRepositoryFromTemplate(), and DeleteRepository()
  • User operations: Implemented GetAuthenticatedUser(), GetUser(), and GetUserByEmail() with email matching logic
  • Organization operations: Implemented GetOrganization(), CreateOrganization(), and DeleteOrganization()
  • Team operations: Implemented CreateTeam(), DeleteTeam(), AddTeamMember(), RemoveTeamMember(), AddTeamRepository(), and RemoveTeamRepository()
  • Collaborator operations: Implemented AddCollaborator() and RemoveCollaborator()
  • Branch operations: Implemented ProtectBranch() and GetLatestCommit()
  • Tests: Replaced placeholder tests with functional tests using httptest to verify error translation behavior

Notable Implementation Details

  • The Gitea SDK's NewClient() may return both a usable client and an ErrUnknownVersion error; the implementation tolerates this case
  • Team creation includes default repository units (Code, Issues, Pulls) and disables "includes all repositories"
  • Repository template creation copies git content, topics, labels, and avatars
  • GetUserByEmail() performs case-insensitive email matching since the Gitea search API doesn't guarantee exact matches
  • Branch protection uses the branch name as both the branch name and rule name
  • Commit retrieval handles cases where commit metadata may be partially populated

https://claude.ai/code/session_01TMo5LrrvEyEc3JfxbvPts6

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.
@bloboss bloboss merged commit c260a1f into main May 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants