-
Notifications
You must be signed in to change notification settings - Fork 16
Migrate filesystem middleware to static middleware #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate filesystem middleware to static middleware #234
Conversation
Extend the filesystem middleware migration to handle NotFoundFile: - Comment out NotFoundFile configuration (deprecated) - Add TODO comment referencing NotFoundHandler (fiber.Handler) - Ensure idempotent migration (no duplicate comments on re-run) Changes: - Add regex pattern to detect and comment NotFoundFile - Only apply migration if TODO comment not already present - Add test for NotFoundFile migration - Add test for idempotency to prevent duplicate migrations Migration transforms: NotFoundFile: "index.html", To: // TODO: Migrate to NotFoundHandler (fiber.Handler) - NotFoundFile is deprecated // NotFoundFile: "index.html",
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 an important enhancement to the existing migration script for the Highlights
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.
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 extends the filesystem middleware migration to handle the deprecated NotFoundFile configuration. The changes correctly comment out the NotFoundFile field and add a TODO for manual migration, with an idempotency check to prevent duplicate changes. The accompanying tests are thorough, covering both the migration logic and its idempotency. My review includes a couple of suggestions for improvement: one for performance by optimizing regex compilation, and another for using the standard library to simplify the test code.
Remove extra whitespace from assertion to match goimports formatted output
|
Warning Rate limit exceeded@ReneWerner87 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 4 seconds before requesting another review. ⌛ 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)
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds migration handling to deprecate Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
cmd/internal/migrations/v3/filesystem_middleware.go (1)
37-44: Consider a more precise idempotency check.The current check uses
strings.Contains(content, "TODO: Migrate to NotFoundHandler")on the entire file content. While this works for typical cases, it could skip legitimateNotFoundFilemigrations if that TODO text exists elsewhere in the file (e.g., in an unrelated comment or string literal).A more robust approach would be to check if each specific
NotFoundFileline already has the TODO comment immediately above it, rather than checking the entire file.For example, you could modify the regex to detect already-migrated patterns:
// Handle NotFoundFile migration - comment it out and add TODO for NotFoundHandler -// Only migrate if not already migrated (check for TODO comment) -if !strings.Contains(content, "TODO: Migrate to NotFoundHandler") { - reNotFoundFile := regexp.MustCompile(`(?m)^(\s*)(NotFoundFile:\s*[^,\n]+)(,?)`) - content = reNotFoundFile.ReplaceAllString(content, - `$1// TODO: Migrate to NotFoundHandler (fiber.Handler) - NotFoundFile is deprecated +// Skip lines that already have the TODO comment above them +reNotFoundFile := regexp.MustCompile(`(?m)^(\s*)(NotFoundFile:\s*[^,\n]+)(,?)`) +content = reNotFoundFile.ReplaceAllStringFunc(content, func(match string) string { + // Check if this specific match is already preceded by the TODO + idx := strings.Index(content, match) + if idx > 0 { + prefix := content[:idx] + if strings.HasSuffix(strings.TrimRight(prefix, "\n"), "TODO: Migrate to NotFoundHandler (fiber.Handler) - NotFoundFile is deprecated") { + return match // Already migrated, leave as is + } + } + // Apply migration + re := regexp.MustCompile(`^(\s*)(NotFoundFile:\s*[^,\n]+)(,?)`) + return re.ReplaceAllString(match, `$1// TODO: Migrate to NotFoundHandler (fiber.Handler) - NotFoundFile is deprecated $1// $2$3`) -} +})cmd/internal/migrations/v3/filesystem_middleware_test.go (1)
121-129: Consider using the built-instrings.Countfunction.The Go standard library provides
strings.Countwhich does exactly what this helper function does, making this implementation redundant.Apply this diff to use the standard library function:
-// Helper function to count occurrences of a substring -func countOccurrences(str, substr string) int { - count := 0 - for i := 0; i <= len(str)-len(substr); i++ { - if str[i:i+len(substr)] == substr { - count++ - } - } - return count -}Then update the usage in the test:
// Verify the TODO comment is only present once - assert.Equal(t, 1, countOccurrences(secondContent, "TODO: Migrate to NotFoundHandler")) + assert.Equal(t, 1, strings.Count(secondContent, "TODO: Migrate to NotFoundHandler")) // Verify the NotFoundFile comment is only present once - assert.Equal(t, 1, countOccurrences(secondContent, "// NotFoundFile:")) + assert.Equal(t, 1, strings.Count(secondContent, "// NotFoundFile:"))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
cmd/internal/migrations/v3/filesystem_middleware.go(1 hunks)cmd/internal/migrations/v3/filesystem_middleware_test.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cmd/internal/migrations/v3/filesystem_middleware_test.go (1)
cmd/internal/migrations/v3/filesystem_middleware.go (1)
MigrateFilesystemMiddleware(14-57)
⏰ 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: Build (1.25.x, macos-13)
- GitHub Check: Build (1.25.x, macos-latest)
- GitHub Check: Build (1.25.x, ubuntu-latest)
- GitHub Check: Build (1.25.x, windows-latest)
🔇 Additional comments (2)
cmd/internal/migrations/v3/filesystem_middleware_test.go (2)
44-77: LGTM!The test thoroughly validates the NotFoundFile migration behavior, checking that the field is commented out, the TODO marker is added, and the static middleware migration is applied correctly.
79-118: Excellent idempotency test!This test effectively validates that the migration can be run multiple times without duplicating comments or producing different results, which is essential for a reliable migration tool.
Performance improvements: - Move all regex compilation from closure to package-level variables - Avoids repeated compilation overhead when processing multiple files - Compiled regexes are now reused across all file migrations Code quality improvements: - Replace custom countOccurrences helper with strings.Count - More idiomatic and efficient standard library usage - Remove unnecessary helper function This addresses code review feedback for better performance and idiomatic Go.
Extend the filesystem middleware migration to handle NotFoundFile:
Changes:
Migration transforms:
NotFoundFile: "index.html", To:
// TODO: Migrate to NotFoundHandler (fiber.Handler) - NotFoundFile is deprecated // NotFoundFile: "index.html",
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.