feat(migrator): add template version migration for Fiber v3 compatibility#272
feat(migrator): add template version migration for Fiber v3 compatibility#272ReneWerner87 merged 3 commits intomasterfrom
Conversation
Summary of ChangesHello @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 Highlights
Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. 📒 Files selected for processing (2)
WalkthroughAdds a new v3 migration, Changes
Sequence DiagramsequenceDiagram
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"
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
updateTemplateGoModModulecompiles 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-levelvar.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
cmd/internal/migrations/lists.gocmd/internal/migrations/v3/swagger_packages.gocmd/internal/migrations/v3/template_versions.gocmd/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.gofile (Lines 81, 86) still uses hardcoded"vendor"and"go.mod"instead of these constants. Consider usingvendorDirNameandgoModFileNamethere 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
MigrateSwaggerPackagesnicely: rewrite source imports viainternal.ChangeFileContent, updatego.modentries, and print only when changes occur.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
There was a problem hiding this comment.
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
MigrateTemplateVersionsfunction 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.goto 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.
There was a problem hiding this comment.
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
📒 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
reTemplateImportregex 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
modulePathconsistently matches itsversionmajor (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 usingvendorDirNameandgoModFileNameconstants 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.QuoteMetafor 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.
…eplace module paths with versioning
Summary by CodeRabbit
New Features
Refactor
Tests