Skip to content

Refactor template render#36438

Merged
wxiaoguang merged 5 commits intogo-gitea:mainfrom
wxiaoguang:refactor-tmpl
Jan 24, 2026
Merged

Refactor template render#36438
wxiaoguang merged 5 commits intogo-gitea:mainfrom
wxiaoguang:refactor-tmpl

Conversation

@wxiaoguang
Copy link
Copy Markdown
Contributor

No description provided.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 23, 2026
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin labels Jan 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the template rendering system in Gitea to improve separation of concerns and code organization. The main changes involve splitting the monolithic HTML renderer into separate page and mail renderers with distinct responsibilities.

Changes:

  • Introduced separate PageRenderer and MailRenderer implementations with distinct lifecycles and initialization
  • Refactored template loading to use a common tmplRender struct with configurable template collection and content reading functions
  • Migrated from http.FileSystem to fs.FS in assetfs for better standard library alignment
  • Improved error page rendering to support both HTML and plain text responses
  • Consolidated template-related utility functions and removed obsolete error types

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
modules/templates/page.go New file implementing PageRenderer with sync.OnceValue initialization and auto-reloading support
modules/templates/mail.go New file implementing MailRenderer with double-checked locking and template mocking for tests
modules/templates/htmlrenderer.go Refactored into generic tmplRender with collectTemplateNames and readTemplateContent callbacks
modules/templates/base.go Removed template listing utility functions (moved into renderer implementations)
modules/templates/vars/vars.go Simplified error handling by removing custom error types, fixed typo in comment
modules/templates/scopedtmpl/scopedtmpl.go Added HasTemplate helper method
services/mailer/mailer.go Simplified initialization to call MailRenderer()
services/mailer/mail.go Changed LoadedTemplates to return MailRender, removed atomic.Pointer
services/mailer/mail_test.go Updated to use new mockMailTemplates helper function
services/mailer/mail_release_test.go Replaced manual variable restoration with test.MockVariableValue
services/mailer/mail_issue_common.go Used util.IfZero for subject fallback, changed Lookup to HasTemplate
services/context/context.go Added ContexterInstallPage helper to reduce duplication
services/context/package.go Renamed HTMLRenderer to PageRenderer
services/markup/*_test.go Updated test mocks to use PageRenderer
routers/web/web.go Removed redundant HTMLRenderer initialization
routers/web/user/home_test.go Updated test to use PageRenderer
routers/web/repo/pull_review_test.go Updated test to use PageRenderer
routers/web/devtest/mail_preview.go Updated to handle empty subject with util.IfZero
routers/private/manager.go Renamed ReloadHTMLTemplates to ReloadAllTemplates
routers/install/install.go Refactored installContexter to use ContexterInstallPage
routers/init.go Removed redundant HTMLRenderer initialization
routers/common/qos.go Refactored renderServiceUnavailable to use common renderServerErrorPage
routers/common/qos_test.go Removed test (moved to errpage_test.go)
routers/common/errpage.go Added renderServerErrorPage helper with Accept header detection
routers/common/errpage_test.go Added Plain subtest for non-HTML response handling
modules/assetfs/layered.go Migrated from http.FileSystem to fs.FS throughout
modules/public/public.go Updated to use http.FS(assetFS) for compatibility
cmd/web.go Removed panic recovery handler (now handled by processStartupTemplateError), added PageRenderer initialization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 30 out of 30 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jan 24, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jan 24, 2026
@wxiaoguang wxiaoguang enabled auto-merge (squash) January 24, 2026 04:36
@wxiaoguang wxiaoguang merged commit 9de6594 into go-gitea:main Jan 24, 2026
24 checks passed
@GiteaBot GiteaBot added this to the 1.26.0 milestone Jan 24, 2026
@wxiaoguang wxiaoguang deleted the refactor-tmpl branch January 24, 2026 05:23
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jan 26, 2026
* giteaofficial/main:
  Normalize guessed languages for code highlighting (go-gitea#36450)
  Add `knip` linter (go-gitea#36442)
  Fix various bugs (go-gitea#36446)
  Update tool dependencies (go-gitea#36445)
  Update JS dependencies, adjust webpack config, misc fixes (go-gitea#36431)
  fix: Improve image captcha contrast for dark mode (go-gitea#36265)
  Refactor template render (go-gitea#36438)
  Add documentation for markdown anchor post-processing (go-gitea#36443)
  Fix markup heading parsing, fix emphasis parsing (go-gitea#36284)
  Front port changelog for 1.25.4 (go-gitea#36432)
  Bugfix: Potential incorrect runID in run status update (go-gitea#36437)
  Restrict branch naming when new change matches with protection rules (go-gitea#36405)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin modifies/go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants