Skip to content

feat(migrator): add template version migration for Fiber v3 compatibility#272

Merged
ReneWerner87 merged 3 commits intomasterfrom
add_template_pkg_migrator
Feb 12, 2026
Merged

feat(migrator): add template version migration for Fiber v3 compatibility#272
ReneWerner87 merged 3 commits intomasterfrom
add_template_pkg_migrator

Conversation

@ReneWerner87
Copy link
Member

@ReneWerner87 ReneWerner87 commented Feb 12, 2026

Summary by CodeRabbit

  • New Features

    • Automatic template package version migration now runs as part of the upgrade process to align template imports and module entries with v3 requirements.
  • Refactor

    • Replaced hard-coded strings with named constants in migration utilities for clearer, safer checks.
  • Tests

    • Added comprehensive tests for template version migration, including idempotency validation.

Copilot AI review requested due to automatic review settings February 12, 2026 21:31
@ReneWerner87 ReneWerner87 requested a review from a team as a code owner February 12, 2026 21:31
@ReneWerner87 ReneWerner87 requested review from efectn, gaby and sixcolors and removed request for a team February 12, 2026 21:31
@github-actions github-actions bot added the ✏️ Feature New feature or request label Feb 12, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ReneWerner87, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new migration step designed to facilitate the upgrade process for Fiber applications to version 3. It automates the necessary adjustments to template package import paths and go.mod dependencies, ensuring that various template engines remain compatible with the updated Fiber framework.

Highlights

  • New Migration Function: A new migration function, MigrateTemplateVersions, has been added to the list of v3 migrations to handle template package updates.
  • Template Package Updates: Implemented logic to automatically update Go import paths and go.mod entries for various Fiber template packages (e.g., ace, amber, django, html) to ensure compatibility with Fiber v3.
  • Code Readability Improvement: Refactored swagger_packages.go by introducing named constants (vendorDirName, goModFileName) to replace hardcoded string literals, enhancing code readability and maintainability.
  • Comprehensive Testing: Included comprehensive unit tests for the new template version migration, covering import path and go.mod updates, and verifying the idempotency of the migration process.
Changelog
  • cmd/internal/migrations/lists.go
    • Added v3migrations.MigrateTemplateVersions to the list of v3 migrations.
  • cmd/internal/migrations/v3/swagger_packages.go
    • Replaced string literal 'vendor' with vendorDirName constant.
    • Replaced string literal 'go.mod' with goModFileName constant.
  • cmd/internal/migrations/v3/template_versions.go
    • Added new file containing the MigrateTemplateVersions function and helper logic.
    • Defined templateTargets map to specify target module paths and versions for various template engines.
    • Implemented regular expression-based logic to update import paths in Go source files.
    • Implemented logic to update require and replace directives in go.mod files.
  • cmd/internal/migrations/v3/template_versions_test.go
    • Added new file containing unit tests for MigrateTemplateVersions.
    • Included tests for import path and go.mod updates.
    • Verified the idempotency of the migration process.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new migration to update template package versions for Fiber v3 compatibility. The implementation includes logic to update both import paths in Go source files and dependencies in go.mod files. The changes are well-tested, including checks for idempotency. My main feedback is related to a performance improvement in cmd/internal/migrations/v3/template_versions.go where regular expressions are repeatedly compiled inside a loop. Caching these would make the migration process more efficient. Additionally, the refactoring in cmd/internal/migrations/v3/swagger_packages.go to use constants instead of magic strings is a good improvement for maintainability.

@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

Warning

Rate limit exceeded

@ReneWerner87 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 17 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 57725b4 and 44946e6.

📒 Files selected for processing (2)
  • cmd/internal/migrations/v3/template_versions.go
  • cmd/internal/migrations/v3/template_versions_test.go

Walkthrough

Adds a new v3 migration, MigrateTemplateVersions, to rewrite template package imports and update go.mod require/replace entries across a project; also refactors two hardcoded strings into named constants in an existing migration helper.

Changes

Cohort / File(s) Summary
Migration Registration
cmd/internal/migrations/lists.go
Registers MigrateTemplateVersions in the migration list for the >=2.0.0 to <4.0.0-0 block.
Template Migration Implementation
cmd/internal/migrations/v3/template_versions.go
New migration: maps template packages to minimum module paths/versions, rewrites source import paths, and updates go.mod require/replace lines across modules.
Template Migration Tests
cmd/internal/migrations/v3/template_versions_test.go
Adds tests asserting imports and go.mod entries are updated and that the migration is idempotent and emits a success message.
Constants Refactor
cmd/internal/migrations/v3/swagger_packages.go
Introduces vendorDirName and goModFileName constants and replaces hardcoded "vendor" and "go.mod" comparisons.

Sequence Diagram

sequenceDiagram
    participant Cmd as Migration Cmd
    participant Src as Source files
    participant FS as Filesystem walker
    participant GoMod as go.mod files

    Cmd->>Src: scan files for template imports (reTemplateImport)
    Src->>Src: rewrite imports to mapped module paths/versions
    Cmd->>FS: walk project tree (skip vendorDirName)
    FS->>GoMod: open each `goModFileName`
    GoMod->>GoMod: update require & replace directives (patterns)
    GoMod->>FS: write back modified go.mod
    Cmd->>Cmd: if any changes detected -> print "Migrated template package versions"
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #120 — Adds/extends v3 migrations and touches the same migrations registration and v3 migration machinery.
  • #186 — Registers new v3 migration functions and modifies the migrations list in cmd/internal/migrations/lists.go.
  • #134 — Modifies migration registration and related v3 migration code that walks and updates go.mod files.

Suggested labels

codex

Suggested reviewers

  • gaby
  • sixcolors
  • efectn

Poem

🐰 I hopped through imports, swift and spry,
Rewriting paths beneath the sky,
go.mod trimmed, replaces set,
Templates updated—no regret!
A tiny rabbit's migration cry.

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, but the template requires explanation of details and the problem being solved. Add a detailed description explaining what problem this change solves, why template version migration is necessary for Fiber v3, and any relevant implementation details.
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding template version migration functionality for Fiber v3 compatibility, which aligns with the changeset.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add_template_pkg_migrator

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@cmd/internal/migrations/v3/template_versions.go`:
- Around line 80-88: Replace the hardcoded strings "vendor" and "go.mod" in the
directory walk callback in template_versions.go with the package-level constants
vendorDirName and goModFileName (the ones introduced in swagger_packages.go) so
the code uses vendorDirName instead of "vendor" and goModFileName instead of
"go.mod"; update the comparisons in the d.IsDir() branch and the subsequent
file-name check to use those constants (no additional imports should be
necessary since the constants live in the same package).
🧹 Nitpick comments (2)
cmd/internal/migrations/v3/template_versions.go (2)

16-16: Minor: escaped quote in raw string character class is misleading.

In a backtick raw string, [^\"] literally excludes both \ and ". Since Go import paths never contain backslashes this works correctly, but the intent reads more clearly as [^"]*.

Suggested tweak
-var reTemplateImport = regexp.MustCompile(`"github\.com/gofiber/template/([a-zA-Z0-9_-]+)(?:/v(\d+))?([^\"]*)"`)
+var reTemplateImport = regexp.MustCompile(`"github\.com/gofiber/template/([a-zA-Z0-9_-]+)(?:/v(\d+))?([^"]*)"`)

123-133: Regex compiled on every call — acceptable but worth noting.

updateTemplateGoModModule compiles two regexes per invocation (9 template packages × N go.mod files). For typical project sizes this is negligible. If it ever becomes a concern, these could be precompiled per package, similar to how the import regex is a package-level var.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53bba68 and f566d1e.

📒 Files selected for processing (4)
  • cmd/internal/migrations/lists.go
  • cmd/internal/migrations/v3/swagger_packages.go
  • cmd/internal/migrations/v3/template_versions.go
  • cmd/internal/migrations/v3/template_versions_test.go
🧰 Additional context used
🧬 Code graph analysis (3)
cmd/internal/migrations/v3/template_versions_test.go (1)
cmd/internal/migrations/v3/template_versions.go (1)
  • MigrateTemplateVersions (40-71)
cmd/internal/migrations/lists.go (1)
cmd/internal/migrations/v3/template_versions.go (1)
  • MigrateTemplateVersions (40-71)
