feat(forgejo): implement Forgejo client wrapper #134
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/thwap-pagesd!134
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/forgejo-client"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Implement the
ForgejoServiceinterface from task #32 onClientininternal/forgejo:NewClient(baseURL, token)authenticates viagitea.SetToken;SetContext(ctx)propagates cancellation to every callGetOrg/GetUserInfo, creates repo with auto-init, mapssite.Visibilityto the SDKPrivateflag (public→false, private→false, limited→private), returns clone URLgiteawebhook postingpushevents to the thwap-pagesd endpoint, returns hook IDvar _ ForgejoService = (*Client)(nil)compile-time assertionTests: httptest-based fake Forgejo server exercising the real gitea SDK — org/user repo creation, error path, webhook payload validation, paginated tag listing, and token auth header verification.
Why
Phase 3 task #37 — the first concrete integration, used by site registration (#69) and the webhook receiver (#75).
Testing
go build ./...go vet ./...go test -race ./internal/forgejo/— 6 tests passgofmt -l ./cmd ./internalcleangolangci-lint run— 0 issuesBreaking Changes
None.
Notes
site.VisibilityLimitedmaps to private — the gitea SDKCreateRepoOptiononly exposes aPrivatebool (limited is org-scoped), as discussed.GetOrg(org →CreateOrgRepo), falling back to user-ownedCreateRepo.Closes #33
Closes #34
Closes #35
Closes #36
Closes #37
Review Summary
Verified locally on the PR head (
b54708e):go build,go vet,gofmt,golangci-lint runall clean; all 6 forgejo tests pass with-race. The httptest fake-server approach exercises the real gitea SDK against realistic payloads — solid integration-style coverage (org/user repo creation, error path, webhook payload, pagination viaLinkheader, token auth header).Implementation is correct: visibility mapping behaves as intended (public → public repo; private and limited → private repo), errors are wrapped with context, and the
ForgejoServiceinterface assertion is in place.No blocking issues.
Non-blocking observations:
forgejo.go:109— thevisibilityPrivatecomment reads "Public and limited map to false and true respectively" and omitsprivate(which also maps to true). Also the PR body states "private→false", which contradicts the code. The code is right; the wording is misleading. Suggest: "Public maps to false; private and limited map to true."isOrgtreats anyGetOrgerror as "not a user" — a transient error (rate limit, network, 403) silently falls back toCreateRepo, which creates the repo under the authenticated user rather than the requestedowner. Consider distinguishing not-found (404) from other errors once error-handling matures.c.gitea.SetContext(ctx)per call mutates shared client state — makesClientunsafe for concurrent use with different contexts. Fine while use is single-threaded; document it before the webhook handler runs concurrent requests.CreateWebhookdoesn't set a hook secret despitewebhook.secretexisting in config — will need wiring when the receiver (task #75) validates signatures.VisibilityPrivatemapping (onlylimitedandpublicare exercised).Approving.