feat(site): implement preview URL generation #321

Merged
fuzzy merged 1 commit from feat/preview-url into main 2026-08-03 22:57:09 +00:00
Owner

What

Add preview URL generation using the path-based format https://{host}/preview/{branch}, matching the preview Ingress routing:

  • KubernetesService.PreviewURL(s, branch) and the Client implementation build the URL from the site host (custom domain if set, else <name>.<base_domain>), producing e.g. https://blog.pages.example.com/preview/test/foo.
  • SiteService.PreviewURL(siteName, branch) resolves the site (returning ErrNotFound for unknown sites) and delegates to the Kubernetes layer.
  • KubernetesClient structural interface extended with PreviewURL.

Why

Phase 6 task #88 — completes the Preview Deployments phase; the URL lets operators (and future API responses) link directly to a preview deployment.

Testing

  • go build ./...
  • go vet ./...
  • go test -race ./... — kubernetes URL builder (default + custom domain hosts), site service (happy path + unknown site); full suite passes
  • gofmt -l ./cmd ./internal ./pkg clean
  • golangci-lint run — 0 issues
  • pre-commit hooks all pass

Breaking Changes

None.

Notes

  • Chose the path-based format over the subdomain alternative since the existing preview Ingress routes via /preview/{branch}.
  • Issues #87–#88 were closed via the Forgejo API as part of this task per the workflow.
  • Phase 6 (Preview Deployments) is now complete.

Closes #87
Closes #88

## What Add preview URL generation using the path-based format `https://{host}/preview/{branch}`, matching the preview Ingress routing: - **`KubernetesService.PreviewURL(s, branch)`** and the `Client` implementation build the URL from the site host (custom domain if set, else `<name>.<base_domain>`), producing e.g. `https://blog.pages.example.com/preview/test/foo`. - **`SiteService.PreviewURL(siteName, branch)`** resolves the site (returning `ErrNotFound` for unknown sites) and delegates to the Kubernetes layer. - **`KubernetesClient`** structural interface extended with `PreviewURL`. ## Why Phase 6 task #88 — completes the Preview Deployments phase; the URL lets operators (and future API responses) link directly to a preview deployment. ## Testing - [x] `go build ./...` - [x] `go vet ./...` - [x] `go test -race ./...` — kubernetes URL builder (default + custom domain hosts), site service (happy path + unknown site); full suite passes - [x] `gofmt -l ./cmd ./internal ./pkg` clean - [x] `golangci-lint run` — 0 issues - [x] pre-commit hooks all pass ## Breaking Changes None. ## Notes - Chose the path-based format over the subdomain alternative since the existing preview Ingress routes via `/preview/{branch}`. - Issues #87–#88 were closed via the Forgejo API as part of this task per the workflow. - Phase 6 (Preview Deployments) is now complete. Closes #87 Closes #88
feat(site): implement preview URL generation
All checks were successful
Test and Release / lint (pull_request) Successful in 7m2s
Test and Release / test (pull_request) Successful in 7m13s
a7239a3d58
Add preview URL generation using the path-based format
https://{host}/preview/{branch}, matching the preview Ingress routing
(the site host prefers a custom domain, else <name>.<base_domain>).

- KubernetesService.PreviewURL(s, branch) and the Client
  implementation build the URL from the site host
- SiteService.PreviewURL(siteName, branch) resolves the site and
  delegates, returning ErrNotFound for unknown sites
- KubernetesClient structural interface extended with PreviewURL

Add tests for the kubernetes URL builder (default and custom domain
hosts) and the site service (happy path, unknown site). Mark task
done in ROADMAP.md.

closes #87
closes #88
fuzzy scheduled this pull request to auto merge when all checks succeed 2026-08-03 22:55:14 +00:00
the.auditor left a comment

Review Summary

Verified locally on the PR head (a7239a3): go build, go vet, gofmt, golangci-lint run all clean; full suite passes with -race (kubernetes URL builder + site service URL tests).

Clean, minimal implementation. PreviewURL produces https://{host}/preview/{branch} using the same siteHost (custom domain preferred, else <name>.<base_domain>) and the same /preview/{branch} path that the preview Ingress routes, so the generated URL always matches the actual routing. Keeping the Kubernetes-level builder pure (no ctx/error — it's string formatting) and wrapping it in SiteService.PreviewURL for site resolution + ErrNotFound is the right split. All structural interface fakes updated, so everything compiles.

No blocking issues.

Non-blocking observations:

  1. The path isn't URL-escaped, but git ref rules already forbid characters that would break a URL (?, #, spaces, etc.), so branches are safe as-is.
  2. The URL is built without consulting the ingress-class or TLS-termination config — it always assumes https://. Fine given the roadmap's TLS approach (ingress controller terminates), worth keeping in mind if a plain-HTTP deployment is ever supported.

Approving.

## Review Summary Verified locally on the PR head (`a7239a3`): `go build`, `go vet`, `gofmt`, `golangci-lint run` all clean; full suite passes with `-race` (kubernetes URL builder + site service URL tests). Clean, minimal implementation. `PreviewURL` produces `https://{host}/preview/{branch}` using the same `siteHost` (custom domain preferred, else `<name>.<base_domain>`) and the same `/preview/{branch}` path that the preview Ingress routes, so the generated URL always matches the actual routing. Keeping the Kubernetes-level builder pure (no `ctx`/error — it's string formatting) and wrapping it in `SiteService.PreviewURL` for site resolution + `ErrNotFound` is the right split. All structural interface fakes updated, so everything compiles. **No blocking issues.** Non-blocking observations: 1. The path isn't URL-escaped, but git ref rules already forbid characters that would break a URL (`?`, `#`, spaces, etc.), so branches are safe as-is. 2. The URL is built without consulting the ingress-class or TLS-termination config — it always assumes `https://`. Fine given the roadmap's TLS approach (ingress controller terminates), worth keeping in mind if a plain-HTTP deployment is ever supported. Approving.
fuzzy merged commit a7239a3d58 into main 2026-08-03 22:57:09 +00:00
fuzzy deleted branch feat/preview-url 2026-08-03 22:57:09 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/thwap-pagesd!321
No description provided.