cmd/internal/migrations/v3/template_versions.go (1)
cmd/internal/helpers.go (1)
  • ChangeFileContent (54-110)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Agent
  • GitHub Check: Build (1.25.x, ubuntu-latest)
  • GitHub Check: Build (1.25.x, windows-latest)
  • GitHub Check: Build (1.25.x, macos-latest)
🔇 Additional comments (4)
cmd/internal/migrations/v3/swagger_packages.go (1)

28-29: LGTM — constants for magic strings.

Clean extraction. However, the new template_versions.go file (Lines 81, 86) still uses hardcoded "vendor" and "go.mod" instead of these constants. Consider using vendorDirName and goModFileName there as well for consistency.
[approve_code_changes, suggest_optional_refactor]

cmd/internal/migrations/lists.go (1)

76-76: LGTM — migration step correctly registered.

cmd/internal/migrations/v3/template_versions_test.go (1)

1-94: Good test coverage for the happy path and idempotency.

Consider adding a small test case for an unrecognized template package (e.g., github.com/gofiber/template/custom/v2) to verify it's left untouched by the migration.
[approve_code_changes, suggest_optional_refactor]

cmd/internal/migrations/v3/template_versions.go (1)

38-71: Implementation looks solid overall.

The structure mirrors the existing MigrateSwaggerPackages nicely: rewrite source imports via internal.ChangeFileContent, update go.mod entries, and print only when changes occur.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link

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 adds a new migration function to update Fiber template package imports and go.mod entries for v3 compatibility. The migration updates template packages from various versions to their minimum required versions for Fiber v3 (e.g., html/v2 → html/v3, django/v3 → django/v4).

Changes:

  • Adds MigrateTemplateVersions function to migrate template package versions in both Go imports and go.mod files
  • Adds comprehensive tests for the migration including idempotency verification
  • Refactors magic strings in swagger_packages.go to named constants for better maintainability
  • Integrates the new migration into the migration execution list

Reviewed changes

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

File Description
cmd/internal/migrations/v3/template_versions.go Implements template version migration with regex-based import and go.mod updates
cmd/internal/migrations/v3/template_versions_test.go Tests basic migration and idempotency with representative template packages
cmd/internal/migrations/v3/swagger_packages.go Extracts magic strings "vendor" and "go.mod" into reusable constants
cmd/internal/migrations/lists.go Adds MigrateTemplateVersions to v2→v3 migration list

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@cmd/internal/migrations/v3/template_versions.go`:
- Around line 141-146: The replace directive replacement in
updateTemplateGoModModule incorrectly preserves the captured old version (group
2) via `${2}`, causing stale versions to remain; change the replacement used
with patterns.replace so it injects the new target version instead of `${2}`
(e.g., format the replacement to `${1}<newPath> <version>${3}`) so versioned
replace lines are updated to the new major version; ensure patterns.require
still sets the require line to `<newPath> <version>` and that patterns.replace
uses the same `version` variable rather than preserving the old group.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f566d1e and 57725b4.

📒 Files selected for processing (1)
  • cmd/internal/migrations/v3/template_versions.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build (1.25.x, macos-latest)
  • GitHub Check: Build (1.25.x, windows-latest)
🔇 Additional comments (5)
cmd/internal/migrations/v3/template_versions.go (5)

1-16: LGTM!

Imports are clean and the reTemplateImport regex correctly captures the package name (group 1), optional major version (group 2), and any trailing sub-path (group 3).


18-41: LGTM!

The target map is well-structured, and each modulePath consistently matches its version major (v3 everywhere except django at v4).


43-76: LGTM!

The migration function cleanly separates import rewriting from go.mod updates, preserves import suffixes via sub[3], and only prints a notice when something actually changed.


78-127: LGTM! Past review feedback on using vendorDirName and goModFileName constants has been addressed.

The directory walk correctly skips vendor directories, reads go.mod files, applies template module updates, and writes back with preserved permissions.


129-139: LGTM!

Good use of regexp.QuoteMeta for safety, and pre-compiling the patterns once before the walk is efficient.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@ReneWerner87 ReneWerner87 merged commit 8b476fd into master Feb 12, 2026
12 of 13 checks passed
@ReneWerner87 ReneWerner87 deleted the add_template_pkg_migrator branch February 12, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✏️ Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant