-
Notifications
You must be signed in to change notification settings - Fork 16
fix: handle ContextKey removal only for fiber configs #192
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
Conversation
|
Warning Rate limit exceeded@ReneWerner87 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 7 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 (3)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
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 refines the v3 migration process by focusing on the intelligent removal of ContextKey fields. The changes ensure that ContextKey is only stripped from relevant Fiber middleware configurations, while meticulously preserving the original struct formatting. This is achieved through enhancements to the removeConfigField utility and the introduction of import detection to precisely target Fiber middleware configurations, along with new tests to validate these behaviors.
Highlights
- Targeted
ContextKeyRemoval: The migration process forContextKeyhas been refined to ensure it is only removed from configurations specifically associated with Fiber middleware, preventing unintended modifications to otherConfigstructs. - Enhanced Formatting Preservation: Improvements have been made to the
removeConfigFieldutility to preserve the original formatting of Go struct literals, ensuring that the removal of fields does not introduce unwanted whitespace or newline changes. - Improved Fiber Middleware Detection: The migration logic now includes robust detection of Fiber middleware imports and their aliases, allowing for precise application of
ContextKeyremoval only within those specific contexts. - Comprehensive Regression Tests: New regression tests have been added to validate the correct behavior of
ContextKeyremoval, including specific tests for formatting preservation and ensuring non-Fiber configurations remain untouched.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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
-
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. ↩
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 effectively addresses an issue where a migration script was too broad in its removal of configuration fields. The changes correctly limit the scope to only Fiber middleware configurations by intelligently detecting imports and their aliases. The addition of regression tests for formatting and for non-fiber configs is a great improvement. I've identified a potential issue with how package aliases are handled in regular expressions, particularly for dot imports and aliases containing special characters, and have provided suggestions to make the migration script more robust.
| for alias, pkg := range imports { | ||
| for _, e := range extractors { | ||
| if e.pkg != pkg { | ||
| continue | ||
| } | ||
| re := regexp.MustCompile(alias + `\.Config{[^}]*` + e.field + `:\s*"([^"]+)"`) | ||
| matches := re.FindAllStringSubmatch(content, -1) | ||
| for _, m := range matches { | ||
| ctxMap[m[1]] = e.replFmt | ||
| } | ||
| } | ||
| } |
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.
The current regular expression construction does not handle package aliases with special characters correctly, and fails for dot imports (import . "..."). The alias should be escaped using regexp.QuoteMeta to prevent misinterpretation of special characters, and dot imports (where the alias is '.') should result in no package prefix for the regex.
This can lead to incorrect or failed migrations for projects using these import styles.
for alias, pkg := range imports {
for _, e := range extractors {
if e.pkg != pkg {
continue
}
var prefix string
if alias == "." {
prefix = ""
} else {
prefix = regexp.QuoteMeta(alias) + "\\."
}
re := regexp.MustCompile(prefix + "Config{[^}]*" + e.field + ":\\s*\"([^\"]+)\"")
matches := re.FindAllStringSubmatch(content, -1)
for _, m := range matches {
ctxMap[m[1]] = e.replFmt
}
}
}| for alias := range imports { | ||
| reCfg := regexp.MustCompile(alias + `\.Config{[^}]*}`) | ||
| content = reCfg.ReplaceAllStringFunc(content, func(cfg string) string { | ||
| cfg = removeConfigField(cfg, "ContextKey") | ||
| cfg = removeConfigField(cfg, "ContextUsername") | ||
| cfg = removeConfigField(cfg, "ContextPassword") | ||
| return cfg | ||
| }) | ||
| } |
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.
Similar to the logic above, this regular expression construction does not handle package aliases with special characters or dot imports correctly. The alias should be escaped and dot imports should be handled to ensure the config struct is correctly identified and modified.
Without this change, the field removal might not apply to configs from packages imported with a dot (.) or an alias containing special characters.
| for alias := range imports { | |
| reCfg := regexp.MustCompile(alias + `\.Config{[^}]*}`) | |
| content = reCfg.ReplaceAllStringFunc(content, func(cfg string) string { | |
| cfg = removeConfigField(cfg, "ContextKey") | |
| cfg = removeConfigField(cfg, "ContextUsername") | |
| cfg = removeConfigField(cfg, "ContextPassword") | |
| return cfg | |
| }) | |
| } | |
| for alias := range imports { | |
| var prefix string | |
| if alias == "." { | |
| prefix = "" | |
| } else { | |
| prefix = regexp.QuoteMeta(alias) + "\\." | |
| } | |
| reCfg := regexp.MustCompile(prefix + "Config{[^}]*}") | |
| content = reCfg.ReplaceAllStringFunc(content, func(cfg string) string { | |
| cfg = removeConfigField(cfg, "ContextKey") | |
| cfg = removeConfigField(cfg, "ContextUsername") | |
| cfg = removeConfigField(cfg, "ContextPassword") | |
| return cfg | |
| }) | |
| } |
Summary
Testing
make lintmake testhttps://chatgpt.com/codex/tasks/task_e_68ab1fd3a7b8832691094b1dbf50e5e0